| Conditions | 3 |
| Paths | 2 |
| Total Lines | 70 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 59 | public function authenticate( $host, $username, $password ) { |
||
| 60 | |||
| 61 | // Get token response |
||
| 62 | $response = $this->browser->post( |
||
| 63 | "$host/ws", |
||
| 64 | [ |
||
| 65 | 'Content-Type' => 'application/x-sah-ws-1-call+json; charset=UTF-8', |
||
| 66 | 'Authorization' => 'X-Sah-Login', |
||
| 67 | ], |
||
| 68 | json_encode( [ |
||
| 69 | 'service' => 'sah.Device.Information', |
||
| 70 | 'method' => 'createContext', |
||
| 71 | 'parameters' => [ |
||
| 72 | 'applicationName' => 'so_sdkut', |
||
| 73 | 'username' => $username, |
||
| 74 | 'password' => $password, |
||
| 75 | ], |
||
| 76 | ] ) |
||
| 77 | |||
| 78 | ); |
||
| 79 | |||
| 80 | |||
| 81 | // Create sessid cookie |
||
| 82 | $cookie = new Cookie(); |
||
| 83 | $cookie->fromSetCookieHeader( $response->getHeader( 'Set-Cookie' ), $host ); |
||
| 84 | |||
| 85 | // Add cookie to JAR |
||
| 86 | $this->cookieJar->addCookie( $cookie ); |
||
| 87 | |||
| 88 | // foreach($response->getHeader('Set-Cookie') as $cookieString) { |
||
| 89 | // $cookie = new CookieJar(); |
||
| 90 | // } |
||
| 91 | |||
| 92 | // $response = $this->client->post( "$host/ws", [ |
||
| 93 | // RequestOptions::HEADERS => [ |
||
| 94 | // 'Content-Type' => 'application/x-sah-ws-1-call+json; charset=UTF-8', |
||
| 95 | // 'Authorization' => 'X-Sah-Login', |
||
| 96 | // ], |
||
| 97 | // RequestOptions::JSON => [ |
||
| 98 | // 'service' => 'sah.Device.Information', |
||
| 99 | // 'method' => 'createContext', |
||
| 100 | // 'parameters' => [ |
||
| 101 | // 'applicationName' => 'so_sdkut', |
||
| 102 | // 'username' => $username, |
||
| 103 | // 'password' => $password, |
||
| 104 | // ], |
||
| 105 | // ], |
||
| 106 | // ] ); |
||
| 107 | |||
| 108 | |||
| 109 | // foreach ( $response->getHeader( 'Set-Cookie' ) as $cookieString ) { |
||
| 110 | // $cookie = SetCookie::fromString( $cookieString ); |
||
| 111 | // $cookie->setDomain( '192.168.1.1' ); |
||
| 112 | // // var_dump( $this->cookieJar->setCookie($cookie)); |
||
| 113 | // $this->cookieJar->save(); |
||
| 114 | // } |
||
| 115 | // echo($this->cookieJar->count()); |
||
| 116 | |||
| 117 | // var_dump( $this->cookieJar->toArray() ); |
||
| 118 | // die(); |
||
| 119 | |||
| 120 | $json = json_decode( $response->getContent() ); |
||
| 121 | |||
| 122 | if ( ( $json->status === 0 ) && isset( $json->data->contextID ) ) { |
||
| 123 | $this->currentToken = $json->data->contextID; |
||
| 124 | |||
| 125 | return $json->data->contextID; |
||
| 126 | } else { |
||
| 127 | // TODO handle |
||
| 128 | throw new \AuthenticationException(); |
||
| 129 | } |
||
| 195 | } |
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