Completed
Push — master ( 2d7c4c...dda5fd )
by Max
03:40
created
tests/ContainerTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         $di->setConfig([
111 111
             'drycart\di\tests\dummy\DummyInterface' => ['#class'=>'drycart\di\tests\dummy\DummyComplex']
112 112
         ]);
113
-        for ($i=0;$i<1000;$i++) {
113
+        for ($i = 0; $i < 1000; $i++) {
114 114
             $obj = $di->make('drycart\di\tests\dummy\DummyInterface', ['intDummy'=>$i]);
115 115
 //            $obj = new DummyComplex($i, null);
116 116
         }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             'stdClass' => ['#class'=>'stdClass']
125 125
         ]);
126 126
         $className = 'stdClass';
127
-        for ($i=0;$i<10000;$i++) {
127
+        for ($i = 0; $i < 10000; $i++) {
128 128
             $obj = $di->get($className);
129 129
 //            $obj = new $className;
130 130
         }
Please login to merge, or discard this patch.
src/AbstractContainer.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     protected function classConfig(string $id) : ?array
36 36
     {
37
-        if(!isset($this->chachedConfig[$id])) {
37
+        if (!isset($this->chachedConfig[$id])) {
38 38
             $config = $this->internalConfig($id);
39 39
             $this->initRequired($config['#required'] ?? []);
40 40
             unset($config['#required']);
@@ -45,26 +45,26 @@  discard block
 block discarded – undo
45 45
     
46 46
     protected function internalConfig(string $id) : ?array
47 47
     {
48
-        if(!isset($this->config[$id]) and !class_exists($id)) {
48
+        if (!isset($this->config[$id]) and !class_exists($id)) {
49 49
             return null;
50 50
         }
51 51
         $config = [];
52
-        if(!$this->isAlias($id)) {
53
-            foreach(array_reverse(class_parents($id)) as $parent) {
52
+        if (!$this->isAlias($id)) {
53
+            foreach (array_reverse(class_parents($id)) as $parent) {
54 54
                 $config = array_merge($config, $this->config[$parent] ?? []);
55 55
             }
56
-        } elseif(isset($this->config[$id]['#class'])) {
57
-            foreach(array_reverse(class_parents($this->config[$id]['#class'])) as $parent) {
56
+        } elseif (isset($this->config[$id]['#class'])) {
57
+            foreach (array_reverse(class_parents($this->config[$id]['#class'])) as $parent) {
58 58
                 $config = array_merge($config, $this->config[$parent] ?? []);
59 59
             }
60 60
         }
61 61
         $config = array_merge($config, $this->config[$id] ?? []);
62 62
         //
63
-        if(empty($config['#class'])) {
63
+        if (empty($config['#class'])) {
64 64
             $config['#class'] = $id;
65 65
         }
66 66
         //
67
-        if(!isset($config['#singleton'])) {
67
+        if (!isset($config['#singleton'])) {
68 68
             $config['#singleton'] = false;
69 69
         }
70 70
         return $config;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     protected function internalSingleton($id, array $config)
80 80
     {
81
-        if(!isset($this->storage[$id])) {
81
+        if (!isset($this->storage[$id])) {
82 82
             $this->storage[$id] = $this->internalMake($id, $config);
83 83
         } 
84 84
         return $this->storage[$id];
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         $fullParameters = array_merge($parameters, $config);
98 98
         $obj = $this->getObject($fullParameters);
99 99
         //
100
-        if(!$this->isAlias($id) and !is_a($obj, $id)) {
100
+        if (!$this->isAlias($id) and !is_a($obj, $id)) {
101 101
             throw new ContainerException('Wrong class, will be '.$id);
102 102
         }
103 103
         return $obj;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     protected function initRequired(array $requirement) : void
112 112
     {
113 113
         foreach ($requirement as $className) {
114
-            if(!isset($this->storage[$className])) {
114
+            if (!isset($this->storage[$className])) {
115 115
                 $this->singleton($className);
116 116
             }
117 117
         }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      */
126 126
     protected function getCallableDependency(callable $callable) : array
127 127
     {
128
-        if(is_array($callable)) {
128
+        if (is_array($callable)) {
129 129
             $className = get_class($callable[0]);
130 130
             $classReflector = new \ReflectionClass($className);
131 131
             return $classReflector->getMethod($callable[1])->getParameters();
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
     private $reflectionCache = [];
150 150
     private function getClassDependency(string $className) : array
151 151
     {
152
-        if(!class_exists($className)) {
152
+        if (!class_exists($className)) {
153 153
             // Not NotFoundException => it is missconfiguration, i.e. wrong class at config
154 154
             throw new ContainerException('Class need to instantiate not exist '.$className);
155 155
         }
156
-        if(!isset($this->reflectionCache[$className])) {
156
+        if (!isset($this->reflectionCache[$className])) {
157 157
             $reflector = new \ReflectionClass($className);
158 158
             $constructor = $reflector->getConstructor();
159
-            if(!is_null($constructor)) {
159
+            if (!is_null($constructor)) {
160 160
                 $this->reflectionCache[$className] = $constructor->getParameters();
161 161
             } else {
162 162
                 $this->reflectionCache[$className] = [];
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
      */
173 173
     private function getObject(array $parameters = [])
174 174
     {
175
-        if(isset($parameters['#factory'])) {
175
+        if (isset($parameters['#factory'])) {
176 176
             return call_user_func_array($parameters['#factory'], [$parameters, $this]);
177 177
         }
178 178
         $className = $parameters['#class'];
179 179
         //
180 180
         $dependency = $this->getClassDependency($className);
181
-        if(!empty($dependency)) {
181
+        if (!empty($dependency)) {
182 182
             $preparedParameters = $this->prepareParameters($dependency, $parameters);
183 183
         } else {
184 184
             $preparedParameters = [];
Please login to merge, or discard this patch.