Conditions | 10 |
Paths | 26 |
Total Lines | 46 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
47 | public function parse() |
||
48 | { |
||
49 | $configuration = new Configuration(); |
||
50 | $preface = ''; |
||
51 | |||
52 | /* @var AbstractSection|null $currentSection */ |
||
53 | $currentSection = null; |
||
54 | |||
55 | foreach ($this->getNormalizedConfigurationLines() as $line) { |
||
56 | // Parse preface |
||
57 | if ($currentSection === null && self::isComment($line)) { |
||
58 | $preface .= $line . PHP_EOL; |
||
59 | } |
||
60 | |||
61 | // Omit empty lines |
||
62 | if (empty($line)) { |
||
63 | continue; |
||
64 | } |
||
65 | |||
66 | // Check for section changes |
||
67 | $newSection = Factory::makeFactory($line); |
||
68 | |||
69 | if ($newSection !== null) { |
||
70 | $currentSection = $newSection; |
||
71 | $configuration->addSection($currentSection); |
||
72 | |||
73 | continue; |
||
74 | } |
||
75 | |||
76 | // Parse parameters into the current section |
||
77 | if ($currentSection !== null) { |
||
78 | // Distinguish between parameters and magic comments |
||
79 | if (self::isMagicComment($line)) { |
||
80 | $currentSection->addMagicComment(self::parseMagicComment($line)); |
||
81 | } else if (!self::isComment($line)) { |
||
82 | $currentSection->addParameter(self::parseParameter($line)); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | |||
87 | if (!empty($preface)) { |
||
88 | $configuration->setPreface($preface); |
||
89 | } |
||
90 | |||
91 | return $configuration; |
||
92 | } |
||
93 | |||
186 |