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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 2
Metric Value
c 7
b 1
f 2
dl 0
loc 55
wmc 5
lcom 1
cbo 4
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A executeOn() 0 17 4
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