Passed
Push — master ( 36bd6b...41f581 )
by stéphane
12:53
created
examples/write.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,4 +24,6 @@
 block discarded – undo
24 24
 if ($nameResultPair[$testName] !== $text) {
25 25
     var_dump('EXPECTED', $nameResultPair[$testName]);
26 26
     var_dump('RECEIVED', $text);
27
-} else echo 'WRITE OK !!!';
27
+} else {
28
+    echo 'WRITE OK !!!';
29
+}
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,10 +14,10 @@  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
-$yamlObject = (include PROJECT_ROOT . "tests/cases/dumping/$testName.php");
17
+$yamlObject = (include PROJECT_ROOT."tests/cases/dumping/$testName.php");
18 18
 $text = Yaml::dump($yamlObject, 0);
19 19
 
20
-$nameResultPair = get_object_vars(/** @scrutinizer ignore-type */ Yaml::parseFile(PROJECT_ROOT . 'tests/definitions/dumping_tests.yml'));
20
+$nameResultPair = get_object_vars(/** @scrutinizer ignore-type */ Yaml::parseFile(PROJECT_ROOT.'tests/definitions/dumping_tests.yml'));
21 21
 
22 22
 // var_dump($nameResultPair);
23 23
 
Please login to merge, or discard this patch.
sources/DumperHandlers.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -96,8 +96,8 @@
 block discarded – undo
96 96
     private function dumpYamlObject(YamlObject $obj):string
