Mapper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 8
Bugs 0 Features 1
Metric Value
wmc 8
c 8
b 0
f 1
lcom 0
cbo 2
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A buildMapping() 0 6 3
A getClassMap() 0 4 1
A setClassMap() 0 4 1
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 7/26/15
6
 * Time: 12:44 PM.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace NilPortugues\Api\Mapping;
12
13
/**
14
 * Class Mapper.
15
 */
16
class Mapper
17
{
18
    /**
19
     * @var array
20
     */
21
    private $classMap = [];
22
    /**
23
     * @var array
24
     */
25
    private $aliasMap = [];
26
27
    /**
28
     * @param array $mappings
29
     *
30
     * @throws MappingException
31
     */
32
    public function __construct(array $mappings = null)
33
    {
34
        if (\is_array($mappings)) {
35
            foreach ($mappings as $mappedClass) {
36
                $mapping = $this->buildMapping($mappedClass);
37
38
                $this->classMap[ltrim($mapping->getClassName(), '\\')] = $mapping;
39
                $this->aliasMap[ltrim($mapping->getClassAlias(), '\\')][] = $mapping->getClassName();
40
            }
41
        }
42
    }
43
44
    /**
45
     * @param string|array $mappedClass
46
     *
47
     * @return Mapping
48
     */
49
    protected function buildMapping($mappedClass)
50
    {
51
        return (\is_string($mappedClass) && \class_exists($mappedClass, true)) ?
52
            MappingFactory::fromClass($mappedClass) :
53
            MappingFactory::fromArray($mappedClass);
0 ignored issues
show
Bug introduced by
It seems like $mappedClass defined by parameter $mappedClass on line 49 can also be of type string; however, NilPortugues\Api\Mapping...ingFactory::fromArray() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function getClassMap()
60
    {
61
        return $this->classMap;
62
    }
63
64
    /**
65
     * @param array $array
66
     */
67
    public function setClassMap(array $array)
68
    {
69
        $this->classMap = $array;
70
    }
71
}
72