RebuildQueueCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * PHPCI - Continuous Integration for PHP.
4
 *
5
 * @copyright    Copyright 2015, Block 8 Limited.
6
 * @license      https://github.com/Block8/PHPCI/blob/master/LICENSE.md
7
 *
8
 * @link         https://www.phptesting.org/
9
 */
10
11
namespace PHPCI\Command;
12
13
use b8\Store\Factory;
14
use Monolog\Logger;
15
use PHPCI\BuildFactory;
16
use PHPCI\Helper\Lang;
17
use PHPCI\Logging\OutputLogHandler;
18
use PHPCI\Service\BuildService;
19
use Symfony\Component\Console\Command\Command;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * @author       Dan Cryer <[email protected]>
25
 */
26
class RebuildQueueCommand extends Command
27
{
28
    /**
29
     * @var OutputInterface
30
     */
31
    protected $output;
32
33
    /**
34
     * @var Logger
35
     */
36
    protected $logger;
37
38
    /**
39
     * @param \Monolog\Logger $logger
40
     * @param string          $name
41
     */
42
    public function __construct(Logger $logger, $name = null)
43
    {
44
        parent::__construct($name);
45
        $this->logger = $logger;
46
    }
47
48
    protected function configure()
49
    {
50
        $this
51
            ->setName('phpci:rebuild-queue')
52
            ->setDescription('Rebuilds the PHPCI worker queue.');
53
    }
54
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $this->output = $output;
58
59
        // For verbose mode we want to output all informational and above
60
        // messages to the symphony output interface.
61
        if ($input->hasOption('verbose') && $input->getOption('verbose')) {
62
            $this->logger->pushHandler(
63
                new OutputLogHandler($this->output, Logger::INFO)
64
            );
65
        }
66
67
        $store = Factory::getStore('Build');
68
        $result = $store->getByStatus(0);
69
70
        $this->logger->addInfo(Lang::get('found_n_builds', count($result['items'])));
71
72
        $buildService = new BuildService($store);
0 ignored issues
show
Compatibility introduced by
$store of type object<b8\Store> is not a sub-type of object<PHPCI\Store\BuildStore>. It seems like you assume a child class of the class b8\Store to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
73
74
        while (count($result['items'])) {
75
            $build = array_shift($result['items']);
76
            $build = BuildFactory::getBuild($build);
77
78
            $this->logger->addInfo('Added build #'.$build->getId().' to queue.');
79
            $buildService->addBuildToQueue($build);
80
        }
81
    }
82
}
83