ResultTaskFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\DeployerTimer;
5
6
use Deployer\Deployer;
7
use Deployer\Task\Task;
8
9
class ResultTaskFactory
10
{
11
    /**
12
     * @var TimerTaskDecorator
13
     */
14
    private $timer;
15
    /**
16
     * @var Deployer
17
     */
18
    private $deployer;
19
20 3
    public function __construct(Deployer $deployer, TimerTaskDecorator $timer)
21
    {
22 3
        $this->deployer = $deployer;
23 3
        $this->timer = $timer;
24 3
    }
25
26 3
    public function createCsvResultTask($fileName): string
27
    {
28 3
        $taskName = uniqid('timer_result-', true);
29
        $taskBody = function () use ($fileName) {
30 3
            file_put_contents($fileName, $this->timer->resultsAsCsv());
31 3
        };
32 3
        $this->deployer->tasks->set($taskName, new Task($taskName, $taskBody));
33
34 3
        return $taskName;
35
    }
36
}
37