CheckoutAction::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1.0033

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 34
ccs 17
cts 20
cp 0.85
rs 9.504
cc 1
nc 1
nop 2
crap 1.0033
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
            $deploymentDir
49
        );
50 1
        $label = ($this->provider->getLabel());
51 1
        $this->info(
52
            $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
            $project,
63
            $deployment,
64
            $deploymentDir,
65 1
            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