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.

TransformService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace SebastianBerc\Repositories\Services;
4
5
use Illuminate\Contracts\Container\Container as Application;
6
use Illuminate\Support\Collection;
7
use SebastianBerc\Repositories\Contracts\ServiceInterface;
8
use SebastianBerc\Repositories\Contracts\TransformerInterface;
9
use SebastianBerc\Repositories\Exceptions\InvalidTransformer;
10
use SebastianBerc\Repositories\Repository;
11
12
/**
13
 * Class TransformService.
14
 *
15
 * @author    Sebastian Berć <[email protected]>
16
 * @copyright Copyright (c) Sebastian Berć
17
 */
18
class TransformService implements ServiceInterface
19
{
20
    /**
21
     * Contains Laravel Application instance.
22
     *
23
     * @var Application
24
     */
25
    protected $app;
26
27
    /**
28
     * Contains a repository instance.
29
     *
30
     * @var Repository
31
     */
32
    protected $repository;
33
34
    /**
35
     * Create a new transform service instance.
36
     *
37
     * @param Application $app
38
     * @param Repository  $repository
39
     */
40 120
    public function __construct(Application $app, Repository $repository)
41
    {
42 120
        $this->app        = $app;
43 120
        $this->repository = $repository;
44 120
    }
45
46
    /**
47
     * Execute transform method on specified transformer.
48
     *
49
     * @param Collection $collection
50
     *
51
     * @throws InvalidTransformer
52
     *
53
     * @return Collection
54
     */
55 26
    public function executeOn(Collection $collection)
56
    {
57 26
        if (empty($collection) || $collection->first() === null) {
58 2
            return $collection;
59
        }
60
61 24
        $transformer = $this->repository->transformer;
62
63 24
        if (!(new \ReflectionClass($transformer))->implementsInterface(TransformerInterface::class)) {
64 2
            throw new InvalidTransformer();
65
        }
66
67
        /** @var TransformerInterface $transformer */
68 22
        $transformer = new $transformer($collection);
69
70 22
        return $transformer->execute();
71
    }
72
}
73