1 | <?php |
||
21 | class Application |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Dependency injection container. |
||
26 | * |
||
27 | * @var DIContainer |
||
28 | */ |
||
29 | protected $container; |
||
30 | |||
31 | /** |
||
32 | * Returns instance of strategy manager. |
||
33 | * |
||
34 | * @param DIContainer $container Dependency injection container. |
||
35 | * |
||
36 | * @return self |
||
37 | */ |
||
38 | 3 | public static function getInstance(DIContainer $container = null) |
|
39 | { |
||
40 | 3 | static $instance = null; |
|
41 | |||
42 | 3 | if ( null === $instance ) { |
|
43 | $instance = new static($container); |
||
44 | } |
||
45 | |||
46 | 3 | return $instance; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Prevents direct instantiation. |
||
51 | * |
||
52 | * @param DIContainer $container Dependency injection container. |
||
53 | */ |
||
54 | 19 | public function __construct(DIContainer $container = null) |
|
55 | { |
||
56 | 19 | if ( !isset($container) ) { |
|
57 | 19 | $container = new DIContainer(); |
|
58 | 19 | } |
|
59 | |||
60 | 19 | $this->container = $container; |
|
61 | 19 | $this->container->setApplication($this); |
|
1 ignored issue
–
show
|
|||
62 | 19 | } |
|
63 | |||
64 | /** |
||
65 | * Returns test suite builder. |
||
66 | * |
||
67 | * @return TestSuiteFactory |
||
68 | * @see BrowserTestCase::suite() |
||
69 | */ |
||
70 | 19 | public function getTestSuiteFactory() |
|
71 | 19 | { |
|
72 | 3 | return $this->getObject('test_suite_factory'); |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Returns object from the container. |
||
77 | * |
||
78 | * @param string $service_id Name of the object in the container. |
||
79 | * |
||
80 | * @return \stdClass |
||
81 | */ |
||
82 | 5 | public function getObject($service_id) |
|
86 | |||
87 | /** |
||
88 | * Replaces object in the container. |
||
89 | * |
||
90 | * @param string $service_id Name of the object in the container. |
||
91 | * @param callable $callable The callable that will return the object. |
||
92 | * @param boolean $is_factory The callable should be considered as a factory. |
||
93 | * |
||
94 | * @return callable Previous service version. |
||
95 | * @throws \InvalidArgumentException When attempt is made to replace non-existing service. |
||
96 | */ |
||
97 | 19 | public function replaceObject($service_id, $callable, $is_factory = false) |
|
1 ignored issue
–
show
|
|||
98 | { |
||
99 | 2 | if ( !isset($this->container[$service_id]) ) { |
|
100 | 19 | throw new \InvalidArgumentException('Service "' . $service_id . '" not found'); |
|
101 | } |
||
102 | |||
103 | 1 | $backup = $this->container->raw($service_id); |
|
104 | 19 | unset($this->container[$service_id]); |
|
105 | 1 | $this->container[$service_id] = $is_factory ? $this->container->factory($callable) : $callable; |
|
106 | |||
107 | 1 | return $backup; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * Prevents cloning. |
||
112 | * |
||
113 | * @return void |
||
114 | * |
||
115 | * @codeCoverageIgnore |
||
116 | */ |
||
117 | private function __clone() |
||
121 | |||
122 | } |
||
123 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: