Conditions | 10 |
Paths | 6 |
Total Lines | 61 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
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 |
||
27 | public function parse(ContextInterface $context, Cursor $cursor) |
||
28 | { |
||
29 | $container = $context->getContainer(); |
||
30 | |||
31 | if (!$container instanceof Paragraph) { |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | $lines = $container->getStrings(); |
||
36 | if (count($lines) < 1) { |
||
37 | return false; |
||
38 | } |
||
39 | |||
40 | $match = RegexHelper::matchAll(self::REGEXP_DEFINITION, $cursor->getLine(), $cursor->getFirstNonSpacePosition()); |
||
41 | if (null === $match) { |
||
42 | return false; |
||
43 | } |
||
44 | |||
45 | $columns = $this->parseColumns($match); |
||
46 | $head = $this->parseRow(trim(array_pop($lines)), $columns, TableCell::TYPE_HEAD); |
||
47 | if (null === $head) { |
||
48 | return false; |
||
49 | } |
||
50 | |||
51 | $table = new Table(function (Cursor $cursor) use (&$table, $columns) { |
||
52 | $row = $this->parseRow($cursor->getLine(), $columns); |
||
53 | if (null === $row) { |
||
54 | if (null !== $table->getCaption()) { |
||
55 | return false; |
||
56 | } |
||
57 | |||
58 | if (null !== ($caption = $this->parseCaption($cursor->getLine()))) { |
||
59 | $table->setCaption($caption); |
||
60 | |||
61 | return true; |
||
62 | } |
||
63 | |||
64 | return false; |
||
65 | } |
||
66 | |||
67 | $table->getBody()->appendChild($row); |
||
68 | |||
69 | return true; |
||
70 | }); |
||
71 | |||
72 | $table->getHead()->appendChild($head); |
||
73 | |||
74 | if (count($lines) >= 1) { |
||
75 | $paragraph = new Paragraph(); |
||
76 | foreach ($lines as $line) { |
||
77 | $paragraph->addLine($line); |
||
78 | } |
||
79 | |||
80 | $context->replaceContainerBlock($paragraph); |
||
81 | $context->addBlock($table); |
||
82 | } else { |
||
83 | $context->replaceContainerBlock($table); |
||
84 | } |
||
85 | |||
86 | return true; |
||
87 | } |
||
88 | |||
137 |
It seems like you are relying on a variable being defined by an iteration: