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