@@ -106,7 +106,7 @@ |
||
| 106 | 106 | |
| 107 | 107 | function isOneOf(object $obj, array $comparison) |
| 108 | 108 | { |
| 109 | - if(!is_object($obj) || !is_array($comparison)) { |
|
| 109 | + if (!is_object($obj) || !is_array($comparison)) { |
|
| 110 | 110 | throw new Exception(__FUNCTION__." only object and array are allowed for comparison", 1); |
| 111 | 111 | } |
| 112 | 112 | foreach ($comparison as $className) { |
@@ -111,7 +111,9 @@ |
||
| 111 | 111 | } |
| 112 | 112 | foreach ($comparison as $className) { |
| 113 | 113 | $fqn = __NAMESPACE__."\\$className"; |
| 114 | - if ($obj instanceof $fqn) return true; |
|
| 114 | + if ($obj instanceof $fqn) { |
|
| 115 | + return true; |
|
| 116 | + } |
|
| 115 | 117 | } |
| 116 | 118 | return false; |
| 117 | 119 | } |
| 118 | 120 | \ No newline at end of file |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | //public |
| 16 | 16 | /* @var null|string */ |
| 17 | 17 | public static $error; |
| 18 | - public const IGNORE_DIRECTIVES = 1;//DONT include_directive |
|
| 19 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 20 | - public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors |
|
| 21 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 18 | + public const IGNORE_DIRECTIVES = 1; //DONT include_directive |
|
| 19 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 20 | + public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors |
|
| 21 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 22 | 22 | |
| 23 | 23 | //private |
| 24 | 24 | /* @var null|false|array */ |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /* @var null|string */ |
| 27 | 27 | private $filePath; |
| 28 | 28 | /* @var integer */ |
| 29 | - private $_debug = 0;///TODO: determine levels |
|
| 29 | + private $_debug = 0; ///TODO: determine levels |
|
| 30 | 30 | /* @var integer */ |
| 31 | 31 | private $_options = 0; |
| 32 | 32 | /* @var array */ |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | { |
| 174 | 174 | $deepest = $previous->getDeepestNode(); |
| 175 | 175 | if ($deepest instanceof NodePartial) { |
| 176 | - return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 177 | - } elseif(!($current instanceof NodePartial)) { |
|
| 176 | + return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 177 | + } elseif (!($current instanceof NodePartial)) { |
|
| 178 | 178 | return $current->specialProcess($previous, $this->_blankBuffer); |
| 179 | 179 | } |
| 180 | 180 | return false; |
@@ -93,7 +93,9 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $source = $this->content ?? preg_split("/\n/m", preg_replace('/(\r\n|\r)/', "\n", $strContent), 0, PREG_SPLIT_DELIM_CAPTURE); |
| 95 | 95 | //TODO : be more permissive on $strContent values |
| 96 | - if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 96 | + if (!is_array($source) || !count($source)) { |
|
| 97 | + throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 98 | + } |
|
| 97 | 99 | foreach ($source as $key => $value) { |
| 98 | 100 | yield ++$key => $value; |
| 99 | 101 | } |
@@ -116,7 +118,9 @@ discard block |
||
| 116 | 118 | try { |
| 117 | 119 | foreach ($generator as $lineNb => $lineString) { |
| 118 | 120 | $node = NodeFactory::get($lineString, $lineNb); |
| 119 | - if ($this->needsSpecialProcess($node, $previous)) continue; |
|
| 121 | + if ($this->needsSpecialProcess($node, $previous)) { |
|
| 122 | + continue; |
|
| 123 | + } |
|
| 120 | 124 | $this->attachBlankLines($previous); |
| 121 | 125 | switch ($node->indent <=> $previous->indent) { |
| 122 | 126 | case -1: $target = $previous->getTargetOnLessIndent($node); |
@@ -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 true; |
|
| 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 true; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public function build(&$parent = null) |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | foreach ($tmp as $child) { |
| 48 | 48 | if (!($child instanceof NodeComment) |
| 49 | 49 | && !($child instanceof NodeDirective) |
| 50 | - && !($child instanceof NodeDocstart && is_null($child->value)) ) return true; |
|
| 50 | + && !($child instanceof NodeDocstart && is_null($child->value))) return true; |
|
| 51 | 51 | } |
| 52 | 52 | return false; |
| 53 | 53 | } |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | public function push($node) |
| 56 | 56 | { |
| 57 | 57 | $type = null; |
| 58 | - if ($node instanceof NodeItem ) $type = self::SEQUENCE; |
|
| 58 | + if ($node instanceof NodeItem) $type = self::SEQUENCE; |
|
| 59 | 59 | elseif ($node instanceof NodeKey) $type = self::MAPPING; |
| 60 | 60 | elseif ($node instanceof NodeSetKey |
| 61 | 61 | || $node instanceof NodeSetValue) { |
| 62 | 62 | $type = self::SET; |
| 63 | - } elseif ($node instanceof NodeScalar ){ |
|
| 63 | + } elseif ($node instanceof NodeScalar) { |
|
| 64 | 64 | $type = self::MULTILINE; |
| 65 | 65 | } |
| 66 | 66 | if (!is_null($type) && $this->checkTypeCoherence($type)) { |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | if ($child instanceof NodeComment) { |
| 144 | 144 | $child->build(); |
| 145 | 145 | } else { |
| 146 | - if($child->value instanceof NodeComment) { |
|
| 146 | + if ($child->value instanceof NodeComment) { |
|
| 147 | 147 | $child->value->build(); |
| 148 | 148 | $child->value = null; |
| 149 | - } elseif($child->value instanceof NodeList) { |
|
| 149 | + } elseif ($child->value instanceof NodeList) { |
|
| 150 | 150 | $child->value = $child->value->filterComment(); |
| 151 | 151 | } |
| 152 | 152 | $out->push($child); |
@@ -35,7 +35,9 @@ discard block |
||
| 35 | 35 | $tmp->rewind(); |
| 36 | 36 | $fqn = __NAMESPACE__."\\$nodeType"; |
| 37 | 37 | foreach ($tmp as $child) { |
| 38 | - if ($child instanceof $fqn) return true; |
|
| 38 | + if ($child instanceof $fqn) { |
|
| 39 | + return true; |
|
| 40 | + } |
|
| 39 | 41 | } |
| 40 | 42 | return false; |
| 41 | 43 | } |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | foreach ($tmp as $child) { |
| 48 | 50 | if (!($child instanceof NodeComment) |
| 49 | 51 | && !($child instanceof NodeDirective) |
| 50 | - && !($child instanceof NodeDocstart && is_null($child->value)) ) return true; |
|
| 52 | + && !($child instanceof NodeDocstart && is_null($child->value)) ) { |
|
| 53 | + return true; |
|
| 54 | + } |
|
| 51 | 55 | } |
| 52 | 56 | return false; |
| 53 | 57 | } |
@@ -55,9 +59,11 @@ discard block |
||
| 55 | 59 | public function push($node) |
| 56 | 60 | { |
| 57 | 61 | $type = null; |
| 58 | - if ($node instanceof NodeItem ) $type = self::SEQUENCE; |
|
| 59 | - elseif ($node instanceof NodeKey) $type = self::MAPPING; |
|
| 60 | - elseif ($node instanceof NodeSetKey |
|
| 62 | + if ($node instanceof NodeItem ) { |
|
| 63 | + $type = self::SEQUENCE; |
|
| 64 | + } elseif ($node instanceof NodeKey) { |
|
| 65 | + $type = self::MAPPING; |
|
| 66 | + } elseif ($node instanceof NodeSetKey |
|
| 61 | 67 | || $node instanceof NodeSetValue) { |
| 62 | 68 | $type = self::SET; |
| 63 | 69 | } elseif ($node instanceof NodeScalar ){ |
@@ -15,12 +15,12 @@ |
||
| 15 | 15 | private const NO_NAME = '%s Error: a tag MUST have a name'; |
| 16 | 16 | private const WRONG_VALUE = "Error : cannot transform tag '%s' for type '%s'"; |
| 17 | 17 | private const LEGACY_TAGS_HANDLERS = ['!!str' => 'strHandler', |
| 18 | - '!!binary' => 'binaryHandler', |
|
| 19 | - '!set' => 'setHandler', |
|
| 20 | - '!!omap' => 'omapHandler', |
|
| 21 | - '!php/object' => 'symfonyPHPobjectHandler', |
|
| 22 | - '!inline' => 'inlineHandler', |
|
| 23 | - ]; |
|
| 18 | + '!!binary' => 'binaryHandler', |
|
| 19 | + '!set' => 'setHandler', |
|
| 20 | + '!!omap' => 'omapHandler', |
|
| 21 | + '!php/object' => 'symfonyPHPobjectHandler', |
|
| 22 | + '!inline' => 'inlineHandler', |
|
| 23 | + ]; |
|
| 24 | 24 | |
| 25 | 25 | public static $registeredHandlers = []; |
| 26 | 26 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $reflectAPI = new \ReflectionClass(self::class); |
| 35 | 35 | $methodsList = []; |
| 36 | - $list = $reflectAPI->getMethods(RM::IS_FINAL | RM::IS_STATIC & RM::IS_PRIVATE); |
|
| 36 | + $list = $reflectAPI->getMethods(RM::IS_FINAL|RM::IS_STATIC & RM::IS_PRIVATE); |
|
| 37 | 37 | foreach ($list as $method) { |
| 38 | 38 | $methodsList[$method->name] = $method->getClosure(); |
| 39 | 39 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | foreach ($node as $key => $child) { |
| 104 | 104 | $list[] = self::strHandler($child)->raw; |
| 105 | 105 | } |
| 106 | - return new NodeScalar(implode('',$list), 0); |
|
| 106 | + return new NodeScalar(implode('', $list), 0); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | public static function transform(string $identifier, object $value) |
| 171 | 171 | { |
| 172 | 172 | if (self::isKnown($identifier)) { |
| 173 | - if (!($value instanceof Node) && !($value instanceof NodeList) ) { |
|
| 173 | + if (!($value instanceof Node) && !($value instanceof NodeList)) { |
|
| 174 | 174 | throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value))); |
| 175 | 175 | } |
| 176 | 176 | return self::$registeredHandlers[$identifier]($value); |
@@ -23,7 +23,9 @@ |
||
| 23 | 23 | |
| 24 | 24 | public function add(Node $child):Node |
| 25 | 25 | { |
| 26 | - if (is_null($this->value)) $this->value = new NodeList(); |
|
| 26 | + if (is_null($this->value)) { |
|
| 27 | + $this->value = new NodeList(); |
|
| 28 | + } |
|
| 27 | 29 | $candidate = $child; |
| 28 | 30 | if (!isOneOf($child, ['NodeScalar', 'NodeBlank', 'NodeComment', 'NodeQuoted'])) { |
| 29 | 31 | $candidate = new NodeScalar($child->raw, $child->line); |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | if ($value instanceof NodeKey && $child instanceof NodeKey) { |
| 29 | 29 | if ($value->indent === $child->indent) { |
| 30 | 30 | return parent::add($child); |
| 31 | - } elseif ($value->isAwaitingChild($child)){ |
|
| 31 | + } elseif ($value->isAwaitingChild($child)) { |
|
| 32 | 32 | return $value->add($child); |
| 33 | 33 | } else { |
| 34 | 34 | throw new \ParseError('key ('.$value->identifier.')@'.$value->line.' has already a value', 1); |
@@ -10,16 +10,16 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class NodeComment extends Node |
| 12 | 12 | { |
| 13 | - public function specialProcess(Node &$previous, array &$emptyLines):bool |
|
| 14 | - { |
|
| 13 | + public function specialProcess(Node &$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 | + } |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | if (is_null($this->value)) { |
| 39 | 39 | return null; |
| 40 | 40 | } else { |
| 41 | - if ($this->value instanceof NodeTag){ |
|
| 41 | + if ($this->value instanceof NodeTag) { |
|
| 42 | 42 | $parent->addTag($this->value->_tag); |
| 43 | 43 | $this->value->build($parent); |
| 44 | 44 | } else { |
@@ -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::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches); |
|
| 16 | + preg_match_all(Regex::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1, -1)), $matches); |
|
| 17 | 17 | foreach ($matches['item'] as $key => $item) { |
| 18 | 18 | $i = new NodeItem('', $line); |
| 19 | 19 | $i->indent = null; |