CurrentRelease   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 48
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 28 3
1
<?php
2
3
/*
4
 * This file is part of Rocketeer
5
 *
6
 * (c) Maxime Fabre <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 */
12
13
namespace Rocketeer\Tasks;
14
15
use DateTime;
16
17
/**
18
 * Display what the current release is.
19
 */
20
class CurrentRelease extends AbstractTask
21
{
22
    /**
23
     * The slug of the task.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'Current';
28
29
    /**
30
     * A description of what the task does.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Display what the current release is';
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 3
    public function execute()
40
    {
41
        // Get the current stage
42 3
        $stage = $this->connections->getCurrentConnectionKey()->stage;
43 3
        $stage = $stage ? ' for stage '.$stage : '';
44
45
        // Check if a release has been deployed already
46 3
        $currentRelease = $this->releasesManager->getCurrentRelease();
47 3
        if (!$currentRelease) {
48 1
            return $this->explainer->error('No release has yet been deployed'.$stage);
49
        }
50
51
        // Create state message
52 2
        $date = DateTime::createFromFormat('YmdHis', $currentRelease)->format('Y-m-d H:i:s');
53 2
        $state = $this->runForCurrentRelease($this->vcs->currentState());
0 ignored issues
show
Documentation Bug introduced by Maxime Fabre
The method runForCurrentRelease does not exist on object<Rocketeer\Tasks\CurrentRelease>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54 2
        $message = sprintf(
55 2
            'The current release'.$stage.' is <info>%s</info> (<comment>%s</comment> deployed at <comment>%s</comment>)',
56 2
            $currentRelease,
57 2
            $state,
58
            $date
59 2
        );
60
61
        // Display current and past releases
62 2
        $this->explainer->line($message);
63 2
        $this->displayReleases();
64
65 2
        return $message;
66
    }
67
}
68