Completed
Push — master ( 23b4c3...cb8b18 )
by stéphane
02:37
created
yaml/Loader.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
     //public
18 18
     /* @var null|string */
19 19
     public static $error;
20
-    public const IGNORE_DIRECTIVES = 1;//DONT include_directive
21
-    public const IGNORE_COMMENTS    = 2;//DONT include_comments
22
-    public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors
23
-    public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object
20
+    public const IGNORE_DIRECTIVES = 1; //DONT include_directive
21
+    public const IGNORE_COMMENTS    = 2; //DONT include_comments
22
+    public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors
23
+    public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object
24 24
 
25 25
     //privates
26 26
     /* @var null|false|array */
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
     /* @var null|string */
29 29
     private $filePath;
30 30
     /* @var integer */
31
-    private $debug = 0;///TODO: determine levels
31
+    private $debug = 0; ///TODO: determine levels
32 32
     /* @var integer */
33 33
     private $options = 0;
34 34
     //Exceptions messages
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         $source = $this->content ?? preg_split("/\n/m", preg_replace('/(\r\n|\r)/', "\n", $strContent), 0, PREG_SPLIT_DELIM_CAPTURE);
79 79
         //TODO : be more permissive on $strContent values
80 80
         if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
81
-        return function () use($source) {
81
+        return function() use($source) {
82 82
             foreach ($source as $key => $value) {
83 83
                 yield ++$key => $value;
84 84
             }
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
                 $target = $previous;
112 112
                 switch ($n->indent <=> $previous->indent) {
113 113
                     case -1:
114
-                        $target = $previous->getParent($n->indent);break;//, $n->type & Y::ITEM ? Y::KEY : null);
114
+                        $target = $previous->getParent($n->indent); break; //, $n->type & Y::ITEM ? Y::KEY : null);
115 115
                     case 0:
116
-                        $this->onEqualIndent($n, $previous, $target);break;
116
+                        $this->onEqualIndent($n, $previous, $target); break;
117 117
                     default:
118 118
                         $this->onMoreIndent($previous, $target);
119 119
                 }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     {
157 157
         $deepest = $previous->getDeepestNode();
158 158
         if ($n->type & Y::KEY && $n->indent === 0) {
159
-            $target = $previous->getParent(-1);//get root
159
+            $target = $previous->getParent(-1); //get root
160 160
         } elseif ($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) {
161 161
             $target = $deepest;
162 162
         } else {
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
                   && !($deepest->type & Y::LITTERALS)) {
193 193
             // $previous->getParent(0)->add($n);
194 194
             return true;
195
-        } elseif ($n->type & Y::TAG && is_null($n->value) ){//&& $previous->type & (Y::ROOT|Y::DOC_START|Y::DOC_END)) {
195
+        } elseif ($n->type & Y::TAG && is_null($n->value)) {//&& $previous->type & (Y::ROOT|Y::DOC_START|Y::DOC_END)) {
196 196
             $n->value = '';
197 197
         }
198 198
         return false;
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -77,7 +77,9 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $source = $this->content ?? preg_split("/\n/m", preg_replace('/(\r\n|\r)/', "\n", $strContent), 0, PREG_SPLIT_DELIM_CAPTURE);
79 79
         //TODO : be more permissive on $strContent values
80
-        if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
80
+        if (!is_array($source) || !count($source)) {
81
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
82
+        }
81 83
         return function () use($source) {
82 84
             foreach ($source as $key => $value) {
83 85
                 yield ++$key => $value;
@@ -105,7 +107,9 @@  discard block
 block discarded – undo
105 107
         try {
106 108
             foreach ($sourceIterator() as $lineNb => $lineString) {
107 109
                 $n = new Node($lineString, $lineNb);
108
-                if ($this->onSpecialType($n, $previous, $emptyLines, $lineString)) continue;
110
+                if ($this->onSpecialType($n, $previous, $emptyLines, $lineString)) {
111
+                    continue;
112
+                }
109 113
                 $this->attachBlankLines($emptyLines, $previous);
110 114
                 $emptyLines = [];
111 115
                 $target = $previous;
@@ -117,7 +121,9 @@  discard block
 block discarded – undo
117 121
                     default:
118 122
                         $this->onMoreIndent($previous, $target);
119 123
                 }
120
-                if ($this->onContextType($n, $target, $lineString)) continue;
124
+                if ($this->onContextType($n, $target, $lineString)) {
125
+                    continue;
126
+                }
121 127
                 $target->add($n);
122 128
                 $previous = $n;
123 129
             }
@@ -200,8 +206,12 @@  discard block
 block discarded – undo
200 206
 
201 207
     private function onSpecialBlank(array &$emptyLines, Node $n, Node $previous, Node $deepest)
202 208
     {
203
-        if ($previous->type & Y::SCALAR)   $emptyLines[] = $n->setParent($previous->getParent());
204
-        if ($deepest->type & Y::LITTERALS) $emptyLines[] = $n->setParent($deepest);
209
+        if ($previous->type & Y::SCALAR) {
210
+            $emptyLines[] = $n->setParent($previous->getParent());
211
+        }
212
+        if ($deepest->type & Y::LITTERALS) {
213
+            $emptyLines[] = $n->setParent($deepest);
214
+        }
205 215
     }
206 216
 
207 217
     private function onContextType(Node &$n, Node &$previous, $lineString):bool
Please login to merge, or discard this patch.