Passed
Push — develop ( 51b9ff...6cf518 )
by Paul
05:56
created
src/Container.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public static function getInstance()
39 39
     {
40
-        if (is_null(static::$instance)) {
40
+        if( is_null( static::$instance ) ) {
41 41
             static::$instance = new static();
42 42
         }
43 43
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return mixed
54 54
      */
55
-    public function bind($alias, $concrete)
55
+    public function bind( $alias, $concrete )
56 56
     {
57 57
         $this->services[$alias] = $concrete;
58 58
     }
@@ -66,20 +66,20 @@  discard block
 block discarded – undo
66 66
      *
67 67
      * @return mixed
68 68
      */
69
-    public function make($abstract)
69
+    public function make( $abstract )
70 70
     {
71
-        $service = isset($this->services[$abstract])
71
+        $service = isset( $this->services[$abstract] )
72 72
             ? $this->services[$abstract]
73
-            : $this->addNamespace($abstract);
73
+            : $this->addNamespace( $abstract );
74 74
 
75
-        if (is_callable($service)) {
76
-            return call_user_func_array($service, [$this]);
75
+        if( is_callable( $service ) ) {
76
+            return call_user_func_array( $service, [$this] );
77 77
         }
78
-        if (is_object($service)) {
78
+        if( is_object( $service ) ) {
79 79
             return $service;
80 80
         }
81 81
 
82
-        return $this->resolve($service);
82
+        return $this->resolve( $service );
83 83
     }
84 84
 
85 85
     /**
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
      *
91 91
      * @return void
92 92
      */
93
-    public function singleton($abstract, $concrete)
93
+    public function singleton( $abstract, $concrete )
94 94
     {
95
-        $this->bind($abstract, $this->make($concrete));
95
+        $this->bind( $abstract, $this->make( $concrete ) );
96 96
     }
97 97
 
98 98
     /**
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
      *
103 103
      * @return mixed
104 104
      */
105
-    public function __get($item)
105
+    public function __get( $item )
106 106
     {
107
-        return isset($this->bucket[$item])
107
+        return isset( $this->bucket[$item] )
108 108
             ? $this->bucket[$item]
109 109
             : null;
110 110
     }
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      *
118 118
      * @return void
119 119
      */
120
-    public function __set($item, $value)
120
+    public function __set( $item, $value )
121 121
     {
122 122
         $this->bucket[$item] = $value;
123 123
     }
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return string
131 131
      */
132
-    protected function addNamespace($abstract)
132
+    protected function addNamespace( $abstract )
133 133
     {
134
-        if (false === strpos($abstract, __NAMESPACE__) && !class_exists($abstract)) {
134
+        if( false === strpos( $abstract, __NAMESPACE__ ) && !class_exists( $abstract ) ) {
135 135
             $abstract = __NAMESPACE__."\\$abstract";
136 136
         }
137 137
 
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
      * @param \ReflectionParameter $parameter
143 143
      * @return null|\ReflectionClass|\ReflectionNamedType|\ReflectionType
144 144
      */
145
-    protected function getClass($parameter)
145
+    protected function getClass( $parameter )
146 146
     {
147
-        if (version_compare(phpversion(), '8', '<')) {
147
+        if( version_compare( phpversion(), '8', '<' ) ) {
148 148
             return $parameter->getClass(); // @compat PHP < 8
149 149
         }
150 150
         return $parameter->getType();
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
      * @return void
159 159
      * @throws BindingResolutionException
160 160
      */
161
-    protected function notInstantiable($concrete)
161
+    protected function notInstantiable( $concrete )
162 162
     {
163 163
         $message = "Target [$concrete] is not instantiable.";
164 164
 
165
-        throw new BindingResolutionException($message);
165
+        throw new BindingResolutionException( $message );
166 166
     }
167 167
 
168 168
     /**
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
      * @return mixed
174 174
      * @throws BindingResolutionException
175 175
      */
176
-    protected function resolve($concrete)
176
+    protected function resolve( $concrete )
177 177
     {
178
-        if ($concrete instanceof Closure) {
179
-            return $concrete($this);
178
+        if( $concrete instanceof Closure ) {
179
+            return $concrete( $this );
180 180
         }
181 181
 
182
-        $reflector = new ReflectionClass($concrete);
182
+        $reflector = new ReflectionClass( $concrete );
183 183
 
184
-        if (!$reflector->isInstantiable()) {
185
-            return $this->notInstantiable($concrete);
184
+        if( !$reflector->isInstantiable() ) {
185
+            return $this->notInstantiable( $concrete );
186 186
         }
187 187
 
188
-        if (is_null(($constructor = $reflector->getConstructor()))) {
188
+        if( is_null( ( $constructor = $reflector->getConstructor() ) ) ) {
189 189
             return new $concrete();
190 190
         }
191 191
 
192 192
         return $reflector->newInstanceArgs(
193
-            $this->resolveDependencies($constructor->getParameters())
193
+            $this->resolveDependencies( $constructor->getParameters() )
194 194
         );
195 195
     }
196 196
 
@@ -200,12 +200,12 @@  discard block
 block discarded – undo
200 200
      * @return mixed
201 201
      * @throws BindingResolutionException
202 202
      */
203
-    protected function resolveClass(ReflectionParameter $parameter)
203
+    protected function resolveClass( ReflectionParameter $parameter )
204 204
     {
205 205
         try {
206
-            return $this->make($this->getClass($parameter)->getName());
207
-        } catch (BindingResolutionException $e) {
208
-            if ($parameter->isOptional()) {
206
+            return $this->make( $this->getClass( $parameter )->getName() );
207
+        } catch( BindingResolutionException $e ) {
208
+            if( $parameter->isOptional() ) {
209 209
                 return $parameter->getDefaultValue();
210 210
             }
211 211
             throw $e;
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
      *
218 218
      * @return array
219 219
      */
220
-    protected function resolveDependencies(array $dependencies)
220
+    protected function resolveDependencies( array $dependencies )
221 221
     {
222 222
         $results = [];
223 223
 
224
-        foreach ($dependencies as $dependency) {
224
+        foreach( $dependencies as $dependency ) {
225 225
             // If the class is null, the dependency is a string or some other primitive type
226
-            $results[] = !is_null($class = $this->getClass($dependency))
227
-                ? $this->resolveClass($dependency)
226
+            $results[] = !is_null( $class = $this->getClass( $dependency ) )
227
+                ? $this->resolveClass( $dependency )
228 228
                 : null;
229 229
         }
230 230
 
Please login to merge, or discard this patch.