ServiceContainerBuilder::getService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 3 Features 0
Metric Value
c 3
b 3
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace PEIP\Service;
4
5
/*
6
 * This file is part of the PEIP package.
7
 * (c) 2009-2016 Timo Michna <timomichna/yahoo.de>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
/*
14
 * ServiceContainerBuilder
15
 *
16
 * @author Timo Michna <timomichna/yahoo.de>
17
 * @package PEIP
18
 * @subpackage service
19
 * @extends \PEIP\Data\InternalStoreAbstract
20
 */
21
22
23
24
25
use PEIP\Factory\DedicatedFactory;
26
27
class ServiceContainerBuilder extends \PEIP\Data\InternalStoreAbstract
28
{
29
    /**
30
     * @param $key
31
     * @param $factory
32
     *
33
     * @return
34
     */
35
    public function setFactory($key, DedicatedFactory $factory)
36
    {
37
        $this->setInternalValue($key, $factory);
38
    }
39
40
    /**
41
     * @param $key
42
     *
43
     * @return
44
     */
45
    public function getFactory($key)
46
    {
47
        $this->getInternalValue($key);
48
    }
49
50
    /**
51
     * @param $key
52
     *
53
     * @return
54
     */
55
    public function hasFactory($key)
56
    {
57
        $this->hasInternalValue($key);
58
    }
59
60
    /**
61
     * @param $key
62
     *
63
     * @return
64
     */
65
    public function deleteFactory($key)
66
    {
67
        $this->deleteInternalValue($key);
68
    }
69
70
    /**
71
     * @param $key
72
     *
73
     * @return
74
     */
75
    public function getService($key)
76
    {
77
        return isset($this->services[$key]) ? $this->services[$key] : $this->services[$key] = $this->getFactory($key)->build();
0 ignored issues
show
Bug introduced by
The property services does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The method build cannot be called on $this->getFactory($key) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
78
    }
79
80
    /**
81
     * @param $key
82
     *
83
     * @return
84
     */
85
    public function buildService($key)
86
    {
87
        return $this->getFactory($key)->build();
0 ignored issues
show
Bug introduced by
The method build cannot be called on $this->getFactory($key) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
88
    }
89
}
90