Passed
Pull Request — 4.2 (#140)
by David
04:58
created

GenerateCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Mouf\Database\TDBM\Commands;
3
4
use Mouf\Database\TDBM\ConfigurationInterface;
5
use Mouf\Database\TDBM\TDBMService;
6
use Mouf\Utils\Log\Psr\MultiLogger;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Logger\ConsoleLogger;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class GenerateCommand extends Command
13
{
14
15
    /**
16
     * @var TDBMService
17
     */
18
    private $configuration;
19
20
    public function __construct(ConfigurationInterface $configuration)
21
    {
22
        parent::__construct();
23
        $this->configuration = $configuration;
0 ignored issues
show
Documentation Bug introduced by
It seems like $configuration of type object<Mouf\Database\TDBM\ConfigurationInterface> is incompatible with the declared type object<Mouf\Database\TDBM\TDBMService> of property $configuration.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
    }
25
26
    protected function configure()
27
    {
28
        $this->setName('tdbm:generate')
29
            ->setDescription('Generates DAOs and beans.')
30
            ->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
31
        ;
32
    }
33
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        // TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans)
37
38
        $alteredConf = new AlteredConfiguration($this->configuration);
0 ignored issues
show
Documentation introduced by
$this->configuration is of type object<Mouf\Database\TDBM\TDBMService>, but the function expects a object<Mouf\Database\TDBM\ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
40
41
        $loggers = [ new ConsoleLogger($output) ];
42
43
        $logger = $alteredConf->getLogger();
44
        if ($logger) {
45
            $loggers[] = $logger;
46
        }
47
48
        $multiLogger = new MultiLogger($loggers);
49
50
        $alteredConf->setLogger($multiLogger);
51
52
        $multiLogger->notice('Starting regenerating DAOs and beans');
53
54
        $tdbmService = new TDBMService($this->configuration);
0 ignored issues
show
Documentation introduced by
$this->configuration is of type object<Mouf\Database\TDBM\TDBMService>, but the function expects a object<Mouf\Database\TDBM\ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
        $tdbmService->generateAllDaosAndBeans();
56
57
        $multiLogger->notice('Finished regenerating DAOs and beans');
58
    }
59
}
60