ManifestCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A setChain() 0 4 1
A execute() 0 17 4
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\Console\Command\Manifest;
11
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Transfer\Exception\MissingManifestChainException;
17
use Transfer\Manifest\ManifestChain;
18
19
/**
20
 * Base for manifest commands.
21
 */
22
abstract class ManifestCommand extends Command
23
{
24
    /**
25
     * @var ManifestChain Manifest chain
26
     */
27
    protected $chain;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 12
    protected function configure()
33
    {
34 12
        $this->addOption('chain', 'c', InputOption::VALUE_REQUIRED, 'Manifest chain');
35 12
    }
36
37
    /**
38
     * Sets manifest chain.
39
     *
40
     * @param ManifestChain $chain Manifest chain
41
     */
42 3
    public function setChain(ManifestChain $chain)
43
    {
44 3
        $this->chain = $chain;
45 3
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 8
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52 8
        $file = $input->getOption('chain');
53
54 8
        if ($file !== null) {
55 2
            if (!file_exists($file)) {
56 1
                throw new \InvalidArgumentException(sprintf('File "%s" could not be located.', $file));
57
            }
58
59
            /* @var ManifestChain $input */
60 1
            $this->chain = require $file;
61 1
        }
62
63 7
        if ($this->chain === null) {
64 3
            throw new MissingManifestChainException();
65
        }
66 4
    }
67
}
68