Test Failed
Push — master ( f97b0a...758f0b )
by stéphane
02:39
created
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.
examples/write.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 define('PROJECT_ROOT', __DIR__."/../");
3
-require_once PROJECT_ROOT . 'vendor/autoload.php';
3
+require_once PROJECT_ROOT.'vendor/autoload.php';
4 4
 
5 5
 use Dallgoot\Yaml;
6 6
 use Dallgoot\Yaml\{Loader, Dumper};
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 // $yaml = (new Loader('./dummy.yml', null, 0))->parse();
13 13
 // var_dump($yaml);
14 14
 $testName = 'yamlObject_properties';
15
-$text = Yaml::dump((include PROJECT_ROOT . "tests/cases/dumping/$testName.php"), 0);
15
+$text = Yaml::dump((include PROJECT_ROOT."tests/cases/dumping/$testName.php"), 0);
16 16
 
17
-$nameResultPair = get_object_vars(Yaml::parseFile(PROJECT_ROOT . '/tests/definitions/dumping_tests.yml'));
17
+$nameResultPair = get_object_vars(Yaml::parseFile(PROJECT_ROOT.'/tests/definitions/dumping_tests.yml'));
18 18
 
19 19
 // var_dump($nameResultPair);
20 20
 
Please login to merge, or discard this patch.
sources/Loader.php 1 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.
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.
sources/DumperHandlers.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -87,8 +87,8 @@
 block discarded – undo
87 87
     private function dumpYamlObject(YamlObject $obj):string
88 88
     {
89 89
         if ($this->multipleDocs || $obj->hasDocStart() || $obj->isTagged() || $obj->isScalar()) {
90
-           $this->multipleDocs = true;
91
-          // && $this->$result instanceof DLL) $this->$result->push("---");
90
+            $this->multipleDocs = true;
91
+            // && $this->$result instanceof DLL) $this->$result->push("---");
92 92
         }
93 93
         if (count($obj) > 0) {
94 94
             return $this->iteratorToString($obj, '-', 0);
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 
33 33
     public function dump($dataType, int $indent):string
34 34
     {
35
-        if(is_null($dataType)) {
35
+        if (is_null($dataType)) {
36 36
             return '';
37
-        } elseif(is_resource($dataType)) {
37
+        } elseif (is_resource($dataType)) {
38 38
             return get_resource_type($dataType);
39 39
         } elseif (is_scalar($dataType)) {
40 40
             return $this->dumpScalar($dataType, $indent);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     }
102 102
 
103 103
 
104
-    private function iteratorToString(iterable $iterator, string $mask, int $indent, bool $isCompact=false):string
104
+    private function iteratorToString(iterable $iterator, string $mask, int $indent, bool $isCompact = false):string
105 105
     {
106 106
         $pairs = [];
107 107
         foreach ($iterator as $key => $value) {
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         if (is_array($subject) || $subject instanceof \ArrayIterator) {
134 134
             $max = count($subject);
135 135
             $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy();
136
-            if(array_keys($objectAsArray) !== range(0, $max-1)) {
136
+            if (array_keys($objectAsArray) !== range(0, $max - 1)) {
137 137
                 $pairs = $objectAsArray;
138 138
             } else {
139 139
                 $valuesList = [];
Please login to merge, or discard this patch.
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function __construct(int $options = null)
27 27
     {
28
-        if (is_int($options)) $this->options = $options;
28
+        if (is_int($options)) {
29
+            $this->options = $options;
30
+        }
29 31
     }
30 32
 
31 33
 
@@ -45,8 +47,12 @@  discard block
 block discarded – undo
45 47
 
46 48
     public function dumpScalar($dataType, $indent):string
47 49
     {
48
-        if ($dataType === \INF) return '.inf';
49
-        if ($dataType === -\INF) return '-.inf';
50
+        if ($dataType === \INF) {
51
+            return '.inf';
52
+        }
53
+        if ($dataType === -\INF) {
54
+            return '-.inf';
55
+        }
50 56
         $precision = "%.".$this->floatPrecision."F";
51 57
         switch (gettype($dataType)) {
52 58
             case 'boolean': return $dataType ? 'true' : 'false';
@@ -73,11 +79,19 @@  discard block
 block discarded – undo
73 79
                 }
74 80
             }
75 81
         } elseif (is_object($compound)) {
76
-            if ($compound instanceof YamlObject) return $this->dumpYamlObject($compound);
77
-            if ($compound instanceof Tagged)     return $this->dumpTagged($compound, $indent);
78
-            if ($compound instanceof Compact)    return $this->dumpCompact($compound, $indent);
82
+            if ($compound instanceof YamlObject) {
83
+                return $this->dumpYamlObject($compound);
84
+            }
85
+            if ($compound instanceof Tagged) {
86
+                return $this->dumpTagged($compound, $indent);
87
+            }
88
+            if ($compound instanceof Compact) {
89
+                return $this->dumpCompact($compound, $indent);
90
+            }
79 91
             //TODO:  consider dumping datetime as date strings according to a format provided by user
80
-            if ($compound instanceof \DateTime)  return $compound->format(self::DATE_FORMAT);
92
+            if ($compound instanceof \DateTime) {
93
+                return $compound->format(self::DATE_FORMAT);
94
+            }
81 95
             $iterator = new \ArrayIterator($compound);
82 96
         }
83 97
         return $this->iteratorToString($iterator, $mask, $indent);
Please login to merge, or discard this patch.
sources/NodeList.php 2 patches
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/Dumper.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
         $dumpHandler = new DumperHandlers($options);
50 50
         if (is_scalar($dataType)) {
51 51
             // TODO: what to woth comments ???
52
-            return "--- ".$dumpHandler->dumpScalar($dataType, 0). self::LINEFEED ;
52
+            return "--- ".$dumpHandler->dumpScalar($dataType, 0).self::LINEFEED;
53 53
         }
54 54
         return $dumpHandler->dump($dataType, 0);
55 55
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,9 @@
 block discarded – undo
44 44
      */
45 45
     public static function toString($dataType, int $options = null):string
46 46
     {
47
-        if (empty($dataType)) throw new \Exception(self::class.": No content to convert to Yaml");
47
+        if (empty($dataType)) {
48
+            throw new \Exception(self::class.": No content to convert to Yaml");
49
+        }
48 50
         self::$options = is_int($options) ? $options : self::OPTIONS;
49 51
         $dumpHandler = new DumperHandlers($options);
50 52
         if (is_scalar($dataType)) {
Please login to merge, or discard this patch.
sources/nodes/Comment.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -10,17 +10,17 @@
 block discarded – undo
10 10
  */
11 11
 class Comment extends NodeGeneric
12 12
 {
13
-   public function specialProcess(NodeGeneric &$previous, array &$emptyLines):bool
14
-   {
13
+    public function specialProcess(NodeGeneric &$previous, array &$emptyLines):bool
14
+    {
15 15
         $previous->getRoot()->add($this);
16 16
         return true;
17
-   }
17
+    }
18 18
 
19
-   public function build(&$parent = null)
20
-   {
19
+    public function build(&$parent = null)
20
+    {
21 21
         $root = $this->getRoot();
22 22
         $yamlObject = $root->getYamlObject();
23 23
         $yamlObject->addComment($this->line, $this->raw);
24 24
         return null;
25
-   }
25
+    }
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
sources/nodes/DocStart.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
             throw new \Exception(__METHOD__." expects a YamlObject as parent", 1);
39 39
         }
40 40
         if (!is_null($this->value)) {
41
-            if ($this->value instanceof Tag){
41
+            if ($this->value instanceof Tag) {
42 42
                 $parent->addTag($this->value->tag);
43 43
                 $this->value->build($parent);
44 44
             } else {
Please login to merge, or discard this patch.