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 ( 1eec8d...b3b44b )
by Richard
05:28 queued 02:13
created

RowMapperManager::getRowMapperByShortName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: wechsler
5
 * Date: 03/03/2017
6
 * Time: 20:09
7
 */
8
9
namespace Phase\TakeATicket\SongLoader;
10
11
use Doctrine\DBAL\Connection;
12
use Phase\TakeATicket\DataSource\Factory;
13
14
class RowMapperManager
15
{
16
17
    /**
18
     * @var string[]
19
     */
20
    protected $rowMapperClasses = [];
21
22
    /**
23
     * @var Connection
24
     */
25
    protected $dbConn;
26
27
    /**
28
     * @var RowMapperInterface[]
29
     */
30
    protected $rowMappers;
31
32
    /**
33
     * RowMapperManager constructor.
34
     * @param Connection $dbConn
35
     * @param \string[] $rowMapperClasses
36
     */
37
    public function __construct(Connection $dbConn, array $rowMapperClasses)
38
    {
39
        $this->dbConn = $dbConn;
40
        $dataStore = Factory::datasourceFromDbConnection($dbConn);
41
        $this->rowMapperClasses = $rowMapperClasses;
0 ignored issues
show
Documentation Bug introduced by
It seems like $rowMapperClasses of type array<integer,object<string>> is incompatible with the declared type array<integer,string> of property $rowMapperClasses.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
42
43
        foreach ($rowMapperClasses as $class) {
44
            $this->validateClass($class);
45
            $mapper = new $class($dataStore);
46
            /** @var RowMapperInterface $mapper */
47
            $this->rowMappers[strtolower($mapper->getShortName())] = $mapper;
48
        }
49
    }
50
51
    /**
52
     * Get the registered row mapper with the specified short name
53
     *
54
     * @param $shortName
55
     * @return null|RowMapperInterface
56
     */
57
    public function getRowMapperByShortName($shortName)
58
    {
59
        $shortName = strtolower($shortName);
60
        return array_key_exists($shortName, $this->rowMappers) ? $this->rowMappers[$shortName] : null;
61
    }
62
63
    /**
64
     * Get the registered row mapper with the specified short name
65
     *
66
     * @param $shortName
67
     * @return null|RowMapperInterface
68
     */
69
    public function getRowMapperClassByShortName($shortName)
70
    {
71
        $mapper = $this->getRowMapperByShortName($shortName);
72
        return $mapper ? get_class($mapper) : null;
73
    }
74
75
    public function getRowMapperShortNames()
76
    {
77
        return array_keys($this->rowMappers);
78
    }
79
80
    /**
81
     * @return RowMapperInterface[]
82
     */
83
    public function getRowMappers()
84
    {
85
        return $this->rowMappers;
86
    }
87
88
    /**
89
     * Ensure that provided classname is a valid RowMapperInterface
90
     *
91
     * @param $rowMapperClass
92
     * @throws \InvalidArgumentException
93
     */
94 View Code Duplication
    protected function validateClass($rowMapperClass)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $class = new \ReflectionClass($rowMapperClass);
97
        if ($class->isSubclassOf(RowMapperInterface::class)) {
98
            $this->rowMapperClass = $rowMapperClass;
0 ignored issues
show
Bug introduced by
The property rowMapperClass does not seem to exist. Did you mean rowMapperClasses?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
99
        } else {
100
            throw new \InvalidArgumentException(
101
                "$rowMapperClass must implement " . RowMapperInterface::class
102
            );
103
        }
104
    }
105
}
106