1 | <?php |
||
2 | namespace Qiniu\Http\Middleware; |
||
3 | |||
4 | use Qiniu\Http\Request; |
||
5 | use Qiniu\Http\Response; |
||
6 | |||
7 | class RetryDomainsMiddleware implements Middleware |
||
8 | { |
||
9 | /** |
||
10 | * @var array<string> backup domains. |
||
11 | */ |
||
12 | private $backupDomains; |
||
13 | |||
14 | /** |
||
15 | * @var numeric max retry times for each backup domains. |
||
0 ignored issues
–
show
|
|||
16 | */ |
||
17 | private $maxRetryTimes; |
||
18 | |||
19 | /** |
||
20 | * @var callable args response and request; returns bool; If true will retry with backup domains. |
||
21 | */ |
||
22 | private $retryCondition; |
||
23 | |||
24 | /** |
||
25 | * @param array<string> $backupDomains |
||
26 | * @param numeric $maxRetryTimes |
||
27 | */ |
||
28 | public function __construct($backupDomains, $maxRetryTimes = 2, $retryCondition = null) |
||
29 | { |
||
30 | $this->backupDomains = $backupDomains; |
||
31 | $this->maxRetryTimes = $maxRetryTimes; |
||
0 ignored issues
–
show
It seems like
$maxRetryTimes can also be of type integer . However, the property $maxRetryTimes is declared as type Qiniu\Http\Middleware\numeric . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
32 | $this->retryCondition = $retryCondition; |
||
33 | } |
||
34 | |||
35 | private function shouldRetry($resp, $req) |
||
36 | { |
||
37 | if (is_callable($this->retryCondition)) { |
||
38 | return call_user_func($this->retryCondition, $resp, $req); |
||
39 | } |
||
40 | |||
41 | return !$resp || $resp->needRetry(); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param Request $request |
||
46 | * @param callable(Request): Response $next |
||
47 | * @return Response |
||
48 | */ |
||
49 | public function send($request, $next) |
||
50 | { |
||
51 | $response = null; |
||
52 | $urlComponents = parse_url($request->url); |
||
53 | |||
54 | foreach (array_merge(array($urlComponents["host"]), $this->backupDomains) as $backupDomain) { |
||
55 | $urlComponents["host"] = $backupDomain; |
||
56 | $request->url = \Qiniu\unparse_url($urlComponents); |
||
57 | $retriedTimes = 0; |
||
58 | |||
59 | while ($retriedTimes < $this->maxRetryTimes) { |
||
60 | $response = $next($request); |
||
61 | |||
62 | $retriedTimes += 1; |
||
63 | |||
64 | if (!$this->shouldRetry($response, $request)) { |
||
65 | return $response; |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | if (!$response) { |
||
71 | $response = $next($request); |
||
72 | } |
||
73 | |||
74 | return $response; |
||
75 | } |
||
76 | } |
||
77 |
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