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

Reddit::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 Reddit implements Service
18
{
19
    public function getCode(): string
20
    {
21
        return 'reddit';
22
    }
23
24
    public function createRequest(RequestFactoryInterface $factory, string $url): RequestInterface
25
    {
26
        return $factory->createRequest('GET', 'https://www.reddit.com/api/info.json?url='.urlencode($url));
27
    }
28
29
    public function count(ResponseInterface $response): int
30
    {
31
        $json = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
32
33
        if (!isset($json['data']['children'])) {
34
            throw new FetchException('The "data.children" attributes could not be found', $response->getBody()->getContents());
35
        }
36
37
        $count = 0;
38
        if (isset($json['data']['children'])) {
39
            foreach ((array) $json['data']['children'] as $child) {
40
                if (isset($child['data']['score'])) {
41
                    $count += $child['data']['score'];
42
                }
43
            }
44
        }
45
46
        return $count;
47
    }
48
}
49