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