Conditions | 2 |
Total Lines | 65 |
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 |
||
96 | private function baseDirs(string $target, array $dirs): void |
||
97 | { |
||
98 | $bc = new class ($dirs) implements BuildListener { |
||
99 | private $expectedBasedirs; |
||
100 | private $calls = 0; |
||
101 | private $error; |
||
102 | |||
103 | public function __construct(array $dirs) |
||
104 | { |
||
105 | $this->expectedBasedirs = $dirs; |
||
106 | } |
||
107 | |||
108 | public function buildStarted(BuildEvent $event) |
||
109 | { |
||
110 | } |
||
111 | |||
112 | public function buildFinished(BuildEvent $event) |
||
113 | { |
||
114 | } |
||
115 | |||
116 | public function targetFinished(BuildEvent $event) |
||
117 | { |
||
118 | } |
||
119 | |||
120 | public function taskStarted(BuildEvent $event) |
||
121 | { |
||
122 | } |
||
123 | |||
124 | public function taskFinished(BuildEvent $event) |
||
125 | { |
||
126 | } |
||
127 | |||
128 | public function messageLogged(BuildEvent $event) |
||
129 | { |
||
130 | } |
||
131 | |||
132 | public function targetStarted(BuildEvent $event) |
||
133 | { |
||
134 | if ($event->getTarget()->getName() === '') { |
||
135 | return; |
||
136 | } |
||
137 | if ($this->error === null) { |
||
138 | try { |
||
139 | BuildFileTest::assertEquals( |
||
140 | $this->expectedBasedirs[$this->calls++], |
||
141 | $event->getProject()->getBaseDir()->getAbsolutePath() |
||
142 | ); |
||
143 | } catch (AssertionError $e) { |
||
144 | $this->error = $e; |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | |||
149 | public function getError() |
||
150 | { |
||
151 | return $this->error; |
||
152 | } |
||
153 | }; |
||
154 | $this->getProject()->addBuildListener($bc); |
||
155 | $this->executeTarget($target); |
||
156 | $ae = $bc->getError(); |
||
157 | if ($ae !== null) { |
||
158 | throw $ae; |
||
159 | } |
||
160 | $this->getProject()->removeBuildListener($bc); |
||
161 | } |
||
163 |