Passed
Pull Request — dev (#170)
by Marcin
02:47
created
src/Contracts/ConverterContract.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@
 block discarded – undo
15 15
  */
16 16
 interface ConverterContract
17 17
 {
18
-    /**
19
-     * Returns array representation of the object.
20
-     *
21
-     * @param object $obj    Object to be converted
22
-     * @param array  $config Converter config array to be used for this object (based on exact class
23
-     *                       name match or inheritance).
24
-     *
25
-     * @return array
26
-     */
27
-    public function convert(object $obj, array $config): array;
18
+	/**
19
+	 * Returns array representation of the object.
20
+	 *
21
+	 * @param object $obj    Object to be converted
22
+	 * @param array  $config Converter config array to be used for this object (based on exact class
23
+	 *                       name match or inheritance).
24
+	 *
25
+	 * @return array
26
+	 */
27
+	public function convert(object $obj, array $config): array;
28 28
 }
Please login to merge, or discard this patch.
src/Converters/ToArrayConverter.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -19,19 +19,19 @@
 block discarded – undo
19 19
 
20 20
 final class ToArrayConverter implements ConverterContract
21 21
 {
22
-    /**
23
-     * Returns array representation of the object.
24
-     *
25
-     * @param object $obj    Object to be converted
26
-     * @param array  $config Converter config array to be used for this object (based on exact class
27
-     *                       name match or inheritance).
28
-     *
29
-     * @return array
30
-     */
31
-    public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array
32
-    {
33
-        Validator::assertIsObject('obj', $obj);
22
+	/**
23
+	 * Returns array representation of the object.
24
+	 *
25
+	 * @param object $obj    Object to be converted
26
+	 * @param array  $config Converter config array to be used for this object (based on exact class
27
+	 *                       name match or inheritance).
28
+	 *
29
+	 * @return array
30
+	 */
31
+	public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array
32
+	{
33
+		Validator::assertIsObject('obj', $obj);
34 34
 
35
-        return $obj->toArray();
36
-    }
35
+		return $obj->toArray();
36
+	}
37 37
 }
Please login to merge, or discard this patch.
src/Converters/ArrayableConverter.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -19,19 +19,19 @@
 block discarded – undo
19 19
 
20 20
 final class ArrayableConverter implements ConverterContract
21 21
 {
22
-    /**
23
-     * Returns array representation of the object implementing Arrayable interface
24
-     *
25
-     * @param Arrayable $obj    Object to be converted
26
-     * @param array     $config Converter config array to be used for this object (based on exact class
27
-     *                          name match or inheritance).
28
-     *
29
-     * @return array
30
-     */
31
-    public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array
32
-    {
33
-        Validator::assertInstanceOf('obj', $obj, Arrayable::class);
22
+	/**
23
+	 * Returns array representation of the object implementing Arrayable interface
24
+	 *
25
+	 * @param Arrayable $obj    Object to be converted
26
+	 * @param array     $config Converter config array to be used for this object (based on exact class
27
+	 *                          name match or inheritance).
28
+	 *
29
+	 * @return array
30
+	 */
31
+	public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array
32
+	{
33
+		Validator::assertInstanceOf('obj', $obj, Arrayable::class);
34 34
 
35
-        return $obj->toArray();
36
-    }
35
+		return $obj->toArray();
36
+	}
37 37
 }
Please login to merge, or discard this patch.
src/Util.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -18,60 +18,60 @@
 block discarded – undo
18 18
  */
19 19
 final class Util
20 20
 {
21
-    /**
22
-     * Merges the configs together and takes multi-dimensional arrays into account.
23
-     * Support for multi-dimensional config array. Built-in config merge only supports flat arrays.
24
-     * Throws \RuntimeException if arrays stucture causes type conflics (i.e. you want to merge
25
-     * array with int).
26
-     *
27
-     * @param array $original Array to merge other array into. Usually default values to overwrite.
28
-     * @param array $merging  Array with items to be merged into $original, overriding (primitives) or merging
29
-     *                        (arrays) entries in destination array.
30
-     *
31
-     * @return array
32
-     *
33
-     * @throws \RuntimeException
34
-     */
35
-    public static function mergeConfig(array $original, array $merging): array
36
-    {
37
-        $array = $original;
38
-        foreach ($merging as $m_key => $m_val) {
39
-            if (\array_key_exists($m_key, $original)) {
40
-                $orig_type = \gettype($original[ $m_key ]);
41
-                $m_type = \gettype($m_val);
42
-                if ($orig_type !== $m_type) {
43
-                    throw new Ex\IncompatibleTypeException(
44
-                        "Incompatible types. Cannot merge {$m_type} into {$orig_type} (key '{$m_key}').");
45
-                }
21
+	/**
22
+	 * Merges the configs together and takes multi-dimensional arrays into account.
23
+	 * Support for multi-dimensional config array. Built-in config merge only supports flat arrays.
24
+	 * Throws \RuntimeException if arrays stucture causes type conflics (i.e. you want to merge
25
+	 * array with int).
26
+	 *
27
+	 * @param array $original Array to merge other array into. Usually default values to overwrite.
28
+	 * @param array $merging  Array with items to be merged into $original, overriding (primitives) or merging
29
+	 *                        (arrays) entries in destination array.
30
+	 *
31
+	 * @return array
32
+	 *
33
+	 * @throws \RuntimeException
34
+	 */
35
+	public static function mergeConfig(array $original, array $merging): array
36
+	{
37
+		$array = $original;
38
+		foreach ($merging as $m_key => $m_val) {
39
+			if (\array_key_exists($m_key, $original)) {
40
+				$orig_type = \gettype($original[ $m_key ]);
41
+				$m_type = \gettype($m_val);
42
+				if ($orig_type !== $m_type) {
43
+					throw new Ex\IncompatibleTypeException(
44
+						"Incompatible types. Cannot merge {$m_type} into {$orig_type} (key '{$m_key}').");
45
+				}
46 46
 
47
-                if (\is_array($merging[ $m_key ])) {
48
-                    $array[ $m_key ] = static::mergeConfig($original[ $m_key ], $m_val);
49
-                } else {
50
-                    $array[ $m_key ] = $m_val;
51
-                }
52
-            } else {
53
-                $array[ $m_key ] = $m_val;
54
-            }
55
-        }
47
+				if (\is_array($merging[ $m_key ])) {
48
+					$array[ $m_key ] = static::mergeConfig($original[ $m_key ], $m_val);
49
+				} else {
50
+					$array[ $m_key ] = $m_val;
51
+				}
52
+			} else {
53
+				$array[ $m_key ] = $m_val;
54
+			}
55
+		}
56 56
 
57
-        return $array;
58
-    }
57
+		return $array;
58
+	}
59 59
 
60
-    /**
61
-     * Sorts array (in place) by value, assuming value is an array and contains `pri` key with integer
62
-     * (positive/negative) value which is used for sorting higher -> lower priority.
63
-     *
64
-     * @param array &$array
65
-     */
66
-    public static function sortArrayByPri(array &$array): void
67
-    {
68
-        uasort($array, static function(array $array_a, array $array_b) {
69
-            $pri_a = $array_a['pri'] ?? 0;
70
-            $pri_b = $array_b['pri'] ?? 0;
60
+	/**
61
+	 * Sorts array (in place) by value, assuming value is an array and contains `pri` key with integer
62
+	 * (positive/negative) value which is used for sorting higher -> lower priority.
63
+	 *
64
+	 * @param array &$array
65
+	 */
66
+	public static function sortArrayByPri(array &$array): void
67
+	{
68
+		uasort($array, static function(array $array_a, array $array_b) {
69
+			$pri_a = $array_a['pri'] ?? 0;
70
+			$pri_b = $array_b['pri'] ?? 0;
71 71
 
72
-            return $pri_b <=> $pri_a;
73
-        });
74
-    }
72
+			return $pri_b <=> $pri_a;
73
+		});
74
+	}
75 75
 
76 76
 	/**
77 77
 	 * Checks if given array uses custom (non numeric) keys.
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,20 +37,20 @@
 block discarded – undo
37 37
         $array = $original;
38 38
         foreach ($merging as $m_key => $m_val) {
39 39
             if (\array_key_exists($m_key, $original)) {
40
-                $orig_type = \gettype($original[ $m_key ]);
40
+                $orig_type = \gettype($original[$m_key]);
41 41
                 $m_type = \gettype($m_val);
42 42
                 if ($orig_type !== $m_type) {
43 43
                     throw new Ex\IncompatibleTypeException(
44 44
                         "Incompatible types. Cannot merge {$m_type} into {$orig_type} (key '{$m_key}').");
45 45
                 }
46 46
 
47
-                if (\is_array($merging[ $m_key ])) {
48
-                    $array[ $m_key ] = static::mergeConfig($original[ $m_key ], $m_val);
47
+                if (\is_array($merging[$m_key])) {
48
+                    $array[$m_key] = static::mergeConfig($original[$m_key], $m_val);
49 49
                 } else {
50
-                    $array[ $m_key ] = $m_val;
50
+                    $array[$m_key] = $m_val;
51 51
                 }
52 52
             } else {
53
-                $array[ $m_key ] = $m_val;
53
+                $array[$m_key] = $m_val;
54 54
             }
55 55
         }
56 56
 
Please login to merge, or discard this patch.
src/Validator.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@
 block discarded – undo
132 132
 	 * @throws \InvalidArgumentException
133 133
 	 */
134 134
 	public static function assertIsType(string $var_name, $value, array $allowed_types,
135
-	                                    string $ex_class = Ex\InvalidTypeException::class): void
135
+										string $ex_class = Ex\InvalidTypeException::class): void
136 136
 	{
137 137
 		$type = \gettype($value);
138 138
 		if (!\in_array($type, $allowed_types, true)) {
Please login to merge, or discard this patch.
src/Converter.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 		$result = null;
61 61
 
62 62
 		$type = \gettype($data);
63
-		$result = $this->primitives[ $type ] ?? null;
63
+		$result = $this->primitives[$type] ?? null;
64 64
 
65 65
 		if ($result === null) {
66 66
 			throw new Ex\ConfigurationNotFoundException(
@@ -92,13 +92,13 @@  discard block
 block discarded – undo
92 92
 		$cls = \get_class($data);
93 93
 		if (\is_string($cls)) {
94 94
 			if (\array_key_exists($cls, $this->classes)) {
95
-				$result = $this->classes[ $cls ];
95
+				$result = $this->classes[$cls];
96 96
 				$debug_result = 'exact config match';
97 97
 			} else {
98 98
 				// no exact match, then lets try with `instanceof`
99 99
 				foreach (\array_keys($this->classes) as $class_name) {
100 100
 					if ($data instanceof $class_name) {
101
-						$result = $this->classes[ $class_name ];
101
+						$result = $this->classes[$class_name];
102 102
 						$debug_result = "subclass of {$class_name}";
103 103
 						break;
104 104
 					}
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
 
145 145
 		if ($result === null && \is_object($data)) {
146 146
 			$cfg = $this->getClassMappingConfigOrThrow($data);
147
-			$worker = new $cfg[ RB::KEY_HANDLER ]();
147
+			$worker = new $cfg[RB::KEY_HANDLER]();
148 148
 			$result = $worker->convert($data, $cfg);
149
-			$result = empty($cfg[ RB::KEY_KEY ]) ? $result : [$cfg[ RB::KEY_KEY ] => $result];
149
+			$result = empty($cfg[RB::KEY_KEY]) ? $result : [$cfg[RB::KEY_KEY] => $result];
150 150
 		}
151 151
 
152 152
 		if ($result === null && \is_array($data)) {
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 
155 155
 			$result = $this->convertArray($data);
156 156
 			if (!Util::isArrayWithNonNumericKeys($data)) {
157
-				$result = [$cfg[ RB::KEY_KEY ] => $result];
157
+				$result = [$cfg[RB::KEY_KEY] => $result];
158 158
 			}
159 159
 		}
160 160
 
161 161
 		if (\is_bool($data) || \is_float($data) || \is_int($data) || \is_string($data)) {
162
-			$result = [$this->getPrimitiveMappingConfigOrThrow($data)[ RB::KEY_KEY ] => $data];
162
+			$result = [$this->getPrimitiveMappingConfigOrThrow($data)[RB::KEY_KEY] => $data];
163 163
 		}
164 164
 
165 165
 		return $result;
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 
180 180
 		foreach ($data as $key => $val) {
181 181
 			if (\is_array($val)) {
182
-				$data[ $key ] = $this->convertArray($val);
182
+				$data[$key] = $this->convertArray($val);
183 183
 			} elseif (\is_object($val)) {
184 184
 				$cfg = $this->getClassMappingConfigOrThrow($val);
185
-				$worker = new $cfg[ RB::KEY_HANDLER ]();
185
+				$worker = new $cfg[RB::KEY_HANDLER]();
186 186
 				$converted_data = $worker->convert($val, $cfg);
187
-				$data[ $key ] = $converted_data;
187
+				$data[$key] = $converted_data;
188 188
 			}
189 189
 		}
190 190
 
Please login to merge, or discard this patch.
src/ResponseBuilderServiceProvider.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
 
79 79
 		Util::sortArrayByPri($merged_config['converter']['classes']);
80 80
 
81
-        $this->app['config']->set($key, $merged_config);
82
-    }
81
+		$this->app['config']->set($key, $merged_config);
82
+	}
83 83
 
84 84
 }
Please login to merge, or discard this patch.