Completed
Branch master (f81cc4)
by stéphane
07:03
created
sources/API.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@
 block discarded – undo
69 69
             return $this->_anchors[$name];
70 70
         }
71 71
         throw new \UnexpectedValueException(sprintf(self::UNKNOWN_REFERENCE,
72
-                                                    $name, implode(',',array_keys($this->_anchors)))
72
+                                                    $name, implode(',', array_keys($this->_anchors)))
73 73
                                                 );
74 74
     }
75 75
 
Please login to merge, or discard this patch.
sources/types/YamlObject.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,9 +46,9 @@
 block discarded – undo
46 46
     public function __call($funcName, $arguments)
47 47
     {
48 48
         $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api));
49
-        $getName    = function ($o) { return $o->name; };
49
+        $getName    = function($o) { return $o->name; };
50 50
         $publicApi  = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC));
51
-        if (!in_array($funcName, $publicApi) ) {
51
+        if (!in_array($funcName, $publicApi)) {
52 52
             throw new \BadMethodCallException(sprintf(self::UNDEFINED_METHOD, $funcName, implode(",", $publicApi)));
53 53
         }
54 54
         return call_user_func_array([$this->__yaml__object__api, $funcName], $arguments);
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,8 +74,12 @@
 block discarded – undo
74 74
     {
75 75
         $prop = get_object_vars($this);
76 76
         unset($prop["__yaml__object__api"]);
77
-        if (count($prop) > 0) return $prop;
78
-        if (count($this) > 0) return iterator_to_array($this);
77
+        if (count($prop) > 0) {
78
+            return $prop;
79
+        }
80
+        if (count($this) > 0) {
81
+            return iterator_to_array($this);
82
+        }
79 83
         return $this->__yaml__object__api->value ?? "_Empty YamlObject_";
80 84
     }
81 85
 }
Please login to merge, or discard this patch.
sources/NodeList.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -79,12 +79,12 @@
 block discarded – undo
79 79
      */
80 80
     public function checkTypeCoherence($estimatedType):bool
81 81
     {
82
-       // if ($this->type === self::MAPPING) {
83
-       //     if ($estimatedType === self::SEQUENCE) {
84
-       //         throw new \ParseError("Error : no coherence in types", 1);
85
-       //     }
86
-       // }
87
-       return (bool) $estimatedType;
82
+        // if ($this->type === self::MAPPING) {
83
+        //     if ($estimatedType === self::SEQUENCE) {
84
+        //         throw new \ParseError("Error : no coherence in types", 1);
85
+        //     }
86
+        // }
87
+        return (bool) $estimatedType;
88 88
     }
89 89
 
90 90
     public function build(&$parent = null)
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                 && !($child instanceof Directive)
65 65
                 && !($child instanceof Blank)
66 66
                 && !($child instanceof Docstart
67
-                && is_null($child->value)) ) return true;
67
+                && is_null($child->value))) return true;
68 68
         }
69 69
         return false;
70 70
     }
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
     public function push($node)
73 73
     {
74 74
         $type = null;
75
-        if     ($node instanceof Item )    $type = self::SEQUENCE;
75
+        if ($node instanceof Item)    $type = self::SEQUENCE;
76 76
         elseif ($node instanceof Key)      $type = self::MAPPING;
77 77
         elseif ($node instanceof SetKey
78 78
              || $node instanceof SetValue) {
79 79
             $type = self::SET;
80
-        } elseif ($node instanceof Scalar ){
80
+        } elseif ($node instanceof Scalar) {
81 81
             $type = self::MULTILINE;
82 82
         }
83 83
         if (!is_null($type) && $this->checkTypeCoherence($type)) {
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             $output = trim($first->raw);
140 140
             foreach ($list as $child) {
141 141
                 if ($child instanceof Scalar) {
142
-                    $separator = isset($output[-1])  && $output[-1] === "\n" ? '' : ' ';
142
+                    $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' ';
143 143
                     $output .= $separator.trim($child->raw);
144 144
                 } elseif ($child instanceof Blank) {
145 145
                     $output .= "\n";
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
             if ($child instanceof Comment) {
166 166
                 // $child->build();
167 167
             } else {
168
-                if($child->value instanceof Comment) {
168
+                if ($child->value instanceof Comment) {
169 169
                     // $child->value->build();
170 170
                     // $child->value = null;
171
-                } elseif($child->value instanceof NodeList) {
171
+                } elseif ($child->value instanceof NodeList) {
172 172
                     $child->value = $child->value->filterComment();
173 173
                 }
174 174
                 $out->push($child);
Please login to merge, or discard this patch.
Braces   +11 added lines, -5 removed lines patch added patch discarded remove patch
@@ -50,7 +50,9 @@  discard block
 block discarded – undo
50 50
         $tmp->rewind();
51 51
         $fqn = __NAMESPACE__."\\Nodes\\$nodeType";
52 52
         foreach ($tmp as $child) {
53
-            if ($child instanceof $fqn) return true;
53
+            if ($child instanceof $fqn) {
54
+                return true;
55
+            }
54 56
         }
55 57
         return false;
56 58
     }
@@ -64,7 +66,9 @@  discard block
 block discarded – undo
64 66
                 && !($child instanceof Directive)
65 67
                 && !($child instanceof Blank)
66 68
                 && !($child instanceof Docstart
67
-                && is_null($child->value)) ) return true;
69
+                && is_null($child->value)) ) {
70
+                return true;
71
+            }
68 72
         }
69 73
         return false;
70 74
     }
@@ -72,9 +76,11 @@  discard block
 block discarded – undo
72 76
     public function push($node)
73 77
     {
74 78
         $type = null;
75
-        if     ($node instanceof Item )    $type = self::SEQUENCE;
76
-        elseif ($node instanceof Key)      $type = self::MAPPING;
77
-        elseif ($node instanceof SetKey
79
+        if     ($node instanceof Item ) {
80
+            $type = self::SEQUENCE;
81
+        } elseif ($node instanceof Key) {
82
+            $type = self::MAPPING;
83
+        } elseif ($node instanceof SetKey
78 84
              || $node instanceof SetValue) {
79 85
             $type = self::SET;
80 86
         } elseif ($node instanceof Scalar ){
Please login to merge, or discard this patch.
sources/Builder.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -92,13 +92,13 @@
 block discarded – undo
92 92
         if (Regex::isDate($v))   return self::$dateAsObject && !$onlyScalar ? date_create($v) : $v;
93 93
         if (Regex::isNumber($v)) return self::getNumber($v);
94 94
         $types = ['yes'   => true,
95
-                  'no'    => false,
96
-                  'true'  => true,
97
-                  'false' => false,
98
-                  'null'  => null,
99
-                  '.inf'  => \INF,
100
-                  '-.inf' => -\INF,
101
-                  '.nan'  => \NAN
95
+                    'no'    => false,
96
+                    'true'  => true,
97
+                    'false' => false,
98
+                    'null'  => null,
99
+                    '.inf'  => \INF,
100
+                    '-.inf' => -\INF,
101
+                    '.nan'  => \NAN
102 102
         ];
103 103
         return array_key_exists(strtolower($v), $types) ? $types[strtolower($v)] : $v;
104 104
     }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
                     $buffer->push($child);
46 46
                 }
47 47
             }
48
-            $documents[] = self::buildDocument($buffer, count($documents) +1);
48
+            $documents[] = self::buildDocument($buffer, count($documents) + 1);
49 49
         } catch (\Exception|\Error|\ParseError $e) {
50 50
             throw new \Exception($e->getMessage(), 1, $e);
51 51
         }
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -112,8 +112,12 @@  discard block
 block discarded – undo
112 112
  \.nan | \.NaN | \.NAN   tag:yaml.org,2002:float (Not a number)
113 113
  *   tag:yaml.org,2002:str (Default)
114 114
  */
