ConsoleBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getApplication() 0 15 3
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