Passed
Pull Request — 4.2 (#140)
by David
09:31
created

GenerateCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Mouf\Database\TDBM\Commands;
3
4
5
use Mouf\Database\TDBM\ConfigurationInterface;
6
use Mouf\Database\TDBM\TDBMService;
7
use Mouf\Utils\Log\Psr\MultiLogger;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Logger\ConsoleLogger;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class GenerateCommand extends Command
14
{
15
16
    /**
17
     * @var TDBMService
18
     */
19
    private $configuration;
20
21
    public function __construct(ConfigurationInterface $configuration)
22
    {
23
        parent::__construct();
24
        $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...
25
    }
26
27
    protected function configure()
28
    {
29
        $this->setName('tdbm:generate')
30
            ->setDescription('Generates DAOs and beans.')
31
            ->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
32
        ;
33
    }
34
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        // TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans)
38
39
        $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...
40
41
42
        $loggers = [ new ConsoleLogger($output) ];
43
44
        $logger = $alteredConf->getLogger();
45
        if ($logger) {
46
            $loggers[] = $logger;
47
        }
48
49
        $multiLogger = new MultiLogger($loggers);
50
51
        $alteredConf->setLogger($multiLogger);
52
53
        $multiLogger->notice('Starting regenerating DAOs and beans');
54
55
        $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...
56
        $tdbmService->generateAllDaosAndBeans();
57
58
        $multiLogger->notice('Finished regenerating DAOs and beans');
59
    }
60
}
61