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.

DefaultMapper::getClassName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace RemiSan\Serializer\Mapper;
4
5
use RemiSan\Serializer\SerializableClassMapper;
6
use RemiSan\Serializer\SerializableClassNameExtractor;
7
8
class DefaultMapper implements SerializableClassMapper
9
{
10
    /**
11
     * @var SerializableClassNameExtractor
12
     */
13
    private $nameExtractor;
14
15
    /**
16
     * @var string[]
17
     */
18
    private $mapping;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param SerializableClassNameExtractor $nameExtractor
24
     */
25 30
    public function __construct(SerializableClassNameExtractor $nameExtractor)
26
    {
27 30
        $this->nameExtractor = $nameExtractor;
28 30
        $this->mapping = [];
29 30
    }
30
31
    /**
32
     * @param string[] $classes
33
     */
34 3
    public function registerMultiple(array $classes)
35
    {
36 3
        foreach ($classes as $class) {
37 3
            $this->register($class);
38 2
        }
39 3
    }
40
41
    /**
42
     * @param string $class
43
     */
44 27
    public function register($class)
45
    {
46 27
        $this->mapping[$this->extractName($class)] = $class;
47 27
    }
48
49
    /**
50
     * @param string $class
51
     *
52
     * @return string
53
     */
54 27
    public function extractName($class)
55
    {
56 27
        return $this->nameExtractor->extractName($class);
57
    }
58
59
    /**
60
     * @param string $name
61
     *
62
     * @return string
63
     */
64 18
    public function getClassName($name)
65
    {
66 18
        if (!isset($this->mapping[$name])) {
67 3
            throw new \InvalidArgumentException(sprintf('Could not find "%s"', $name));
68
        }
69
70 15
        return $this->mapping[$name];
71
    }
72
}
73