Completed
Push — master ( a65b20...519791 )
by stéphane
02:30
created
yaml/Tag.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
         if (is_null($tagName)) {
17 17
             throw new \Exception(self::class.": a tag MUST have a name", 1);
18 18
         }
19
-        $this->tagName  = $tagName;
19
+        $this->tagName = $tagName;
20 20
         $this->value = $value;
21 21
     }
22 22
 
Please login to merge, or discard this patch.
yaml/Regex.php 3 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@
 block discarded – undo
32 32
     {
33 33
         $d         = "\\d{4}([-\\/])\\d{2}\\1\\d{2}";
34 34
         $h         = "\\d{2}(:)\\d{2}\\2\\d{2}";
35
-        $date      =  "/^$d$/";// 2002-12-14, 2002/12/14
36
-        $canonical =  "/^$d(?:t| )$h\\.\\dz?$/im";// 2001-12-15T02:59:43.1Z
37
-        $spaced    =  "/^$d(?:t| )$h\\.\\d{2} [-+]\\d$/im";// 2001-12-14 21:59:43.10 -5
38
-        $iso8601   =  "/^$d(?:t| )$h\\.\\d{2}[-+]\\d{2}\\2\\d{2}/im";// 2001-12-14t21:59:43.10-05:00
35
+        $date      = "/^$d$/"; // 2002-12-14, 2002/12/14
36
+        $canonical = "/^$d(?:t| )$h\\.\\dz?$/im"; // 2001-12-15T02:59:43.1Z
37
+        $spaced    = "/^$d(?:t| )$h\\.\\d{2} [-+]\\d$/im"; // 2001-12-14 21:59:43.10 -5
38
+        $iso8601   = "/^$d(?:t| )$h\\.\\d{2}[-+]\\d{2}\\2\\d{2}/im"; // 2001-12-14t21:59:43.10-05:00
39 39
         $matchDate      = preg_match($date, $v);
40 40
         $matchCanonical = preg_match($canonical, $v);
41 41
         $matchSpaced    = preg_match($spaced, $v);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,9 @@
 block discarded – undo
40 40
         $matchCanonical = preg_match($canonical, $v);
41 41
         $matchSpaced    = preg_match($spaced, $v);
42 42
         $matchIso       = preg_match($iso8601, $v);
43
-        if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso))
44
-          throw new \Exception("Regex date error");
43
+        if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) {
44
+                  throw new \Exception("Regex date error");
45
+        }
45 46
 
46 47
         return $matchDate || $matchCanonical || $matchSpaced || $matchIso;
47 48
     }
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
         $matchSpaced    = preg_match($spaced, $v);
38 38
         $matchIso       = preg_match($iso8601, $v);
39 39
         if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso))
40
-          throw new \Exception("Regex date error");
40
+            throw new \Exception("Regex date error");
41 41
 
42 42
         return $matchDate || $matchCanonical || $matchSpaced || $matchIso;
43 43
     }
Please login to merge, or discard this patch.
yaml/YamlObject.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
     public function __construct()
22 22
     {
23
-        parent::__construct([], 1);//1 = Array indices can be accessed as properties in read/write.
23
+        parent::__construct([], 1); //1 = Array indices can be accessed as properties in read/write.
24 24
         $this->__yaml__object__api = new API();
25 25
     }
26 26
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
     public function __call($funcName, $arguments)
29 29
     {
30 30
         $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api));
31
-        $getName = function ($o) { return $o->name; };
31
+        $getName = function($o) { return $o->name; };
32 32
         $publicApi  = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC));
33 33
         $privateApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PRIVATE));
34 34
         if (!in_array($funcName, $publicApi) && !in_array($funcName, $privateApi)) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,12 @@
 block discarded – undo
40 40
     {
41 41
         $prop = get_object_vars($this);
42 42
         unset($prop["__yaml__object__api"]);
43
-        if (count($prop) > 0) return $prop;
44
-        if (count($this) > 0) return iterator_to_array($this);
43
+        if (count($prop) > 0) {
44
+            return $prop;
45
+        }
46
+        if (count($this) > 0) {
47
+            return iterator_to_array($this);
48
+        }
45 49
         return $this->__yaml__object__api->value;
46 50
     }
47 51
 }
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 namespace Dallgoot\Yaml;
3 3
 
