| Conditions | 17 |
| Paths | 82 |
| Total Lines | 112 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 54 | public function validate(Request $request): Template |
||
| 55 | { |
||
| 56 | /* Load simpleSAMLphp, configuration and metadata */ |
||
| 57 | $casconfig = Configuration::getConfig('module_casserver.php'); |
||
| 58 | |||
| 59 | /* Instantiate protocol handler */ |
||
| 60 | $protocolClass = Module::resolveClass('casserver:Cas10', 'Cas\Protocol'); |
||
| 61 | |||
| 62 | /** @psalm-suppress InvalidStringClass */ |
||
| 63 | $protocol = new $protocolClass($casconfig); |
||
| 64 | |||
| 65 | $response = new StreamedResponse(); |
||
| 66 | if ($request->query->has('service') && $request->query->has('ticket')) { |
||
| 67 | $forceAuthn = $request->query->has('renew') && !!$request->query->get('renew'); |
||
| 68 | |||
| 69 | try { |
||
| 70 | /* Instantiate ticket store */ |
||
| 71 | $ticketStoreConfig = $casconfig->getOptionalValue( |
||
| 72 | 'ticketstore', |
||
| 73 | ['class' => 'casserver:FileSystemTicketStore'] |
||
| 74 | ); |
||
| 75 | |||
| 76 | $ticketStoreClass = Module::resolveClass($ticketStoreConfig['class'], 'Cas\Ticket'); |
||
| 77 | |||
| 78 | /** @psalm-suppress InvalidStringClass */ |
||
| 79 | $ticketStore = new $ticketStoreClass($casconfig); |
||
| 80 | |||
| 81 | $ticketFactoryClass = Module::resolveClass('casserver:TicketFactory', 'Cas\Ticket'); |
||
| 82 | |||
| 83 | /** @psalm-suppress InvalidStringClass */ |
||
| 84 | $ticketFactory = new $ticketFactoryClass($casconfig); |
||
| 85 | |||
| 86 | $ticket = $request->query->get('ticket'); |
||
| 87 | $serviceTicket = $ticketStore->getTicket($ticket); |
||
| 88 | |||
| 89 | if (!is_null($serviceTicket) && $ticketFactory->isServiceTicket($serviceTicket)) { |
||
| 90 | $service = $request->query->get('service'); |
||
| 91 | $ticketStore->deleteTicket($ticket); |
||
| 92 | $usernameField = $casconfig->getOptionalValue('attrname', 'eduPersonPrincipalName'); |
||
| 93 | |||
| 94 | if ( |
||
| 95 | !$ticketFactory->isExpired($serviceTicket) && |
||
| 96 | $this->urlUtils->sanitize($serviceTicket['service']) === $this->urlUtils->sanitize($service) && |
||
| 97 | (!$forceAuthn || $serviceTicket['forceAuthn']) && |
||
| 98 | array_key_exists($usernameField, $serviceTicket['attributes']) |
||
| 99 | ) { |
||
| 100 | $response->setCallback(function() { |
||
| 101 | echo $protocol->getValidateSuccessResponse($serviceTicket['attributes'][$usernameField][0]); |
||
| 102 | }); |
||
| 103 | } else { |
||
| 104 | if (!array_key_exists($usernameField, $serviceTicket['attributes'])) { |
||
| 105 | Logger::error(sprintf( |
||
| 106 | 'casserver:validate: internal server error. Missing user name attribute: %s', |
||
| 107 | var_export($usernameField, true) |
||
| 108 | )); |
||
| 109 | |||
| 110 | $response->setCallback(function() { |
||
| 111 | echo $protocol->getValidateFailureResponse(); |
||
| 112 | }); |
||
| 113 | } else { |
||
| 114 | if ($ticketFactory->isExpired($serviceTicket)) { |
||
| 115 | $message = 'Ticket has ' . var_export($ticket, true) . ' expired'; |
||
| 116 | } else { |
||
| 117 | if ($this->urlUtils->sanitize($serviceTicket['service']) === $this->urlUtils->sanitize($service)) { |
||
| 118 | $message = 'Mismatching service parameters: expected ' . |
||
| 119 | var_export($serviceTicket['service'], true) . |
||
| 120 | ' but was: ' . var_export($service, true); |
||
| 121 | } else { |
||
| 122 | $message = 'Ticket was issue from single sign on session'; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | Logger::debug('casserver:' . $message); |
||
| 126 | |||
| 127 | $response->setCallback(function() { |
||
| 128 | echo $protocol->getValidateFailureResponse(); |
||
| 129 | }); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } else { |
||
| 133 | if (is_null($serviceTicket)) { |
||
| 134 | $message = 'ticket: ' . var_export($ticket, true) . ' not recognized'; |
||
| 135 | } else { |
||
| 136 | $message = 'ticket: ' . var_export($ticket, true) . ' is not a service ticket'; |
||
| 137 | } |
||
| 138 | |||
| 139 | Logger::debug('casserver:' . $message); |
||
| 140 | |||
| 141 | $response->setCallback(function() { |
||
| 142 | echo $protocol->getValidateFailureResponse(); |
||
| 143 | }); |
||
| 144 | } |
||
| 145 | } catch (Exception $e) { |
||
| 146 | Logger::error('casserver:validate: internal server error. ' . var_export($e->getMessage(), true)); |
||
| 147 | |||
| 148 | $response->setCallback(function() { |
||
| 149 | echo $protocol->getValidateFailureResponse(); |
||
| 150 | }); |
||
| 151 | } |
||
| 152 | } else { |
||
| 153 | if (!$request->query->has('service')) { |
||
| 154 | $message = 'Missing service parameter: [service]'; |
||
| 155 | } else { |
||
| 156 | $message = 'Missing ticket parameter: [ticket]'; |
||
| 157 | } |
||
| 158 | |||
| 159 | Logger::debug('casserver:' . $message); |
||
| 160 | $response->setCallback(function() { |
||
| 161 | echo $protocol->getValidateFailureResponse(); |
||
| 162 | }); |
||
| 163 | } |
||
| 164 | |||
| 165 | return $response; |
||
| 166 | } |
||
| 168 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths