FinaliseAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 3
b 0
f 0
dl 0
loc 25
ccs 0
cts 10
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 20 3
1
<?php
2
3
namespace App\Action;
4
5
use App\Action\AbstractAction;
6
use App\Action\ActionInterface;
7
use Carbon\Carbon;
8
use Ronanchilvers\Foundation\Config;
9
use Ronanchilvers\Utility\File;
10
use RuntimeException;
11
12
/**
13
 * Action to finalise the deployment
14
 *
15
 * @author Ronan Chilvers <[email protected]>
16
 */
17
class FinaliseAction extends AbstractAction
18
{
19
    /**
20
     * @see \App\Action\ActionInterface::run()
21
     */
22
    public function run(Config $configuration, Context $context)
23
    {
24
        $deployment    = $context->getOrThrow('deployment', 'Invalid or missing project');
25
        $deploymentDir = $context->get('deployment_dir', null);
26
        if (is_null($deploymentDir)) {
27
            return;
28
        }
29
        $filename = File::join($deploymentDir, '.deploy_info');
30
        if (file_exists($filename)) {
31
            return;
32
        }
33
        $info = [
34
            'sha'       => $deployment->sha,
35
            'deployed'  => $deployment->started->format('Y-m-d H:i:s'),
36
            'author'    => $deployment->author,
37
            'committer' => $deployment->committer,
38
        ];
39
        file_put_contents(
40
            $filename,
41
            json_encode($info, JSON_PRETTY_PRINT) . "\n"
42
        );
43
    }
44
}
45