4 4
 /**
5
-  *  The returned object representing a YAML file content
5
+ *  The returned object representing a YAML file content
6 6
  * @category tag in class comment
7 7
  * @package tag in class comment
8 8
  * @author tag in class comment
Please login to merge, or discard this patch.
yaml/Node.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -288,13 +288,13 @@
 block discarded – undo
288 288
     private static function getScalar(string $v)
289 289
     {
290 290
         $types = ['yes'   => true,
291
-                  'no'    => false,
292
-                  'true'  => true,
293
-                  'false' => false,
294
-                  'null'  => null,
295
-                  '.inf'  => INF,
296
-                  '-.inf' => -INF,
297
-                  '.nan'  => NAN
291
+                    'no'    => false,
292
+                    'true'  => true,
293
+                    'false' => false,
294
+                    'null'  => null,
295
+                    '.inf'  => INF,
296
+                    '-.inf' => -INF,
297
+                    '.nan'  => NAN
298 298
         ];
299 299
         if (isset($types[strtolower($v)])) return $types[strtolower($v)];
300 300
         if (R::isDate($v))   return date_create($v);
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
             //modify type according to child
95 95
             switch ($child->type) {
96 96
                 case Y::COMMENT: //fall through
97
-                case Y::KEY:     $this->value->type = Y::MAPPING;break;
98
-                case Y::ITEM:    $this->value->type = Y::SEQUENCE;break;
97
+                case Y::KEY:     $this->value->type = Y::MAPPING; break;
98
+                case Y::ITEM:    $this->value->type = Y::SEQUENCE; break;
99 99
             }
100 100
             $this->type & Y::LITTERALS && $this->value->type = $this->type;
101 101
         }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public function parse(string $nodeString):Node
121 121
     {
122
-        $nodeValue = preg_replace("/^\t+/m", " ", $nodeString);//permissive to tabs but replacement
122
+        $nodeValue = preg_replace("/^\t+/m", " ", $nodeString); //permissive to tabs but replacement
123 123
         $this->indent = strspn($nodeValue, ' ');
124 124
         $nodeValue = ltrim($nodeValue);
125 125
         if ($nodeValue === '') {
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             case '#': return [Y::COMMENT, ltrim($v)];
157 157
             case "-": return $this->onHyphen($nodeValue);
158 158
             case '%': return [Y::DIRECTIVE, ltrim($v)];
159
-            case '?': return [Y::SET_KEY,   empty($v) ? null : new Node(ltrim($v), $this->line)];
159
+            case '?': return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)];
160 160
             case ':': return [Y::SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)];
161 161
             case '>': return [Y::LITT_FOLDED, null];
162 162
             case '|': return [Y::LITT, null];
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
             if (!is_bool($hasComment)) {
182 182
                 $tmpNode = new Node(trim(substr($value, 0, $hasComment)), $this->line);
183 183
                 if ($tmpNode->type !== Y::PARTIAL) {
184
-                    $comment = new Node(trim(substr($value, $hasComment+1)), $this->line);
185
-                    $comment->identifier = true;//to specify it is NOT a fullline comment
184
+                    $comment = new Node(trim(substr($value, $hasComment + 1)), $this->line);
185
+                    $comment->identifier = true; //to specify it is NOT a fullline comment
186 186
                     $this->add($comment);
187 187
                     $n = $tmpNode;
188 188
                 }
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         $type = ['!' => Y::TAG, '&' => Y::REF_DEF, '*' => Y::REF_CALL][$nodeValue[0]];
251 251
         $pos = strpos($v, ' ');
252 252
         $this->identifier = is_bool($pos) ? $v : strstr($v, ' ', true);
253
-        $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos+1)), $this->line))->setParent($this);
253
+        $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos + 1)), $this->line))->setParent($this);
254 254
         return [$type, $n];
255 255
     }
256 256
 
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
     {
264 264
         $v = &$this->value;
265 265
         if (is_null($v)) return null;
266
-        if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v);
267
-        if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
266
+        if ($this->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($v);
267
+        if ($this->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
268 268
         switch ($this->type) {
269 269
             case Y::JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
270 270
             case Y::QUOTED: return substr($v, 1, -1);
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
     {
321 321
         $out = new Compact();
322 322
         if ($type === Y::COMPACT_SEQUENCE) {
323
-            $f = function ($e) { return self::getScalar(trim($e));};
323
+            $f = function($e) { return self::getScalar(trim($e)); };
324 324
             //TODO : that's not robust enough, improve it
325 325
             foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) {
326 326
                 $out[$key] = $value;
Please login to merge, or discard this patch.
Braces   +45 added lines, -15 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function getParent(int $indent = null):Node
61 61
     {
62
-        if (!is_int($indent)) return $this->parent ?? $this;
62
+        if (!is_int($indent)) {
63
+            return $this->parent ?? $this;
64
+        }
63 65
         $cursor = $this;
64 66
         while ($cursor instanceof Node && $cursor->indent >= $indent) {
65 67
             $cursor = $cursor->parent;
@@ -150,8 +152,12 @@  discard block
 block discarded – undo
150 152
             $type = R::isProperlyQuoted($nodeValue) ? Y::QUOTED : Y::PARTIAL;
151 153
             return [$type, $nodeValue];
152 154
         }
153
-        if (in_array($first, ['{', '[']))      return $this->onObject($nodeValue);
154
-        if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue);
155
+        if (in_array($first, ['{', '['])) {
156
+            return $this->onObject($nodeValue);
157
+        }
158
+        if (in_array($first, ['!', '&', '*'])) {
159
+            return $this->onNodeAction($nodeValue);
160
+        }
155 161
         switch ($first) {
156 162
             case '#': return [Y::COMMENT, ltrim($v)];
157 163
             case "-": return $this->onHyphen($nodeValue);
@@ -203,9 +209,15 @@  discard block
 block discarded – undo
203 209
     private function onObject($value):array
204 210
     {
205 211
         json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
206
-        if (json_last_error() === JSON_ERROR_NONE)  return [Y::JSON, $value];
207
-        if (preg_match(R::MAPPING, $value))         return [Y::COMPACT_MAPPING, $value];
208
-        if (preg_match(R::SEQUENCE, $value))        return [Y::COMPACT_SEQUENCE, $value];
212
+        if (json_last_error() === JSON_ERROR_NONE) {
213
+            return [Y::JSON, $value];
214
+        }
215
+        if (preg_match(R::MAPPING, $value)) {
216
+            return [Y::COMPACT_MAPPING, $value];
217
+        }
218
+        if (preg_match(R::SEQUENCE, $value)) {
219
+            return [Y::COMPACT_SEQUENCE, $value];
220
+        }
209 221
         return [Y::PARTIAL, $value];
210 222
     }
211 223
 
@@ -220,7 +232,9 @@  discard block
 block discarded – undo
220 232
     {
221 233
         if (substr($nodeValue, 0, 3) === '---') {
222 234
             $rest = trim(substr($nodeValue, 3));
223
-            if (empty($rest)) return [Y::DOC_START, null];
235
+            if (empty($rest)) {
236
+                return [Y::DOC_START, null];
237
+            }
224 238
             $n = new Node($rest, $this->line);
225 239
             $n->indent = $this->indent + 4;
226 240
             return [Y::DOC_START, $n->setParent($this)];
@@ -262,9 +276,15 @@  discard block
 block discarded – undo
262 276
     public function getPhpValue()
263 277
     {
264 278
         $v = &$this->value;
265
-        if (is_null($v)) return null;
266
-        if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v);
267
-        if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
279
+        if (is_null($v)) {
280
+            return null;
281
+        }
282
+        if ($this->type & (Y::REF_CALL | Y::SCALAR)) {
283
+            return self::getScalar($v);
284
+        }
285
+        if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) {
286
+            return self::getCompact(substr($v, 1, -1), $this->type);
287
+        }
268 288
         switch ($this->type) {
269 289
             case Y::JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
270 290
             case Y::QUOTED: return substr($v, 1, -1);
@@ -293,9 +313,15 @@  discard block
 block discarded – undo
293 313
                   '-.inf' => -INF,
294 314
                   '.nan'  => NAN
295 315
         ];
296
-        if (isset($types[strtolower($v)])) return $types[strtolower($v)];
297
-        if (R::isDate($v))   return date_create($v);
298
-        if (R::isNumber($v)) return self::getNumber($v);
316
+        if (isset($types[strtolower($v)])) {
317
+            return $types[strtolower($v)];
318
+        }
319
+        if (R::isDate($v)) {
320
+            return date_create($v);
321
+        }
322
+        if (R::isNumber($v)) {
323
+            return self::getNumber($v);
324
+        }
299 325
         return strval($v);
300 326
     }
301 327
 
@@ -308,8 +334,12 @@  discard block
 block discarded – undo
308 334
      */
