original_string: protected function addProtocolPortIfNeeded(string $matched, array $parsed) : string
      {
          if ('' === $matched || '*' === $matched) {
              $return = $matched;
  
              return $return;
          }
          $protocol = 'https://';
          $port     = 0;
          if (true === isset($parsed['scheme'])) {
              $this->addLog('Parsed a protocol from origin: '.$parsed['scheme']);
              $protocol = $parsed['scheme'].'://';
          } else {
              $this->addLog('Unable to parse protocol/scheme from origin');
          }
          if (true === isset($parsed['port'])) {
              $this->addLog('Parsed a port from origin: '.$parsed['port']);
              $port = (int) $parsed['port'];
          } else {
              $this->addLog('Unable to parse port from origin');
          }
  
          if (0 === $port) {
              if ('https://' === $protocol) {
                  $port = 443;
              } else {
                  $port = 80;
              }
          }
  
          if (('http://' === $protocol && 80 === $port) || ('https://' === $protocol && 443 === $port)) {
              $return = $protocol.$matched;
          } else {
              $return = $protocol.$matched.':'.$port;
          }
          return $return;
      }
code: protected function addProtocolPortIfNeeded(string $matched, array $parsed) : string
      {
          if ('' === $matched || '*' === $matched) {
              $return = $matched;
  
              return $return;
          }
          $protocol = 'https://';
          $port     = 0;
          if (true === isset($parsed['scheme'])) {
              $this->addLog('Parsed a protocol from origin: '.$parsed['scheme']);
              $protocol = $parsed['scheme'].'://';
          } else {
              $this->addLog('Unable to parse protocol/scheme from origin');
          }
          if (true === isset($parsed['port'])) {
              $this->addLog('Parsed a port from origin: '.$parsed['port']);
              $port = (int) $parsed['port'];
          } else {
              $this->addLog('Unable to parse port from origin');
          }
  
          if (0 === $port) {
              if ('https://' === $protocol) {
                  $port = 443;
              } else {
                  $port = 80;
              }
          }
  
          if (('http://' === $protocol && 80 === $port) || ('https://' === $protocol && 443 === $port)) {
              $return = $protocol.$matched;
          } else {
              $return = $protocol.$matched.':'.$port;
          }
          return $return;
      }
code_tokens: protected function addProtocolPortIfNeeded ( string $ matched , array $ parsed ) : string { if ( '' === $ matched || '*' === $ matched ) { $ return = $ matched ; return $ return ; } $ protocol = 'https://' ; $ port = 0 ; if ( true === isset ( $ parsed [ 'scheme' ] ) ) { $ this -> addLog ( 'Parsed a protocol from origin: ' . $ parsed [ 'scheme' ] ) ; $ protocol = $ parsed [ 'scheme' ] . '://' ; } else { $ this -> addLog ( 'Unable to parse protocol/scheme from origin' ) ; } if ( true === isset ( $ parsed [ 'port' ] ) ) { $ this -> addLog ( 'Parsed a port from origin: ' . $ parsed [ 'port' ] ) ; $ port = ( int ) $ parsed [ 'port' ] ; } else { $ this -> addLog ( 'Unable to parse port from origin' ) ; } if ( 0 === $ port ) { if ( 'https://' === $ protocol ) { $ port = 443 ; } else { $ port = 80 ; } } if ( ( 'http://' === $ protocol && 80 === $ port ) || ( 'https://' === $ protocol && 443 === $ port ) ) { $ return = $ protocol . $ matched ; } else { $ return = $ protocol . $ matched . ':' . $ port ; } return $ return ; }
docstring: Returns the protocol if needed.
  
  @param string $matched The matched host.
  @param array  $parsed  The results of parse_url.
  
  @return string
docstring_tokens: Returns the protocol if needed .