97 97
     {
98 98
         if ($this->multipleDocs || $obj->hasDocStart() || $obj->isTagged()) {
99
-           $this->multipleDocs = true;
100
-          // && $this->$result instanceof DLL) $this->$result->push("---");
99
+            $this->multipleDocs = true;
100
+            // && $this->$result instanceof DLL) $this->$result->push("---");
101 101
         }
102 102
         if (count($obj) > 0) {
103 103
             return $this->iteratorToString($obj, '-', 0);
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 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):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';
Please login to merge, or discard this patch.
sources/tag/TagFactory.php 2 patches
Indentation   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -62,7 +62,6 @@  discard block
 block discarded – undo
62 62
 %TAG !! tag:example.com,2000:app/
63 63
 %TAG !e! tag:example.com,2000:app/
64 64
 !<tag:yaml.org,2002:str> foo :
65
-
66 65
      */
67 66
     /**
68 67
      * Add Handlers for legacy Yaml tags
@@ -107,16 +106,16 @@  discard block
 block discarded – undo
107 106
             self::createCoreSchema();
108 107
         }
109 108
         if (!($value instanceof NodeGeneric) && !($value instanceof NodeList) ) {
110
-              throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value)));
109
+                throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value)));
111 110
         } else {
112 111
             // try {
113 112
                 if (!preg_match(Regex::TAG_PARTS, $identifier, $matches)) {
114 113
                     throw new \UnexpectedValueException("Tag '$identifier' is invalid", 1);
115 114
                 }
116 115
                 return self::runHandler($matches['handle'],
117
-                                          $matches['tagname'],
118
-                                          $value,
119
-                                          $parent);
116
+                                            $matches['tagname'],
117
+                                            $value,
118
+                                            $parent);
120 119
             // } catch (\UnexpectedValueException $e) {
121 120
             //     return new Tagged($identifier, is_null($value) ? null : $value->build($parent));
122 121
             // } catch (\Throwable $e) {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@
 block discarded – undo
106 106
         if (count(self::$schemas) === 0) {
107 107
             self::createCoreSchema();
108 108
         }
109
-        if (!($value instanceof NodeGeneric) && !($value instanceof NodeList) ) {
109
+        if (!($value instanceof NodeGeneric) && !($value instanceof NodeList)) {
110 110
               throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value)));
111 111
         } else {
112 112
             // try {
Please login to merge, or discard this patch.
sources/tag/CoreSchema.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function str(object $node, &$parent = null)
59 59
     {
60
-        if($node instanceof Nodes\Literals){
60
+        if ($node instanceof Nodes\Literals) {
61 61
             $node = $node->value;
62 62
         }
63 63
         if ($node instanceof Nodes\NodeGeneric) {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                 $list[] = $this->str($child);
73 73
             }
74 74
             // return new Nodes\Scalar(implode('',$list), 0);
75
-            return implode('',$list);
75
+            return implode('', $list);
76 76
         }
77 77
     }
78 78
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
                 $keyValue = $key->value->build();
134 134
                 if (is_null($parent)) {
135 135
                     return [$keyName => $keyValue];
136
-                } else{
136
+                } else {
137 137
                     $parent[$keyName] = $keyValue;
138 138
                 }
139 139
             } else {
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
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
             throw new \Exception(__METHOD__." expects a YamlObject as parent", 1);
40 40
         }
41 41
         if (!is_null($this->value)) {
42
-            if ($this->value instanceof Tag){
42
+            if ($this->value instanceof Tag) {
43 43
                 preg_match(Regex::TAG_PARTS, $this->value->raw, $tagparts);
44 44
                 if (preg_match("/(?(DEFINE)".Regex::TAG_URI.')(?&url)/', $tagparts['tagname'], $matches)) {
45 45
                     // throw new \UnexpectedValueException("Tag '".$this->value->raw."' is invalid", 1);
Please login to merge, or discard this patch.
sources/nodes/Tag.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
         } catch (\UnexpectedValueException $e) {
60 60
             return new Tagged($this->tag, is_null($value) ? null : $this->value->build($parent));
61 61
         } catch (\Throwable $e) {
62
-            throw new \Exception("Tagged value could not be transformed for tag '$this->tag'", 1, $e);;
62
+            throw new \Exception("Tagged value could not be transformed for tag '$this->tag'", 1, $e); ;
63 63
         }
64 64
     }
65 65
 }
66 66
\ No newline at end of file
Please login to merge, or discard this patch.
sources/NodeFactory.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
         elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) return new Nodes\Key($nodeString, $line, $matches);
29 29
         else {
30 30
             $first = $trimmed[0];
31
-            $stringGroups = ['-',         '>|' ,   '"\'',    "#%" ,    "{[" ,       ":?" ,       '*&!'];
32
-            $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction'];
31
+            $stringGroups = ['-', '>|', '"\'', "#%", "{[", ":?", '*&!'];
32
+            $methodGroups = ['Hyphen', 'Literal', 'Quoted', 'Special', 'Compact', 'SetElement', 'NodeAction'];
33 33
             foreach ($stringGroups as $groupIndex => $stringRef) {
34 34
                 if (is_int(strpos($stringRef, $first))) {
35 35
                     $methodName = 'on'.$methodGroups[$groupIndex];
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         }
146 146
         // $action = trim($matches['action']);//var_dump($matches);
147 147
         switch ($first) {
148
-            case '!': return new Nodes\Tag   ($nodeString, $line);
148
+            case '!': return new Nodes\Tag($nodeString, $line);
149 149
             default :
150 150
                 return new Nodes\Anchor($nodeString, $line);
151 151
             // 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
@@ -23,10 +23,13 @@  discard block
 block discarded – undo
23 23
     final public static function get($nodeString = null, $line = 0):NodeGeneric
24 24
     {
25 25
         $trimmed = ltrim($nodeString);
26
-        if ($trimmed === '')                                return new Nodes\Blank($nodeString, $line);
27
-        elseif (substr($trimmed, 0, 3) === '...')           return new Nodes\DocEnd($nodeString, $line);
28
-        elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) return new Nodes\Key($nodeString, $line, $matches);
29
-        else {
26
+        if ($trimmed === '') {
27
+            return new Nodes\Blank($nodeString, $line);
28
+        } elseif (substr($trimmed, 0, 3) === '...') {
29
+            return new Nodes\DocEnd($nodeString, $line);
30
+        } elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) {
31
+            return new Nodes\Key($nodeString, $line, $matches);
32
+        } else {
30 33
             $first = $trimmed[0];
31 34
             $stringGroups = ['-',         '>|' ,   '"\'',    "#%" ,    "{[" ,       ":?" ,       '*&!'];
32 35
             $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction'];
@@ -105,10 +108,13 @@  discard block
 block discarded – undo
105 108
     final private static function onCompact(string $first, string $nodeString, int $line):NodeGeneric
106 109
     {
107 110
         json_decode($nodeString, false, 512, self::JSON_OPTIONS);
108
-        if (json_last_error() === \JSON_ERROR_NONE)             return new Nodes\JSON($nodeString, $line);
109
-        elseif ((bool) preg_match(Regex::MAPPING, trim($nodeString)))  return new Nodes\CompactMapping($nodeString, $line);
110
-        elseif ((bool) preg_match(Regex::SEQUENCE, trim($nodeString))) return new Nodes\CompactSequence($nodeString, $line);
111
-        else {
111
+        if (json_last_error() === \JSON_ERROR_NONE) {
112
+            return new Nodes\JSON($nodeString, $line);
113
+        } elseif ((bool) preg_match(Regex::MAPPING, trim($nodeString))) {
114
+            return new Nodes\CompactMapping($nodeString, $line);
115
+        } elseif ((bool) preg_match(Regex::SEQUENCE, trim($nodeString))) {
116
+            return new Nodes\CompactSequence($nodeString, $line);
117
+        } else {
112 118
             return new Nodes\Partial($nodeString, $line);
113 119
         }
114 120
     }
@@ -123,9 +129,11 @@  discard block
 block discarded – undo
123 129
      */
124 130
     final private static function onHyphen(string $first, string $nodeString, int $line):NodeGeneric
125 131
     {
126
-        if (substr($nodeString, 0, 3) === '---')              return new Nodes\DocStart($nodeString, $line);
127
-        elseif ((bool) preg_match(Regex::ITEM, ltrim($nodeString)))  return new Nodes\Item($nodeString, $line);
128
-        else {
132
+        if (substr($nodeString, 0, 3) === '---') {
133
+            return new Nodes\DocStart($nodeString, $line);
134
+        } elseif ((bool) preg_match(Regex::ITEM, ltrim($nodeString))) {
135
+            return new Nodes\Item($nodeString, $line);
136
+        } else {
129 137
             return new Nodes\Scalar($nodeString, $line);
130 138
         }
131 139
     }
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,14 +6,14 @@
 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
 
13 13
 /* USE CASE 1
14 14
 * load and parse if file exists
15 15
 */
16
-$content = file_get_contents('./tests/cases/examples/Example_2_25.yml');//var_dump($content);
16
+$content = file_get_contents('./tests/cases/examples/Example_2_25.yml'); //var_dump($content);
17 17
 $yaml = Yaml::parse($content, 0, $debug);
18 18
 // var_dump($yaml);
19 19
 var_dump(json_encode($yaml, JSON_OPTIONS));
Please login to merge, or discard this patch.