Skip to content

Commit 6bcf74e

Browse files
committed
Improve from static analysis results
1 parent 017b891 commit 6bcf74e

File tree

11 files changed

+45
-27
lines changed

11 files changed

+45
-27
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
"autoload-dev": {
3535
"psr-4": {
3636
"IntegerNet\\DeployerTimer\\": "tests/"
37-
}
37+
},
38+
"files": [
39+
"recipe/timer.php"
40+
]
3841
},
3942
"scripts": {
4043
"test": "phpunit && infection && phpstan analyze --level 7 src tests && phan"

recipe/timer.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
use IntegerNet\DeployerTimer\ResultTaskFactory;
88
use IntegerNet\DeployerTimer\TimerTaskDecorator;
99

10-
function timer(): ResultTaskFactory
11-
{
12-
$deployer = Deployer::get();
13-
$decorateAllTasks = new DecorateAllTasks($deployer);
14-
$timer = new TimerTaskDecorator();
15-
$decorateAllTasks->with($timer);
16-
return new ResultTaskFactory($deployer, $timer);
10+
/**
11+
* @SuppressWarnings(PHPMD.StaticAccess)
12+
*/
13+
if (!function_exists(__NAMESPACE__ . '\timer')) {
14+
function timer(): ResultTaskFactory
15+
{
16+
$deployer = Deployer::get();
17+
$decorateAllTasks = new DecorateAllTasks($deployer);
18+
$timer = new TimerTaskDecorator();
19+
$decorateAllTasks->with($timer);
20+
return new ResultTaskFactory($deployer, $timer);
21+
}
1722
}

src/Clock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
interface Clock
77
{
88
public function microtime(): float;
9-
}
9+
}

src/DecorateAllTasks.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ public function with(TaskDecorator $decorator): void
2323
foreach ($this->deployer->tasks as $taskName => $task) {
2424
$beforeName = $taskName . '.' . $decorator->name() . '.before';
2525
$afterName = $taskName . '.' . $decorator->name() . '.after';
26-
$this->deployer->tasks->set($beforeName, (new Task($beforeName, $decorator->callbackBefore($taskName)))->shallow());
27-
$this->deployer->tasks->set($afterName, (new Task($afterName, $decorator->callbackAfter($taskName)))->shallow());
26+
$this->deployer->tasks->set(
27+
$beforeName,
28+
(new Task($beforeName, $decorator->callbackBefore($taskName)))->shallow()
29+
);
30+
$this->deployer->tasks->set(
31+
$afterName,
32+
(new Task($afterName, $decorator->callbackAfter($taskName)))->shallow()
33+
);
2834
if (!in_array($task->getName(), [$beforeName, $afterName], true)) {
2935
$task->addBefore($beforeName);
3036
$task->addAfter($afterName);

src/FakeClock.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ public function microtime(): float
2020
return $this->timestamp;
2121
}
2222

23-
public function advanceMs(int $ms): void
23+
public function advanceMillis(int $millis): void
2424
{
25-
$this->timestamp += ($ms * 0.001);
25+
$this->timestamp += ($millis * 0.001);
2626
}
27-
28-
}
27+
}

src/ResultTaskFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ public function createCsvResultTask($fileName): string
3333

3434
return $taskName;
3535
}
36-
}
36+
}

src/TimerEvents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ public function asCsv(): string
2323
}
2424
return implode("\n", $lines);
2525
}
26-
}
26+
}

src/TimerTaskDecorator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,25 @@ public function name(): string
3333

3434
public function callbackBefore(string $taskName): callable
3535
{
36-
return function() use ($taskName) {
36+
return function () use ($taskName) {
3737
\array_push($this->startTimeStack, $this->clock->microtime());
3838
$this->events->append(new TimerEvent(TimerEvent::TYPE_BEGIN, $taskName, $this->clock->microtime(), 0));
3939
};
4040
}
4141

4242
public function callbackAfter(string $taskName): callable
4343
{
44-
return function() use ($taskName) {
44+
return function () use ($taskName) {
4545
$startTime = \array_pop($this->startTimeStack);
4646
$duration = $this->clock->microtime() - $startTime;
47-
$this->events->append(new TimerEvent(TimerEvent::TYPE_END, $taskName, $this->clock->microtime(), $duration));
47+
$this->events->append(
48+
new TimerEvent(TimerEvent::TYPE_END, $taskName, $this->clock->microtime(), $duration)
49+
);
4850
};
4951
}
5052

5153
public function resultsAsCsv(): string
5254
{
5355
return $this->events->asCsv();
5456
}
55-
}
57+
}

tests/FakeClockTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public function testAdvanceMs()
1111
{
1212
$clock = new FakeClock((float) strtotime('2000-01-01'));
1313
$this->assertEqualsWithDelta(946684800, $clock->microtime(), 0.001);
14-
$clock->advanceMs(500);
14+
$clock->advanceMillis(500);
1515
$this->assertEqualsWithDelta(946684800.5, $clock->microtime(), 0.001);
16-
$clock->advanceMs(50);
16+
$clock->advanceMillis(50);
1717
$this->assertEqualsWithDelta(946684800.55, $clock->microtime(), 0.001);
1818
}
1919
}

tests/TaskDecoratorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use function Deployer\task;
1818
use function Deployer\writeln;
1919

20+
/**
21+
* @SuppressWarnings(PHPMD.StaticAccess)
22+
*/
2023
class TaskDecoratorTest extends TestCase
2124
{
2225
/**

0 commit comments

Comments
 (0)