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.
Completed
Push — master ( fad287...99c177 )
by
unknown
20s queued 11s
created

Pinterest::count()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\ShariffBundle\Service;
11
12
use Core23\ShariffBundle\Service\Exception\FetchException;
13
use Psr\Http\Message\RequestFactoryInterface;
14
use Psr\Http\Message\RequestInterface;
15
use Psr\Http\Message\ResponseInterface;
16
17
final class Pinterest implements Service
18
{
19
    public function getCode(): string
20
    {
21
        return 'pinterest';
22
    }
23
24
    public function createRequest(RequestFactoryInterface $factory, string $url): RequestInterface
25
    {
26
        return $factory->createRequest(
27
            'GET',
28
            'https://api.pinterest.com/v1/urls/count.json?callback=x&url='.urlencode($url)
29
        );
30
    }
31
32
    public function count(ResponseInterface $response): int
33
    {
34
        $content = $response->getBody()->getContents();
35
        $content = mb_substr($content, 2, mb_strlen($content) - 3);
36
37
        $json = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
38
39
        if (!\array_key_exists('count', $json)) {
40
            throw new FetchException('The "count" attributes could not be found', $response->getBody()->getContents());
41
        }
42
43
        return (int) $json['count'];
44
    }
45
}
46