Completed
Pull Request — master (#7)
by Emily
02:15
created
src/Factory/Reflection/TypeParser.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -225,6 +225,9 @@
 block discarded – undo
225 225
             : new ObjectType($context);
226 226
     }
227 227
 
228
+    /**
229
+     * @param string $var
230
+     */
228 231
     public function scalarToType($var) : ?AbstractType
229 232
     {
230 233
         switch (strtolower($var))
Please login to merge, or discard this patch.
Spacing   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -88,8 +88,7 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public function parseObjectName($var) : ObjectType
90 90
     {
91
-        return $this->parse(str_replace
92
-        (
91
+        return $this->parse(str_replace(
93 92
             ['_g', '_e', '_c'],
94 93
             ['<', '>', ','],
95 94
             get_class($var)
@@ -134,7 +133,7 @@  discard block
 block discarded – undo
134 133
                     $item = $stack->pop();
135 134
                     if ($value{$i - 1} !== '>')
136 135
                     {
137
-                        $item->generics[] =$this->resolveName();
136
+                        $item->generics[] = $this->resolveName();
138 137
                     }
139 138
 
140 139
                     if ($i + 1 !== strlen($value) && $value{$i + 1} === '[')
@@ -182,7 +181,7 @@  discard block
 block discarded – undo
182 181
         }
183 182
         elseif ($i + 2 !== strlen($value))
184 183
         {
185
-            if (!in_array($value{$i + 2}, ['>',',']))
184
+            if (!in_array($value{$i + 2}, ['>', ',']))
186 185
             {
187 186
                 throw new \Exception('Unexpected char after collection');
188 187
             }
@@ -225,7 +224,7 @@  discard block
 block discarded – undo
225 224
             : new ObjectType($context);
226 225
     }
227 226
 
228
-    public function scalarToType($var) : ?AbstractType
227
+    public function scalarToType($var) : ? AbstractType
229 228
     {
230 229
         switch (strtolower($var))
231 230
         {
Please login to merge, or discard this patch.
src/Service/GenericNameProvider.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -20,10 +20,8 @@
 block discarded – undo
20 20
 use Spaark\CompositeUtils\Model\Reflection\Type\FloatType;
21 21
 use Spaark\CompositeUtils\Model\Reflection\Type\MixedType;
22 22
 use Spaark\CompositeUtils\Model\Reflection\Type\IntegerType;
23
-use Spaark\CompositeUtils\Model\Reflection\Type\CollectionType;
24 23
 use Spaark\CompositeUtils\Model\Reflection\Type\StringType;
25 24
 use Spaark\CompositeUtils\Model\Reflection\Type\GenericType;
26
-use Spaark\CompositeUtils\Model\Generic\GenericContext;
27 25
 use Spaark\CompositeUtils\Exception\MissingContextException;
28 26
 use Spaark\CompositeUtils\Traits\HasGenericContextTrait;
29 27
 use Spaark\CompositeUtils\Model\ClassName;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -63,8 +63,7 @@  discard block
 block discarded – undo
63 63
                 return $this->inferGenericName($reflect);
64 64
         }
65 65
 
66
-        throw new \DomainException
67
-        (
66
+        throw new \DomainException(
68 67
             'Unknown type: ' . get_class($reflect)
69 68
         );
70 69
     }
@@ -101,8 +100,7 @@  discard block
 block discarded – undo
101 100
                 $items[] = $this->inferName($generic);
102 101
             }
103 102
 
104
-            return new ClassName
105
-            (
103
+            return new ClassName(
106 104
                   self::BASE . $reflect->classname
107 105
                 . '_g' . implode('_c', $items) . '_e'
108 106
             );
Please login to merge, or discard this patch.
src/Service/PropertyAccessor.php 3 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -17,11 +17,6 @@
 block discarded – undo
17 17
 use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite;
18 18
 use Spaark\CompositeUtils\Model\Reflection\ReflectionProperty;
19 19
 use Spaark\CompositeUtils\Model\Reflection\Type\ObjectType;
20
-use Spaark\CompositeUtils\Model\Reflection\Type\MixedType;
21
-use Spaark\CompositeUtils\Model\Reflection\Type\StringType;
22
-use Spaark\CompositeUtils\Model\Reflection\Type\IntegerType;
23
-use Spaark\CompositeUtils\Model\Reflection\Type\BooleanType;
24
-use Spaark\CompositeUtils\Model\Reflection\Type\CollectionType;
25 20
 use Spaark\CompositeUtils\Model\Reflection\Type\ScalarType;
26 21
 use Spaark\CompositeUtils\Model\Reflection\Type\AbstractType;
27 22
 use Spaark\CompositeUtils\Exception\CannotWritePropertyException;
Please login to merge, or discard this patch.
Spacing   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -69,8 +69,7 @@  discard block
 block discarded – undo
69 69
         {
70 70
             if (!isset($args[$i]))
71 71
             {
72
-                throw new MissingRequiredParameterException
73
-                (
72
+                throw new MissingRequiredParameterException(
74 73
                     get_class($this->object),
75 74
                     $property->name
76 75
                 );
@@ -148,14 +147,12 @@  discard block
 block discarded – undo
148 147
     {
149 148
         if (!$this->reflect->properties->containsKey($property))
150 149
         {
151
-            throw new CannotWritePropertyException
152
-            (
150
+            throw new CannotWritePropertyException(
153 151
                 get_class($this->object), $property
154 152
             );
155 153
         }
156 154
 
157
-        $this->setAnyValue
158
-        (
155
+        $this->setAnyValue(
159 156
             $this->reflect->properties[$property],
160 157
             $value
161 158
         );
@@ -193,8 +190,7 @@  discard block
 block discarded – undo
193 190
      * @param ScalarType $valueType The scalar type
194 191
      * @param mixed $value The value to set
195 192
      */
196
-    private function setScalarValue
197
-    (
193
+    private function setScalarValue(
198 194
         ReflectionProperty $property,
199 195
         ScalarType $valueType,
200 196
         $value
@@ -204,16 +200,14 @@  discard block
 block discarded – undo
204 200
 
205 201
         if (is_scalar($value))
206 202
         {
207
-            $this->setRawValue
208
-            (
203
+            $this->setRawValue(
209 204
                 $property->name,
210 205
                 $property->type->cast($value)
211 206
             );
212 207
         }
213 208
         elseif (is_object($value) && method_exists([$value, $method]))
214 209
         {
215
-            $this->setScalarValue
216
-            (
210
+            $this->setScalarValue(
217 211
                 $property,
218 212
                 $valueType,
219 213
                 $value->$method()
@@ -231,14 +225,12 @@  discard block
 block discarded – undo
231 225
      * @param ReflectionProperty $property The property being set
232 226
      * @param AbstractType $valueType The value being set
233 227
      */
234
-    private function throwError
235
-    (
228
+    private function throwError(
236 229
         ReflectionProperty $property,
237 230
         AbstractType $valueType
238 231
     )
239 232
     {
240
-        throw new IllegalPropertyTypeException
241
-        (
233
+        throw new IllegalPropertyTypeException(
242 234
             get_class($this->object),
243 235
             $property->name,
244 236
             $property->type,
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -87,15 +87,13 @@  discard block
 block discarded – undo
87 87
             if ($building)
88 88
             {
89 89
                 $this->buildProperty($property);
90
-            }
91
-            else
90
+            } else
92 91
             {
93 92
                 if (isset($args[$i]))
94 93
                 {
95 94
                     $this->setAnyValue($property, $args[$i]);
96 95
                     $i++;
97
-                }
98
-                else
96
+                } else
99 97
                 {
100 98
                     $building = true;
101 99
                     $this->buildProperty($property);
@@ -119,8 +117,7 @@  discard block
 block discarded – undo
119 117
         if (!$property->type instanceof ObjectType)
120 118
         {
121 119
             $this->setAnyValue($property, 0);
122
-        }
123
-        elseif ($property->builtInConstructor)
120
+        } elseif ($property->builtInConstructor)
124 121
         {
125 122
             $class = (string)$property->type->classname;
126 123
             $this->setRawValue($property->name, new $class());
@@ -175,12 +172,10 @@  discard block
 block discarded – undo
175 172
         if ($comparator->compatible($property->type, $valueType))
176 173
         {
177 174
             $this->setRawValue($property->name, $value);
178
-        }
179
-        elseif ($property->type instanceof ScalarType)
175
+        } elseif ($property->type instanceof ScalarType)
180 176
         {
181 177
             $this->setScalarValue($property, $valueType, $value);
182
-        }
183
-        else
178
+        } else
184 179
         {
185 180
             $this->throwError($property, $valueType);
186 181
         }
@@ -209,8 +204,7 @@  discard block
 block discarded – undo
209 204
                 $property->name,
210 205
                 $property->type->cast($value)
211 206
             );
212
-        }
213
-        elseif (is_object($value) && method_exists([$value, $method]))
207
+        } elseif (is_object($value) && method_exists([$value, $method]))
214 208
         {
215 209
             $this->setScalarValue
216 210
             (
@@ -218,8 +212,7 @@  discard block
 block discarded – undo
218 212
                 $valueType,
219 213
                 $value->$method()
220 214
             );
221
-        }
222
-        else
215
+        } else
223 216
         {
224 217
             $this->throwError($property, $valueType);
225 218
         }
Please login to merge, or discard this patch.
src/Model/Reflection/Type/ObjectType.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,8 +59,7 @@
 block discarded – undo
59 59
      */
60 60
     public function equals($type) : bool
61 61
     {
62
-        if
63
-        (
62
+        if (
64 63
             $type instanceof ObjectType &&
65 64
             $type->classname === $this->classname &&
66 65
             $type->generics->size() === $this->generics->size()
Please login to merge, or discard this patch.
src/Service/TypeComparator.php 2 patches
Spacing   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,15 +32,13 @@  discard block
 block discarded – undo
32 32
      * @param AbstractType $child
33 33
      * @return boolean
34 34
      */
35
-    public function compatible
36
-    (
35
+    public function compatible(
37 36
         AbstractType $parent,
38 37
         AbstractType $child
39 38
     )
40 39
     : bool
41 40
     {
42
-        if
43
-        (
41
+        if (
44 42
             ($child instanceof NullType && $parent->nullable) ||
45 43
             ($parent instanceof MixedType)
46 44
         )
@@ -53,11 +51,9 @@  discard block
 block discarded – undo
53 51
         }
54 52
         elseif ($parent instanceof ObjectType)
55 53
         {
56
-            if
57
-            (
54
+            if (
58 55
                 $child instanceof ObjectType && 
59
-                is_a
60
-                (
56
+                is_a(
61 57
                     $child->classname->__toString(),
62 58
                     $parent->classname->__toString(),
63 59
                     true
@@ -66,8 +62,7 @@  discard block
 block discarded – undo
66 62
             {
67 63
                 foreach ($child->generics as $i => $generic)
68 64
                 {
69
-                    $compare = $this->compatible
70
-                    (
65
+                    $compare = $this->compatible(
71 66
                         $parent->generics[$i],
72 67
                         $generic
73 68
                     );
@@ -84,8 +79,7 @@  discard block
 block discarded – undo
84 79
             return false;
85 80
         }
86 81
 
87
-        throw new \DomainException
88
-        (
82
+        throw new \DomainException(
89 83
             'Unknown type: ' . get_class($parent)
90 84
         );
91 85
     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,12 +46,10 @@
 block discarded – undo
46 46
         )
47 47
         {
48 48
             return true;
49
-        }
50
-        elseif ($parent instanceof ScalarType)
49
+        } elseif ($parent instanceof ScalarType)
51 50
         {
52 51
             return get_class($parent) === get_class($child);
53
-        }
54
-        elseif ($parent instanceof ObjectType)
52
+        } elseif ($parent instanceof ObjectType)
55 53
         {
56 54
             if
57 55
             (
Please login to merge, or discard this patch.