GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#145)
by Yong
04:38
created

RetryTrait::shouldRetry()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.2

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 5
nop 1
dl 0
loc 17
ccs 8
cts 10
cp 0.8
crap 5.2
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Request\Traits;
4
5
use Stringy\Stringy;
6
use AlibabaCloud\Client\Result\Result;
7
use AlibabaCloud\Client\Filter\ClientFilter;
8
use AlibabaCloud\Client\Exception\ClientException;
9
10
/**
11
 * Trait RetryTrait
12
 *
13
 * @package AlibabaCloud\Client\Request\Traits
14
 */
15
trait RetryTrait
16
{
17
    /**
18
     * Retry Times
19
     *
20
     * @var int
21
     */
22
    private $retry = 0;
23
24
    /**
25
     * Retry Strings
26
     *
27
     * @var string[]
28
     */
29
    private $retryStrings = [];
30
31
    /**
32
     * Retry Codes
33
     *
34
     * @var int[]
35
     */
36
    private $retryStatusCodes = [];
37
38
    /**
39
     * @param int   $times
40
     * @param array $strings
41
     * @param array $statusCodes
42
     *
43
     * @return $this
44
     * @throws ClientException
45
     */
46 2
    public function retry($times, array $strings, array $statusCodes = [])
47
    {
48 2
        $this->retry            = ClientFilter::retry($times);
0 ignored issues
show
Documentation Bug introduced by
The property $retry was declared of type integer, but AlibabaCloud\Client\Filt...ntFilter::retry($times) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
49 2
        $this->retryStrings     = $strings;
50 2
        $this->retryStatusCodes = $statusCodes;
51
52 2
        return $this;
53
    }
54
55
    /**
56
     * @param Result $result
57
     *
58
     * @return bool
59
     */
60 21
    private function shouldRetry(Result $result)
61
    {
62 21
        if ($this->retry <= 0) {
63 21
            return false;
64
        }
65
66 2
        if (in_array($result->getResponse()->getStatusCode(), $this->retryStatusCodes)) {
67 1
            return true;
68
        }
69
70 1
        foreach ($this->retryStrings as $message) {
71 1
            if (Stringy::create($result->getResponse()->getBody())->contains($message)) {
72 1
                return true;
73
            }
74
        }
75
76
        return false;
77
    }
78
}
79