ConsoleBuilder::getApplication()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
/*
4
 * doctrine-manager-builder (https://github.com/juliangut/doctrine-manager-builder).
5
 * Doctrine2 managers builder.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/doctrine-manager-builder
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
namespace Jgut\Doctrine\ManagerBuilder;
13
14
use Symfony\Component\Console\Application;
15
16
/**
17
 * Console builder.
18
 */
19
class ConsoleBuilder extends AbstractBuilderCollection
20
{
21
    /**
22
     * Get console application.
23
     *
24
     * @return Application
25
     */
26
    public function getApplication()
27
    {
28
        $application = new Application('Doctrine Manager Builder Command Line Interface');
29
        $application->setCatchExceptions(true);
30
31
        foreach ($this->builders as $builder) {
32
            foreach ($builder->getConsoleCommands() as $command) {
33
                $helperSet = $command->getHelperSet();
34
35
                $application->add($command)->setHelperSet($helperSet);
0 ignored issues
show
Bug introduced by
It seems like $helperSet defined by $command->getHelperSet() on line 33 can be null; however, Symfony\Component\Consol...Command::setHelperSet() 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...
36
            }
37
        }
38
39
        return $application;
40
    }
41
}
42