Completed
Pull Request — master (#5)
by David
02:09
created

DumpCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 16
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 7 1
1
<?php
2
3
4
namespace TheCodingMachine\Discovery\Commands;
5
6
7
use Composer\Command\BaseCommand;
8
use Composer\Factory;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use TheCodingMachine\Discovery\AssetsBuilder;
14
use TheCodingMachine\Discovery\AssetType;
15
use TheCodingMachine\Discovery\Dumper;
16
17
class DumpCommand extends BaseCommand
18
{
19
    protected function configure()
20
    {
21
        $this->setName('discovery:dump')
22
             ->setDescription('Regenerates the Discovery class (in the .discovery folder). This is automatically triggered on install and update.');
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $dumper = new Dumper($this->getComposer(), $this->getIO());
0 ignored issues
show
Bug introduced by
It seems like $this->getComposer() can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
28
        $dumper->dumpDiscoveryFiles();
29
30
        $output->writeln('Discovery files successfully dumped in the .discovery directory.');
31
    }
32
}
33