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
Push — master ( d476d1...1782a7 )
by Yong
03:51
created

src/Traits/LogTrait.php (1 issue)

1
<?php
2
3
namespace AlibabaCloud\Client\Traits;
4
5
use DateTime;
6
use DateTimeZone;
7
use Exception;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * Trait LogTrait
12
 *
13
 * @package AlibabaCloud\Client\Traits
14
 */
15
trait LogTrait
16
{
17
    /**
18
     * @var LoggerInterface
19
     */
20
    private static $logger;
21
22
    /**
23
     * @var float
24
     */
25
    private static $logStartTime = 0;
26
27
    /**
28 75
     * @var string
29
     */
30 75
    private static $logFormat;
31
32
    /**
33
     * @var DateTime
34
     */
35
    private static $ts;
36
37
    /**
38 1
     * @return LoggerInterface
39
     */
40 1
    public static function getLogger()
41 1
    {
42
        return self::$logger;
43
    }
44
45
    /**
46 2
     * @param LoggerInterface $logger
47
     *
48
     * @throws Exception
49 2
     */
50
    public static function setLogger(LoggerInterface $logger)
51
    {
52
        self::$logger       = $logger;
53
        self::$logStartTime = microtime(true);
54
        $timezone           = new DateTimeZone(date_default_timezone_get() ?: 'UTC');
55
        if (PHP_VERSION_ID < 70100) {
56
            self::$ts = DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $timezone);
0 ignored issues
show
Documentation Bug introduced by
It seems like DateTime::createFromForm...time(true)), $timezone) can also be of type false. However, the property $ts is declared as type DateTime. 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 $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

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...
57
        } else {
58
            self::$ts = new DateTime(null, $timezone);
59
        }
60 1
    }
61
62 1
    /**
63 1
     * @return string
64
     */
65
    public static function getLogFormat()
66
    {
67
        $template = self::$logFormat
68
            ?: '"{method} {uri} HTTP/{version}" {code} {cost} {hostname} {pid}';
69
70
        return str_replace(
71
            ['{pid}', '{cost}', '{start_time}'],
72
            [getmypid(), self::getCost(), self::$ts->format('Y-m-d H:i:s.u')],
73
            $template
74
        );
75
    }
76
77
    /**
78
     * Apache Common Log Format.
79
     *
80
     * @param string $formatter
81
     *
82
     * @link http://httpd.apache.org/docs/2.4/logs.html#common
83
     * @see  \GuzzleHttp\MessageFormatter
84
     */
85
    public static function setLogFormat($formatter)
86
    {
87
        self::$logFormat = $formatter;
88
    }
89
90
    /**
91
     * @return float|mixed
92
     */
93
    private static function getCost()
94
    {
95
        return microtime(true) - self::$logStartTime;
96
    }
97
}
98