@@ -69,7 +69,7 @@ |
||
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 |
@@ -74,8 +74,12 @@ |
||
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 | } |
@@ -79,12 +79,12 @@ |
||
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) |
@@ -64,7 +64,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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); |
@@ -50,7 +50,9 @@ discard block |
||
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 |
||
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 |
||
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 ){ |
@@ -45,7 +45,7 @@ |
||
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 | } |
@@ -1,11 +1,11 @@ |
||
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 |
@@ -20,10 +20,10 @@ discard block |
||
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 |
||
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 |
||
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; |
@@ -130,8 +130,12 @@ |
||
130 | 130 | try { |
131 | 131 | foreach ($generator as $lineNB => $lineString) { |
132 | 132 | $node = NodeFactory::get($lineString, $lineNB); |
133 | - if ($this->_debug === 1) echo get_class($node)."\n"; |
|
134 | - if ($this->needsSpecialProcess($node, $previous)) continue; |
|
133 | + if ($this->_debug === 1) { |
|
134 | + echo get_class($node)."\n"; |
|
135 | + } |
|
136 | + if ($this->needsSpecialProcess($node, $previous)) { |
|
137 | + continue; |
|
138 | + } |
|
135 | 139 | $this->_attachBlankLines($previous); |
136 | 140 | switch ($node->indent <=> $previous->indent) { |
137 | 141 | case -1: $target = $previous->getTargetOnLessIndent($node); |
@@ -44,7 +44,9 @@ |
||
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)) { |
@@ -41,7 +41,7 @@ |
||
41 | 41 | self::$options = is_int($options) ? $options : self::OPTIONS; |
42 | 42 | $dumpHandler = new DumperHandlers($options); |
43 | 43 | if (is_scalar($dataType)) { |
44 | - return "--- ".$dumpHandler->dumpScalar($dataType). self::LINEFEED ; |
|
44 | + return "--- ".$dumpHandler->dumpScalar($dataType).self::LINEFEED; |
|
45 | 45 | } |
46 | 46 | return $dumpHandler->dump($dataType, 0); |
47 | 47 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function __construct(string $nodeString, int $line) |
14 | 14 | { |
15 | 15 | parent::__construct($nodeString, $line); |
16 | - preg_match_all(Regex::MAPPING_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches); |
|
16 | + preg_match_all(Regex::MAPPING_VALUES, trim(substr(trim($nodeString), 1, -1)), $matches); |
|
17 | 17 | foreach ($matches['k'] as $index => $property) { |
18 | 18 | $pair = $property.': '.trim($matches['v'][$index]); |
19 | 19 | $child = NodeFactory::get($pair, $line); |
@@ -10,17 +10,17 @@ |
||
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 |