title: SonarQube Refactor this method to reduce its Cognitive Complexity
body: <p>I have the below utility method and I am using multiple if statements and getting cognitive complexity issue. I went through some links, but I am not able to understand how should I change my code without affecting users of this method.</p>
  
  <pre><code>public static boolean isWrapperValid(WrapperClass wrapper, boolean isTechnicalToken){
  
      String key=null;
      boolean isValidWrapper = false;
  
      if (wrapper != null &amp;&amp; wrapper.length() &gt; 7
          &amp;&amp; wrapper.substring(0, 6).equalsIgnoreCase("XYZ"))
      {
          wrapper= wrapper.substring(7, wrapper.lastIndexOf('.')+1);
      }
      if(wrapper != null &amp;&amp; wrapper.equalsIgnoreCase("TFR")) {
          isValidWrapper=Boolean.TRUE;
      }
      try {
           key = wrapper.getKey();
      }
      catch (Exception exception) {
          return isValidWrapper;
      }
  
      if(key!=null) {
  
          Date tokenExpiryTime = key.getExpiresAt();
  
          if(tokenExpiryTime!=null) {
              return isValidWrapper;
          }
  
          String algorithm=key.getAlgorithm();
          if(!DESIRED_ALGO.equals(algorithm)) {
              return isValidWrapper;
          }
  
          String value6=key.getType();
          if(!DESIRED_TYPE.equals(value6)) {
              return isValidWrapper;
          }
  
  
          if(key.getValue1()!=null &amp;&amp; key.getValue2().size()&gt;0 &amp;&amp; key.getValue3()!=null &amp;&amp; key.getValue4()!=null &amp;&amp; key.getValue5()!=null) {
              isValidWrapper=Boolean.TRUE;
          }
      }
  
      return isValidWrapper;
  }
  </code></pre>
  
  <p>Please share your suggestions to refactor this code.</p>