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 ( baec26...abf8ca )
by Grisha
02:28
created

DateTrait::getDateTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Poloniex PHP SDK.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2017-2018 Chasovskih Grisha <[email protected]>
9
 * @license https://github.com/signulls/poloniex-php-sdk/blob/master/LICENSE MIT
10
 */
11
12
namespace Poloniex\Response\Traits;
13
14
use DateTime;
15
use Poloniex\Exception\PoloniexException;
16
use Poloniex\Response\ResponseInterface;
17
18
/**
19
 * Trait DateTrait
20
 *
21
 * @author Grisha Chasovskih <[email protected]>
22
 */
23
trait DateTrait
24
{
25
    /**
26
     * Example: "2014-10-18 23:03:21"
27
     *
28
     * @var string
29
     */
30
    public $date;
31
32
    /**
33
     * @internal
34
     * @param string $date
35
     */
36
    public function setDate(string $date): void
37
    {
38
        $this->date = $date;
39
    }
40
41
    /**
42
     * @internal
43
     * @param string|null $format
44
     * @return string
45
     */
46
    public function getDate(string $format = null): string
47
    {
48
        return $format
49
            ? $this->getDateTime()->format($format)
50
            : $this->date;
51
    }
52
53
    /**
54
     * @return DateTime
55
     */
56
    public function getDateTime(): DateTime
57
    {
58
        $dateTime = DateTime::createFromFormat(ResponseInterface::DATE_FORMAT, $this->date);
59
60
        if (!$dateTime instanceof DateTime) {
61
            throw new PoloniexException(sprintf('Unable to get DateTime object for date %s', $this->date));
62
        }
63
64
        return $dateTime;
65
    }
66
}