Completed
Push — master ( f51a8f...5648aa )
by Emily
11s
created

ReflectionCompositeProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Service;
16
17
use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite;
18
use Spaark\CompositeUtils\Factory\Reflection\ReflectionCompositeFactory;
19
use Spaark\CompositeUtils\Model\Collection\HashMap;
20
21
/**
22
 */
23
class ReflectionCompositeProvider
24
    implements ReflectionCompositeProviderInterface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
25
{
26
    /**
27
     * @var ReflectionCompositeProviderInterface
28
     */
29
    protected static $default;
30
31 20
    public static function getDefault()
32
        : ReflectionCompositeProviderInterface
33
    {
34 20
        if (!static::$default)
35
        {
36 1
            static::$default = new static();
37
        }
38
39 20
        return static::$default;
40
    }
41
42
    public static function setDefault
43
    (
44
        ReflectionCompositeProviderInterface $default
45
    )
46
    {
47
        static::$default = $default;
48
    }
49
50
    private $cache;
51
52 1
    public function __construct()
53
    {
54 1
        $this->cache = new HashMap();
55 1
    }
56
57 4
    public function get(string $classname) : ReflectionComposite
58
    {
59 4
        if (!$this->cache->containsKey($classname))
0 ignored issues
show
Documentation introduced by
$classname is of type string, but the function expects a object<Spaark\CompositeU...del\Collection\KeyType>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
        {
61 4
            $this->cache[$classname] =
62
                (
63 4
                    ReflectionCompositeFactory::fromClassName
64
                    (
65
                        $classname
66
                    )
67
                )
68 4
                ->build();
69
        }
70
        
71 4
        return $this->cache[$classname];
72
    }
73
}
74