| Conditions | 24 | 
| Paths | 668 | 
| Total Lines | 63 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 98 | public function parse($strContent = null)  | 
            ||
| 99 |     { | 
            ||
| 100 | $sourceIterator = $this->getSourceIterator($strContent);  | 
            ||
| 101 | $previous = $root = new Node();  | 
            ||
| 102 | $emptyLines = [];  | 
            ||
| 103 |         try { | 
            ||
| 104 |             foreach ($sourceIterator() as $lineNb => $lineString) { | 
            ||
| 105 | $n = new Node($lineString, $lineNb);  | 
            ||
| 106 | $deepest = $previous->getDeepestNode();  | 
            ||
| 107 |                 if ($n->type & (Y::LITTERALS|Y::BLANK|Y::COMMENT|Y::TAG) || $deepest->type & Y::PARTIAL) { | 
            ||
| 108 | if ($this->onSpecialType($n, $previous, $emptyLines, $lineString)) continue;  | 
            ||
| 109 | }  | 
            ||
| 110 | //Note: 6.6 comments: Note that outside scalar content, a line containing only white space characters is taken to be a comment line.  | 
            ||
| 111 |                 foreach ($emptyLines as $blankNode) { | 
            ||
| 112 |                     if ($blankNode !== $previous) { | 
            ||
| 113 | $blankNode->getParent()->add($blankNode);  | 
            ||
| 114 | }  | 
            ||
| 115 | }  | 
            ||
| 116 | $emptyLines = [];  | 
            ||
| 117 |                 switch ($n->indent <=> $previous->indent) { | 
            ||
| 118 | case -1: $target = $previous->getParent($n->indent, $n->type & Y::ITEM ? Y::KEY : null);  | 
            ||
| 119 | break;  | 
            ||
| 120 | case 0:  | 
            ||
| 121 |                         if ($n->type & Y::KEY && $n->indent === 0) { | 
            ||
| 122 | $target = $root;  | 
            ||
| 123 |                         } elseif($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) { | 
            ||
| 124 | $target = $deepest;  | 
            ||
| 125 |                         } else { | 
            ||
| 126 | $target = $previous->getParent();  | 
            ||
| 127 | }  | 
            ||
| 128 | break;  | 
            ||
| 129 | default:  | 
            ||
| 130 | $target = $previous;  | 
            ||
| 131 |                         if ($previous->type & Y::ITEM) { | 
            ||
| 132 |                             if ($deepest->type & (Y::KEY|Y::TAG) && is_null($deepest->value)) { | 
            ||
| 133 | $target = $deepest;  | 
            ||
| 134 | }  | 
            ||
| 135 | }  | 
            ||
| 136 | }  | 
            ||
| 137 | if ($this->onContextType($n, $target, $lineString)) continue;  | 
            ||
| 138 | $target->add($n);  | 
            ||
| 139 | $previous = $n;  | 
            ||
| 140 | }  | 
            ||
| 141 |             if ($this->debug === 2) { | 
            ||
| 142 | print_r((new \ReflectionClass(Y::class))->getConstants());  | 
            ||
| 143 | echo "\033[33mParsed Structure\033[0m\n";  | 
            ||
| 144 | print_r($root);  | 
            ||
| 145 | exit();  | 
            ||
| 146 | }  | 
            ||
| 147 | $out = Builder::buildContent($root, $this->debug);  | 
            ||
| 148 | return $out;  | 
            ||
| 149 |         } catch (\Error|\Exception|\ParseError $e) { | 
            ||
| 150 | $file = $this->filePath ? basename($this->filePath) : '#YAML STRING#';  | 
            ||
| 151 | $message = basename($e->getFile())."@".$e->getLine().": ".$e->getMessage()." for '$file' @".($lineNb)."\n";  | 
            ||
| 152 |             if ($this->options & self::NO_PARSING_EXCEPTIONS) { | 
            ||
| 153 | // trigger_error($message, E_USER_WARNING);  | 
            ||
| 154 | self::$error = $message;  | 
            ||
| 155 | return null;  | 
            ||
| 156 | }  | 
            ||
| 157 | $this->debug && print_r($root);  | 
            ||
| 158 | throw new \Exception($message, 3);  | 
            ||
| 159 | }  | 
            ||
| 160 | }  | 
            ||
| 161 | |||
| 207 | 
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.