TraitCommand::fire()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
namespace Factory\Console\Make;
4
5
use Factory\Composer;
6
use Factory\Console\BaseCommand;
7
use Factory\Generators\TraitGenerator;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class TraitCommand extends BaseCommand
12
{
13
    /**
14
     * @var TraitGenerator
15
     */
16
    private $generator;
17
    /**
18
     * @var \Factory\Composer
19
     */
20
    private $composer;
21
22
    public function __construct(Composer $composer, TraitGenerator $generator)
23
    {
24
        parent::__construct();
25
        $this->generator = $generator;
26
        $this->composer = $composer;
27
    }
28
29
    public function configure()
30
    {
31
        $this->setName('make:trait');
32
        $this->setDescription('Create a trait.');
33
34
        $this->addArgument('name', InputArgument::REQUIRED, 'The name of the trait to make.');
35
        $this->addOption('force', null, InputOption::VALUE_NONE, 'The class should overwrite an existing one.');
36
    }
37
38
    public function fire()
39
    {
40
        $data = [
41
            'name' => $this->argument('name'),
42
        ];
43
44
        $result = $this->generator->setData($data)->setForce($this->option('force'))->make();
0 ignored issues
show
Documentation introduced by
$this->option('force') is of type string|array, but the function expects a boolean.

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...
45
46
        if ($result) {
47
            $this->info('Trait: ' . $this->composer->getClassPath($this->argument('name')) . ' created');
48
        } else {
49
            $this->error('Something went wrong!');
50
        }
51
    }
52
}
53