309 335
     private static function getNumber(string $v)
310 336
     {
311
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
312
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
337
+        if (preg_match("/^(0o\d+)$/i", $v)) {
338
+            return intval(base_convert($v, 8, 10));
339
+        }
340
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
341
+            return intval(base_convert($v, 16, 10));
342
+        }
313 343
         // TODO: remove these if not needed
314 344
         // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through
315 345
         // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v):
Please login to merge, or discard this patch.
yaml/Compact.php 2 patches
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,8 +27,12 @@
 block discarded – undo
27 27
     public function jsonSerialize()
28 28
     {
29 29
         $prop = get_object_vars($this);
30
-        if (count($prop) > 0) return $prop;
31
-        if (count($this) > 0) return iterator_to_array($this);
30
+        if (count($prop) > 0) {
31
+            return $prop;
32
+        }
33
+        if (count($this) > 0) {
34
+            return iterator_to_array($this);
35
+        }
32 36
     }
33 37
 
34 38
     public static function wrap($arrayOrObject)
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
             foreach ($arrayOrObject as $key => $value) {
43 43
                 $out[$key] = $value;
44 44
             }
45
-        } elseif (is_object($arrayOrObject)){
45
+        } elseif (is_object($arrayOrObject)) {
46 46
             $propList = get_object_vars($arrayOrObject);
47 47
             foreach ($propList as $prop => $value) {
48 48
                 $arrayOrObject->{$prop} = $value;
Please login to merge, or discard this patch.
yaml/Dumper.php 2 patches
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,7 +21,9 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function __construct(int $options = null)
23 23
     {
24
-        if (is_int($options)) self::$options = $options;
24
+        if (is_int($options)) {
25
+            self::$options = $options;
26
+        }
25 27
     }
26 28
 
27 29
     /**
@@ -36,7 +38,9 @@  discard block
 block discarded – undo
36 38
      */
37 39
     public static function toString($dataType, int $options = null):string
38 40
     {
39
-        if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1);
41
+        if (is_null($dataType)) {
42
+            throw new \Exception(self::class.": No content to convert to Yaml", 1);
43
+        }
40 44
         self::$options = is_int($options) ? $options : self::OPTIONS;
41 45
         self::$result = new DLL;
42 46
         self::$result->setIteratorMode(DLL::IT_MODE_FIFO|DLL::IT_MODE_DELETE);
@@ -74,8 +78,12 @@  discard block
 block discarded – undo
74 78
         if (is_scalar($dataType)) {
75 79
             switch (gettype($dataType)) {
76 80
                 case 'boolean': return $dataType ? 'true' : 'false';
77
-                case 'float': if (is_infinite((float) $dataType)) return $dataType > 0 ? '.inf' : '-.inf';
78
-                case 'double': if (is_nan((float) $dataType)) return '.nan';
81
+                case 'float': if (is_infinite((float) $dataType)) {
82
+                    return $dataType > 0 ? '.inf' : '-.inf';
83
+                }
84
+                case 'double': if (is_nan((float) $dataType)) {
85
+                    return '.nan';
86
+                }
79 87
                 default:
80 88
                     return $dataType;
81 89
             }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
         // foreach (self::$result as $value) {
55 55
         //     $out .= $value."\n";
56 56
         // }
57
-        $out = implode("\n", iterator_to_array(self::$result));//TODO: replace by iterator_to_array and implode ???
57
+        $out = implode("\n", iterator_to_array(self::$result)); //TODO: replace by iterator_to_array and implode ???
58 58
         self::$result = null;
59 59
         return $out;
60 60
     }
Please login to merge, or discard this patch.
example.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once __DIR__ . '/vendor/autoload.php';
2
+require_once __DIR__.'/vendor/autoload.php';
3 3
 
4 4
 use \Dallgoot\Yaml as Y;
5 5
 
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 /* USE CASE 1
11 11
 * load and parse if file exists
12 12
 */
13
-$yaml = Y::parseFile('./tests/cases/examples/Example_2_18.yml', null, 2);//->parse();
13
+$yaml = Y::parseFile('./tests/cases/examples/Example_2_18.yml', null, 2); //->parse();
14 14
 // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1);
15 15
 var_dump($yaml);
16 16
 exit(0);
Please login to merge, or discard this patch.
yaml/NodeList.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 class NodeList extends \SplDoublyLinkedList
14 14
 {
15 15
     /* @var null|int */
16
-    public $type = null;//Y::LITT_FOLDED;
16
+    public $type = null; //Y::LITT_FOLDED;
17 17
 
18 18
     /**
19 19
      * NodeList constructor
Please login to merge, or discard this patch.
yaml/Yaml.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,14 +21,14 @@
 block discarded – undo
21 21
     const ITEM             = 128;
22 22
     const JSON             = 256;
23 23
     const KEY              = 512;
24
-    const LITT             = 1024;//litteral
25
-    const LITT_FOLDED      = 2048;//litteral
24
+    const LITT             = 1024; //litteral
25
+    const LITT_FOLDED      = 2048; //litteral
26 26
     const MAPPING          = 4096;
27 27
     const PARTIAL          = 8192;
28 28
     const QUOTED           = 16384;
29 29
     const RAW              = 32768;
30
-    const REF_CALL         = 65536;//reference
31
-    const REF_DEF          = 131072;//reference
30
+    const REF_CALL         = 65536; //reference
31
+    const REF_DEF          = 131072; //reference
32 32
     const ROOT             = 262144;
33 33
     const SCALAR           = 524288;
34 34
     const SEQUENCE         = 1048576;
Please login to merge, or discard this patch.