Passed
Branch master (4e8cc8)
by Tolan
04:09
created
lib/DependencyInjector.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     /**
37 37
      * @param Container $container
38 38
      */
39
-    private function __construct( Container $container ){
39
+    private function __construct(Container $container) {
40 40
         $this->container = $container;
41 41
     }
42 42
 
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
      * @return DependencyInjector
45 45
      * @throws \Exception
46 46
      */
47
-    public static function instance(){
48
-        if( ! isset( self::$singleton->container ) ){
49
-            throw new \Exception( "Can't access DependencyInjector singleton before it is initialised via DependencyInjector::init()" );
47
+    public static function instance() {
48
+        if ( ! isset(self::$singleton->container)) {
49
+            throw new \Exception("Can't access DependencyInjector singleton before it is initialised via DependencyInjector::init()");
50 50
         }
51 51
         return self::$singleton;
52 52
     }
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
     /**
55 55
      * @param Container $container
56 56
      */
57
-    public static function init( Container $container ){
58
-        $di = new DependencyInjector( $container );
57
+    public static function init(Container $container) {
58
+        $di = new DependencyInjector($container);
59 59
         self::$singleton = $di;
60 60
     }
61 61
 
@@ -65,24 +65,24 @@  discard block
 block discarded – undo
65 65
      * @param $methodName
66 66
      * @return mixed The method's return value
67 67
      */
68
-    public function injectIntoMethod( $object, $methodName = "injectDependencies" ){
68
+    public function injectIntoMethod($object, $methodName = "injectDependencies") {
69 69
         $ref = new \ReflectionClass($object);
70
-        try{
71
-            $refMethod = $ref->getMethod( $methodName );
72
-        }catch( ReflectionException  $e ){
70
+        try {
71
+            $refMethod = $ref->getMethod($methodName);
72
+        }catch (ReflectionException  $e) {
73 73
             return null;
74 74
         }
75 75
         
76 76
         $toInject = [];
77 77
         foreach ($refMethod->getParameters() as $p) {
78 78
             $className = $p->getClass()->name;
79
-            if( $className === "Pimple\\Container" ){
79
+            if ($className === "Pimple\\Container") {
80 80
                 $toInject[] = $this->container;
81
-            }else{
82
-                $toInject[] = $this->container[ $className ];
81
+            }else {
82
+                $toInject[] = $this->container[$className];
83 83
             }
84 84
         }
85
-        return $refMethod->invoke( $object, ... $toInject );
85
+        return $refMethod->invoke($object, ... $toInject);
86 86
     }
87 87
 
88 88
     /**
@@ -93,28 +93,28 @@  discard block
 block discarded – undo
93 93
      * @param array $toInject
94 94
      * @return bool Whether the method was found
95 95
      */
96
-    public function injectIntoConstructor( $classToBuildName, array $toInject=[] ){
96
+    public function injectIntoConstructor($classToBuildName, array $toInject = []) {
97 97
         $ref = new \ReflectionClass($classToBuildName);
98
-        try{
98
+        try {
99 99
             $constr = $ref->getConstructor();
100
-        }catch( ReflectionException  $e ){
100
+        }catch (ReflectionException  $e) {
101 101
             return null;
102 102
         }
103 103
 
104 104
         $numToSkip = count($toInject);
105 105
         foreach ($constr->getParameters() as $p) {
106
-            if( $numToSkip > 0 ){
106
+            if ($numToSkip > 0) {
107 107
                 $numToSkip--;
108 108
                 continue;
109 109
             }
110 110
             $classToInjectName = $p->getClass()->name;
111
-            if( $classToInjectName === "Pimple\\Container" ){
111
+            if ($classToInjectName === "Pimple\\Container") {
112 112
                 $toInject[] = $this->container;
113
-            }else{
114
-                $toInject[] = $this->container[ $classToInjectName ];
113
+            }else {
114
+                $toInject[] = $this->container[$classToInjectName];
115 115
             }
116 116
         }
117
-        return new $classToBuildName( ... $toInject );
117
+        return new $classToBuildName(... $toInject);
118 118
     }
119 119
 
120 120
 }
121 121
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         $ref = new \ReflectionClass($object);
70 70
         try{
71 71
             $refMethod = $ref->getMethod( $methodName );
72
-        }catch( ReflectionException  $e ){
72
+        } catch( ReflectionException  $e ){
73 73
             return null;
74 74
         }
75 75
         
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
             $className = $p->getClass()->name;
79 79
             if( $className === "Pimple\\Container" ){
80 80
                 $toInject[] = $this->container;
81
-            }else{
81
+            } else{
82 82
                 $toInject[] = $this->container[ $className ];
83 83
             }
84 84
         }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         $ref = new \ReflectionClass($classToBuildName);
98 98
         try{
99 99
             $constr = $ref->getConstructor();
100
-        }catch( ReflectionException  $e ){
100
+        } catch( ReflectionException  $e ){
101 101
             return null;
102 102
         }
103 103
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
             $classToInjectName = $p->getClass()->name;
111 111
             if( $classToInjectName === "Pimple\\Container" ){
112 112
                 $toInject[] = $this->container;
113
-            }else{
113
+            } else{
114 114
                 $toInject[] = $this->container[ $classToInjectName ];
115 115
             }
116 116
         }
Please login to merge, or discard this patch.