Conditions | 14 |
Paths | 42 |
Total Lines | 85 |
Code Lines | 53 |
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 |
||
72 | public function validate(Request $request): Response |
||
73 | { |
||
74 | // Check if any of the required query parameters are missing |
||
75 | if(!$request->query->has('service')) { |
||
76 | Logger::debug('casserver: Missing service parameter: [service]'); |
||
77 | return new Response( |
||
78 | $this->cas10Protocol->getValidateFailureResponse(), |
||
79 | Response::HTTP_BAD_REQUEST |
||
80 | ); |
||
81 | } else if(!$request->query->has('ticket')) { |
||
82 | Logger::debug('casserver: Missing service parameter: [ticket]'); |
||
83 | return new Response( |
||
84 | $this->cas10Protocol->getValidateFailureResponse(), |
||
85 | Response::HTTP_BAD_REQUEST |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | // Check if we are required to force an authentication |
||
90 | $forceAuthn = $request->query->has('renew') && $request->query->get('renew'); |
||
91 | // Get the ticket |
||
92 | $ticket = $request->query->get('ticket'); |
||
93 | // Get the service |
||
94 | $service = $request->query->get('service'); |
||
95 | |||
96 | try { |
||
97 | // Get the service ticket |
||
98 | $serviceTicket = $this->ticketStore->getTicket($ticket); |
||
99 | // Delete the ticket |
||
100 | $this->ticketStore->deleteTicket($ticket); |
||
101 | } catch (\Exception $e) { |
||
102 | Logger::error('casserver:validate: internal server error. ' . var_export($e->getMessage(), true)); |
||
103 | return new Response( |
||
104 | $this->cas10Protocol->getValidateFailureResponse(), |
||
105 | Response::HTTP_INTERNAL_SERVER_ERROR |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | $failed = false; |
||
110 | $message = ''; |
||
111 | // No ticket |
||
112 | if ($serviceTicket === null) { |
||
113 | $message = 'ticket: ' . var_export($ticket, true) . ' not recognized'; |
||
114 | $failed = true; |
||
115 | // This is not a service ticket |
||
116 | } else if (!$this->ticketFactory->isServiceTicket($serviceTicket)){ |
||
117 | $message = 'ticket: ' . var_export($ticket, true) . ' is not a service ticket'; |
||
118 | $failed = true; |
||
119 | // the ticket has expired |
||
120 | } else if ($this->ticketFactory->isExpired($serviceTicket)) { |
||
121 | $message = 'Ticket has ' . var_export($ticket, true) . ' expired'; |
||
122 | $failed = true; |
||
123 | } else if ($this->sanitize($serviceTicket['service']) === $this->sanitize($service)) { |
||
124 | $message = 'Mismatching service parameters: expected ' . |
||
125 | var_export($serviceTicket['service'], true) . |
||
126 | ' but was: ' . var_export($service, true); |
||
127 | $failed = true; |
||
128 | } else if ($forceAuthn && isset($serviceTicket['forceAuthn']) && $serviceTicket['forceAuthn']) { |
||
129 | $message = 'Ticket was issued from single sign on session'; |
||
130 | $failed = true; |
||
131 | } |
||
132 | |||
133 | if ($failed) { |
||
134 | Logger::error('casserver:validate: ' . $message, true); |
||
135 | return new Response( |
||
136 | $this->cas10Protocol->getValidateFailureResponse(), |
||
137 | Response::HTTP_BAD_REQUEST |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | // Get the username field |
||
142 | $usernameField = $this->casConfig->getOptionalValue('attrname', 'eduPersonPrincipalName'); |
||
143 | |||
144 | // Fail if the username field is not present in the attribute list |
||
145 | if (!\array_key_exists($usernameField, $serviceTicket['attributes'])) { |
||
146 | Logger::error( |
||
147 | 'casserver:validate: internal server error. Missing user name attribute: ' |
||
148 | . var_export($usernameField, true), |
||
149 | ); |
||
150 | |||
151 | } |
||
152 | |||
153 | // Successful validation |
||
154 | return new Response( |
||
155 | $this->cas10Protocol->getValidateSuccessResponse($serviceTicket['attributes'][$usernameField][0]), |
||
156 | Response::HTTP_OK |
||
157 | ); |
||
159 | } |
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