Passed
Push — master ( fb2551...83ffab )
by Ronan
03:47
created

CheckoutAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 82.76%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 29
c 1
b 0
f 0
dl 0
loc 54
ccs 24
cts 29
cp 0.8276
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 34 1
1
<?php
2
3
namespace App\Action;
4
5
use App\Action\AbstractAction;
6
use App\Action\ActionInterface;
7
use App\Facades\Log;
8
use App\Provider\ProviderInterface;
9
use Ronanchilvers\Foundation\Config;
10
use Ronanchilvers\Utility\File;
11
12
/**
13
 * Action to checkout the project from source control
14
 *
15
 * @author Ronan Chilvers <[email protected]>
16
 */
17
class CheckoutAction extends AbstractAction
18
{
19
    /**
20
     * @var \App\Provider\ProviderInterface
21
     */
22
    protected $provider;
23
24
    /**
25
     * Class constructor
26
     *
27
     * @author Ronan Chilvers <[email protected]>
28
     */
29 1
    public function __construct(ProviderInterface $provider)
30
    {
31 1
        $this->provider = $provider;
32 1
    }
33
34
    /**
35
     * @see \App\Action\ActionInterface::run()
36
     */
37 1
    public function run(Config $configuration, Context $context)
38
    {
39 1
        $deploymentBaseDir = $context->getOrThrow('deployment_base_dir', 'Invalid or missing deployment_dir');
40 1
        $project           = $context->getOrThrow('project', 'Invalid or missing project');
41 1
        $deployment        = $context->getOrThrow('deployment', 'Invalid or missing deployment');
42 1
        $deploymentDir     = File::join(
43 1
            $deploymentBaseDir,
44 1
            $deployment->number
45
        );
46 1
        $context->set(
47 1
            'deployment_dir',
48 1
            $deploymentDir
49
        );
50 1
        $label = ($this->provider->getLabel());
51 1
        $this->info(
52 1
            $deployment,
53
            [
54 1
                "Repository: {$label}://{$project->repository} @ {$deployment->sha}",
55
            ]
56
        );
57 1
        Log::debug('Downloading codebase', [
58 1
            'project'    => $project->toArray(),
59 1
            'deployment' => $deployment->toArray(),
60
        ]);
61 1
        $this->provider->download(
62 1
            $project,
63 1
            $deployment,
64 1
            $deploymentDir,
65
            function($type, $detail = '') use ($deployment) {
66
                $this->eventFinder->event(
67
                    $type,
68
                    $deployment,
69
                    'Checkout',
70
                    $detail
71
                );
72 1
            }
73
        );
74 1
    }
75
}
76