Passed
Push — main ( 8fb716...17db83 )
by Sammy
01:41
created
LeMarchand.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
     public const RX_SETTINGS = '/^settings\./';
15 15
     public const RX_MODEL_CLASS = '/([a-zA-Z]+)(Class|Model)$/';
16 16
 
17
-    public static function box($settings=null) : ContainerInterface
17
+    public static function box($settings = null) : ContainerInterface
18 18
     {
19
-      if(is_null(self::$instance)){
20
-        if(is_array($settings))
19
+      if (is_null(self::$instance)) {
20
+        if (is_array($settings))
21 21
           return (self::$instance = new LeMarchand($settings));
22 22
         throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN');
23 23
       }
@@ -48,14 +48,14 @@  discard block
 block discarded – undo
48 48
 
49 49
     public function has($configuration)
50 50
     {
51
-      try{
51
+      try {
52 52
         $this->get($configuration);
53 53
         return true;
54 54
       }
55
-      catch(NotFoundExceptionInterface $e){
55
+      catch (NotFoundExceptionInterface $e) {
56 56
         return false;
57 57
       }
58
-      catch(ContainerExceptionInterface $e){
58
+      catch (ContainerExceptionInterface $e) {
59 59
         return false;
60 60
       }
61 61
     }
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         // 4. is it a class ?
85 85
         if (preg_match(self::RX_MODEL_CLASS, $configuration, $m) === 1) {
86 86
             $class_name = $this->cascadeNamespace($m[1], 'Models');
87
-            if($m[2] === 'Model')
87
+            if ($m[2] === 'Model')
88 88
               return $this->getInstance($class_name);
89 89
             else
90 90
               return $class_name;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
         if (preg_match(self::RX_INTERFACE_NAME, $configuration, $m) === 1) {
94 94
             $wire = $this->get('settings.interface_implementations');
95
-            if(isset($wire[$configuration]))
95
+            if (isset($wire[$configuration]))
96 96
               return $this->getInstance($wire[$configuration]);
97 97
         }
98 98
 
@@ -114,19 +114,19 @@  discard block
 block discarded – undo
114 114
     //     throw new ConfigurationException($controller_name);
115 115
     // }
116 116
 
117
-    private function cascadeNamespace($class_name, $mvc_type=null)
117
+    private function cascadeNamespace($class_name, $mvc_type = null)
118 118
     {
119 119
         // is the controller name already instantiable ?
120
-        if(is_null($mvc_type) && class_exists($class_name))
120
+        if (is_null($mvc_type) && class_exists($class_name))
121 121
           return $class_name;
122 122
 
123
-        if($mvc_type !== 'Models' && $mvc_type !== 'Controllers'){
123
+        if ($mvc_type !== 'Models' && $mvc_type !== 'Controllers') {
124 124
             throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN');
125 125
         }
126 126
 
127 127
         // not fully namespaced, lets cascade
128 128
         foreach ($this->getSettings('settings.namespaces') as $ns) {
129
-            if(class_exists($full_name = $ns . $mvc_type . '\\' . $class_name))
129
+            if (class_exists($full_name = $ns.$mvc_type.'\\'.$class_name))
130 130
               return $full_name;
131 131
         }
132 132
         throw new ConfigurationException($class_name);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             $construction_args = [];
141 141
             if (!is_null($rc->getConstructor())) {
142 142
                 foreach ($rc->getConstructor()->getParameters() as $param) {
143
-                    $construction_args [] = $this->get($param->getType() . '');
143
+                    $construction_args [] = $this->get($param->getType().'');
144 144
                 }
145 145
                 $instance = $rc->newInstanceArgs($construction_args);
146 146
             } else {
Please login to merge, or discard this patch.
Braces   +19 added lines, -16 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
     public static function box($settings=null) : ContainerInterface
18 18
     {
19 19
       if(is_null(self::$instance)){
20
-        if(is_array($settings))
21
-          return (self::$instance = new LeMarchand($settings));
20
+        if(is_array($settings)) {
21
+                  return (self::$instance = new LeMarchand($settings));
22
+        }
22 23
         throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN');
23 24
       }
24 25
 
@@ -51,11 +52,9 @@  discard block
 block discarded – undo
51 52
       try{
52 53
         $this->get($configuration);
53 54
         return true;
54
-      }
55
-      catch(NotFoundExceptionInterface $e){
55
+      } catch(NotFoundExceptionInterface $e){
56 56
         return false;
57
-      }
58
-      catch(ContainerExceptionInterface $e){
57
+      } catch(ContainerExceptionInterface $e){
59 58
         return false;
60 59
       }
61 60
     }
@@ -84,16 +83,18 @@  discard block
 block discarded – undo
84 83
         // 4. is it a class ?
85 84
         if (preg_match(self::RX_MODEL_CLASS, $configuration, $m) === 1) {
86 85
             $class_name = $this->cascadeNamespace($m[1], 'Models');
87
-            if($m[2] === 'Model')
88
-              return $this->getInstance($class_name);
89
-            else
90
-              return $class_name;
86
+            if($m[2] === 'Model') {
87
+                          return $this->getInstance($class_name);
88
+            } else {
89
+                          return $class_name;
90
+            }
91 91
         }
92 92
 
93 93
         if (preg_match(self::RX_INTERFACE_NAME, $configuration, $m) === 1) {
94 94
             $wire = $this->get('settings.interface_implementations');
95
-            if(isset($wire[$configuration]))
96
-              return $this->getInstance($wire[$configuration]);
95
+            if(isset($wire[$configuration])) {
96
+                          return $this->getInstance($wire[$configuration]);
97
+            }
97 98
         }
98 99
 
99 100
         throw new ConfigurationException($configuration);
@@ -117,8 +118,9 @@  discard block
 block discarded – undo
117 118
     private function cascadeNamespace($class_name, $mvc_type=null)
118 119
     {
119 120
         // is the controller name already instantiable ?
120
-        if(is_null($mvc_type) && class_exists($class_name))
121
-          return $class_name;
121
+        if(is_null($mvc_type) && class_exists($class_name)) {
122
+                  return $class_name;
123
+        }
122 124
 
123 125
         if($mvc_type !== 'Models' && $mvc_type !== 'Controllers'){
124 126
             throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN');
@@ -126,8 +128,9 @@  discard block
 block discarded – undo
126 128
 
127 129
         // not fully namespaced, lets cascade
128 130
         foreach ($this->getSettings('settings.namespaces') as $ns) {
129
-            if(class_exists($full_name = $ns . $mvc_type . '\\' . $class_name))
130
-              return $full_name;
131
+            if(class_exists($full_name = $ns . $mvc_type . '\\' . $class_name)) {
132
+                          return $full_name;
133
+            }
131 134
         }
132 135
         throw new ConfigurationException($class_name);
133 136
     }
Please login to merge, or discard this patch.