115
-        if (Regex::isDate($v))   return self::$dateAsObject && !$onlyScalar ? date_create($v) : $v;
116
-        if (Regex::isNumber($v)) return self::getNumber($v);
115
+        if (Regex::isDate($v)) {
116
+            return self::$dateAsObject && !$onlyScalar ? date_create($v) : $v;
117
+        }
118
+        if (Regex::isNumber($v)) {
119
+            return self::getNumber($v);
120
+        }
117 121
         $types = ['yes'   => true,
118 122
                   'no'    => false,
119 123
                   'true'  => true,
@@ -136,8 +140,12 @@  discard block
 block discarded – undo
136 140
      */
137 141
     private static function getNumber(string $v)
138 142
     {
139
-        if ((bool) preg_match(Regex::OCTAL_NUM, $v)) return intval(base_convert($v, 8, 10));
140
-        if ((bool) preg_match(Regex::HEX_NUM, $v))   return intval(base_convert($v, 16, 10));
143
+        if ((bool) preg_match(Regex::OCTAL_NUM, $v)) {
144
+            return intval(base_convert($v, 8, 10));
145
+        }
146
+        if ((bool) preg_match(Regex::HEX_NUM, $v)) {
147
+            return intval(base_convert($v, 16, 10));
148
+        }
141 149
         return is_bool(strpos($v, '.')) || substr_count($v, '.') > 1 ? intval($v) : floatval($v);
142 150
     }
143 151
 
Please login to merge, or discard this patch.
sources/Loader.php 2 patches
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -129,8 +129,12 @@
 block discarded – undo
129 129
         try {
130 130
             foreach ($generator as $lineNb => $lineString) {
131 131
                 $node = NodeFactory::get($lineString, $lineNb);
132
-                if ($this->_debug === 1) echo get_class($node)."\n";
133
-                if ($this->needsSpecialProcess($node, $previous)) continue;
132
+                if ($this->_debug === 1) {
133
+                    echo get_class($node)."\n";
134
+                }
135
+                if ($this->needsSpecialProcess($node, $previous)) {
136
+                    continue;
137
+                }
134 138
                 $this->_attachBlankLines($previous);
135 139
                 switch ($node->indent <=> $previous->indent) {
136 140
                     case -1: $target = $previous->getTargetOnLessIndent($node);
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
     //public
21 21
     /* @var null|string */
22 22
     public static $error;
23
-    public const IGNORE_DIRECTIVES     = 1;//DONT include_directive
24
-    public const IGNORE_COMMENTS       = 2;//DONT include_comments
25
-    public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors
26
-    public const NO_OBJECT_FOR_DATE    = 8;//DONT import date strings as dateTime Object
23
+    public const IGNORE_DIRECTIVES     = 1; //DONT include_directive
24
+    public const IGNORE_COMMENTS       = 2; //DONT include_comments
25
+    public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors
26
+    public const NO_OBJECT_FOR_DATE    = 8; //DONT import date strings as dateTime Object
27 27
 
28 28
     //private
29 29
     /* @var null|array */
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                 $previous = $target->add($node);
145 145
             }
146 146
             $this->_attachBlankLines($previous);
147
-            if ($this->_debug === 1){
147
+            if ($this->_debug === 1) {
148 148
                 return null;
149 149
             }
150 150
             return Builder::buildContent($root, $this->_debug);
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
     {
184 184
         $deepest = $previous->getDeepestNode();
185 185
         if ($deepest instanceof Nodes\Partial) {
186
-            return $deepest->specialProcess($current,  $this->_blankBuffer);
187
-        } elseif(!($current instanceof Nodes\Partial)) {
186
+            return $deepest->specialProcess($current, $this->_blankBuffer);
187
+        } elseif (!($current instanceof Nodes\Partial)) {
188 188
             return $current->specialProcess($previous, $this->_blankBuffer);
189 189
         }
190 190
         return false;
Please login to merge, or discard this patch.
examples/write.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,4 +21,6 @@
 block discarded – undo
21 21
 if ($nameResultPair[$testName] !== $text) {
22 22
     var_dump('EXPECTED', $nameResultPair[$testName]);
23 23
     var_dump('RECEIVED', $text);
24
-} else echo 'OK';
24
+} else {
25
+    echo 'OK';
26
+}
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 define('PROJECT_ROOT', __DIR__."/../");
3 3
 
4
-require_once PROJECT_ROOT . 'vendor/autoload.php';
4
+require_once PROJECT_ROOT.'vendor/autoload.php';
5 5
 
6 6
 use Dallgoot\Yaml;
7 7
 // use Dallgoot\Yaml\{Loader, Dumper};
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
 // $yaml = (new Loader('./dummy.yml', null, 0))->parse();
15 15
 // var_dump($yaml);
16 16
 $testName = 'yamlObject_properties';
17
-$text = Yaml::dump((include PROJECT_ROOT . "tests/cases/dumping/$testName.php"), 0);
17
+$text = Yaml::dump((include PROJECT_ROOT."tests/cases/dumping/$testName.php"), 0);
18 18
 
19
-$nameResultPair = get_object_vars(Yaml::parseFile(PROJECT_ROOT . 'tests/definitions/dumping_tests.yml'));
19
+$nameResultPair = get_object_vars(Yaml::parseFile(PROJECT_ROOT.'tests/definitions/dumping_tests.yml'));
20 20
 
21 21
 // var_dump($nameResultPair);
22 22
 
Please login to merge, or discard this patch.
examples/read.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 /**
7 7
  * Display some use cases for Yaml library
8 8
  */
9
-const JSON_OPTIONS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_PARTIAL_OUTPUT_ON_ERROR;
9
+const JSON_OPTIONS = JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_LINE_TERMINATORS|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION|JSON_PARTIAL_OUTPUT_ON_ERROR;
10 10
 
11 11
 $debug = (int) (isset($argv[1]) ? $argv[1] : null);
12 12
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 * load and parse if file exists
15 15
 */
16 16
 // $content = file_get_contents('./tests/cases/parsing/multidoc_mapping.yml');//var_dump($content);
17
-$content = file_get_contents('./tests/definitions/examples_tests.yml');//var_dump($content);
17
+$content = file_get_contents('./tests/definitions/examples_tests.yml'); //var_dump($content);
18 18
 $yaml = Yaml::parse($content, 0, $debug);
19 19
 // var_dump($yaml);
20 20
 var_dump(json_encode($yaml, JSON_OPTIONS));
Please login to merge, or discard this patch.
examples/load_modify_save.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Dallgoot\Yaml;
3 3
 
4
-require_once __DIR__ . '/../../vendor/autoload.php';
4
+require_once __DIR__.'/../../vendor/autoload.php';
5 5
 
6 6
 use Dallgoot;
7 7
 
8
-$fileName = __DIR__ . '/../dummy.yml';
8
+$fileName = __DIR__.'/../dummy.yml';
9 9
 
10 10
 $yamlObject = Yaml::parseFile($fileName, $options = null, $debug = null);
11 11
 
Please login to merge, or discard this patch.
sources/NodeFactory.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
         elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) return new Nodes\Key($nodeString, $line, $matches);
28 28
         else {
29 29
             $first = $trimmed[0];
30
-            $stringGroups = ["-" ,'>|' ,'"\'',"#%" ,"{[" ,":?" ,'*&!'];
31
-            $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction'];
30
+            $stringGroups = ["-", '>|', '"\'', "#%", "{[", ":?", '*&!'];
31
+            $methodGroups = ['Hyphen', 'Literal', 'Quoted', 'Special', 'Compact', 'SetElement', 'NodeAction'];
32 32
             foreach ($stringGroups as $groupIndex => $stringRef) {
33 33
                 if (is_int(strpos($stringRef, $first))) {
34 34
                     $methodName = 'on'.$methodGroups[$groupIndex];
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
         if (!((bool) preg_match(Regex::NODE_ACTIONS, trim($nodeString), $matches))) {
135 135
             return new Nodes\Scalar($nodeString, $line);
136 136
         }
137
-        $action = trim($matches['action']);//var_dump($matches);
137
+        $action = trim($matches['action']); //var_dump($matches);
138 138
         switch ($action[0]) {
139
-            case '!': return new Nodes\Tag   ($nodeString, $line);
139
+            case '!': return new Nodes\Tag($nodeString, $line);
140 140
             default :
141 141
                 return new Nodes\Anchor($nodeString, $line);
142 142
             // case '&': return new NodeAnchor($nodeString, $line);
Please login to merge, or discard this patch.
Braces   +19 added lines, -11 removed lines patch added patch discarded remove patch
@@ -22,10 +22,13 @@  discard block
 block discarded – undo
22 22
     final public static function get($nodeString = null, $line = 0):NodeGeneric
23 23
     {
24 24
         $trimmed = ltrim($nodeString);
25
-        if ($trimmed === '')                                return new Nodes\Blank($nodeString, $line);
26
-        elseif (substr($trimmed, 0, 3) === '...')           return new Nodes\DocEnd($nodeString, $line);
27
-        elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) return new Nodes\Key($nodeString, $line, $matches);
28
-        else {
25
+        if ($trimmed === '') {
26
+            return new Nodes\Blank($nodeString, $line);
27
+        } elseif (substr($trimmed, 0, 3) === '...') {
28
+            return new Nodes\DocEnd($nodeString, $line);
29
+        } elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) {
30
+            return new Nodes\Key($nodeString, $line, $matches);
31
+        } else {
29 32
             $first = $trimmed[0];
30 33
             $stringGroups = ["-" ,'>|' ,'"\'',"#%" ,"{[" ,":?" ,'*&!'];
31 34
             $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction'];
@@ -96,10 +99,13 @@  discard block
 block discarded – undo
96 99
     final private static function onCompact(string $first, string $nodeString, int $line):NodeGeneric
97 100
     {
98 101
         json_decode($nodeString, false, 512, self::JSON_OPTIONS);
99
-        if (json_last_error() === \JSON_ERROR_NONE)             return new Nodes\JSON($nodeString, $line);
100
-        elseif ((bool) preg_match(Regex::MAPPING, trim($nodeString)))  return new Nodes\CompactMapping($nodeString, $line);
101
-        elseif ((bool) preg_match(Regex::SEQUENCE, trim($nodeString))) return new Nodes\CompactSequence($nodeString, $line);
102
-        else {
102
+        if (json_last_error() === \JSON_ERROR_NONE) {
103
+            return new Nodes\JSON($nodeString, $line);
104
+        } elseif ((bool) preg_match(Regex::MAPPING, trim($nodeString))) {
105
+            return new Nodes\CompactMapping($nodeString, $line);
106
+        } elseif ((bool) preg_match(Regex::SEQUENCE, trim($nodeString))) {
107
+            return new Nodes\CompactSequence($nodeString, $line);
108
+        } else {
103 109
             return new Nodes\Partial($nodeString, $line);
104 110
         }
105 111
     }
@@ -114,9 +120,11 @@  discard block
 block discarded – undo
114 120
      */
115 121
     final private static function onHyphen(string $first, string $nodeString, int $line):NodeGeneric
116 122
     {
117
-        if (substr($nodeString, 0, 3) === '---')              return new Nodes\DocStart($nodeString, $line);
118
-        elseif ((bool) preg_match(Regex::ITEM, ltrim($nodeString)))  return new Nodes\Item($nodeString, $line);
119
-        else {
123
+        if (substr($nodeString, 0, 3) === '---') {
124
+            return new Nodes\DocStart($nodeString, $line);
125
+        } elseif ((bool) preg_match(Regex::ITEM, ltrim($nodeString))) {
126
+            return new Nodes\Item($nodeString, $line);
127
+        } else {
120 128
             return new Nodes\Scalar($nodeString, $line);
121 129
         }
122 130
     }
Please login to merge, or discard this patch.