Completed
Push — master ( d38a64...a65b20 )
by stéphane
03:22
created
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.
yaml/Builder.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     private static function buildNodeList(NodeList $node, &$parent)
30 30
     {
31 31
         $type = &$node->type;
32
-        if ($type & (Y::RAW | Y::LITTERALS)) {
32
+        if ($type&(Y::RAW|Y::LITTERALS)) {
33 33
             return self::litteral($node, $type);
34 34
         }
35 35
         $p = $parent;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     private static function buildNode(Node $node, &$parent)
57 57
     {
58 58
         extract((array) $node, EXTR_REFS);
59
-        if ($type & (Y::REF_DEF | Y::REF_CALL)) {
59
+        if ($type&(Y::REF_DEF|Y::REF_CALL)) {
60 60
             if (is_object($value)) {
61 61
                 $tmp = self::build($value, $parent) ?? $parent;
62 62
             } else {
@@ -176,15 +176,15 @@  discard block
 block discarded – undo
176 176
     {
177 177
         self::$_root = new YamlObject();
178 178
         $childTypes = $list->getTypes();
179
-        $isMapping  = (bool) (Y::KEY | Y::MAPPING) & $childTypes;
179
+        $isMapping  = (bool) (Y::KEY|Y::MAPPING)&$childTypes;
180 180
         $isSequence = (bool) Y::ITEM & $childTypes;
181 181
         $isSet      = (bool) Y::SET_VALUE & $childTypes;
182 182
         if ($isMapping && $isSequence) {
183 183
             throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key));
184 184
         } else {
185 185
             switch (true) {
186
-                case $isSequence: $list->type = Y::SEQUENCE;break;
187
-                case $isSet:      $list->type = Y::SET;break;
186
+                case $isSequence: $list->type = Y::SEQUENCE; break;
187
+                case $isSet:      $list->type = Y::SET; break;
188 188
                 default:          $list->type = Y::MAPPING;
189 189
             }
190 190
         }
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
         $children->rewind();
207 207
         $refIndent = $children->current()->indent;
208 208
         $separator = $type === Y::RAW ? '' : "\n";
209
-        $action = function ($c) { return (string) $c->value; };
209
+        $action = function($c) { return (string) $c->value; };
210 210
         //TODO: use iterator_to_array for LITT & RAW
211
-        if ($type & Y::LITT_FOLDED) {
211
+        if ($type&Y::LITT_FOLDED) {
212 212
             $separator = ' ';
213
-            $action = function ($c) use ($refIndent) {
213
+            $action = function($c) use ($refIndent) {
214 214
                 return $c->indent > $refIndent || ($c->type & Y::BLANK) ? "\n".$c->value : $c->value;
215 215
             };
216 216
         }
Please login to merge, or discard this patch.
yaml/Node.php 1 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.
yaml/Loader.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -19,17 +19,17 @@  discard block
 block discarded – undo
19 19
     /* @var null|string */
20 20
     public $error;
21 21
 
22
-    public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive
23
-    public const IGNORE_COMMENTS    = 2;//DONT include_comments
24
-    public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors
25
-    public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object
22
+    public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive
23
+    public const IGNORE_COMMENTS    = 2; //DONT include_comments
24
+    public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors
25
+    public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object
26 26
     //privates
27 27
     /* @var null|string */
28 28
     private $content;
29 29
     /* @var null|string */
30 30
     private $filePath;
31 31
     /* @var integer */
32
-    private $debug = 0;///TODO: determine levels
32
+    private $debug = 0; ///TODO: determine levels
33 33
     /* @var integer */
34 34
     private $options = 0;
35 35
     //Exceptions messages
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 $target->add($n);
118 118
                 $previous = $n;
119 119
             }
120
-            if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n",var_export($root, true);
120
+            if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n", var_export($root, true);
121 121
             $out = Builder::buildContent($root, $this->debug);
122 122
             return $out;
123 123
         } catch (\Error|\Exception|\ParseError $e) {
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $deepest->parse($deepest->value.' '.ltrim($lineString));
156 156
             return true;
157 157
         }
158
-        if(($previous->type & Y::LITTERALS) || (($deepest->type & Y::LITTERALS) && is_null($deepest->value))) {
158
+        if (($previous->type & Y::LITTERALS) || (($deepest->type & Y::LITTERALS) && is_null($deepest->value))) {
159 159
             $n->type = Y::SCALAR;
160 160
             $n->identifier = null;
161 161
             $n->value = trim($lineString);
Please login to merge, or discard this patch.
yaml/Dumper.php 1 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.