Passed
Push — master ( 898cc7...450add )
by Thomas Mauro
03:07
created

checkServerResponse()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 5.3906

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.6111
cc 5
nc 3
nop 2
crap 5.3906
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient;
6
7
use Psr\Http\Message\ResponseInterface;
8
use TMV\OpenIdClient\Exception\OAuth2Exception;
9
10
/**
11
 * @param ResponseInterface $response
12
 * @param int|null $expectedCode
13
 */
14
function check_server_response(ResponseInterface $response, ?int $expectedCode = null): void
15
{
16 11
    if (! $expectedCode && $response->getStatusCode() >= 400) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $expectedCode of type integer|null is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
17 4
        throw OAuth2Exception::fromResponse($response);
18
    }
19
20 7
    if ($expectedCode && $expectedCode !== $response->getStatusCode()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $expectedCode of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
21
        throw OAuth2Exception::fromResponse($response);
22
    }
23
}
24