VariableDefinition   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 27
wmc 2
lcom 1
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A instantiateNode() 0 4 1
A createNode() 0 11 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-Config package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Config\Definition\Builder;
12
13
use Borobudur\Config\Definition\VariableNode;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     8/10/15
18
 */
19
class VariableDefinition extends AbstractDefinition
20
{
21
    /**
22
     * Instantiate a variable node.
23
     *
24
     * @return VariableNode
25
     */
26
    protected function instantiateNode()
27
    {
28
        return new VariableNode($this->name, $this->parent);
0 ignored issues
show
Bug introduced by
It seems like $this->parent can also be of type object<Borobudur\Config\...er\DefinitionInterface> or object<Borobudur\Config\...odeDefinitionInterface>; however, Borobudur\Config\Definit...ractNode::__construct() does only seem to accept null|object<Borobudur\Co...finition\NodeInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function createNode()
35
    {
36
        $this->assertParentNode();
37
        $node = $this->instantiateNode();
38
39
        $node->setDefaultValue($this->defaultValue);
40
        $node->setRequired($this->required);
41
        $node->setAllowOverwrite($this->allowOverwrite);
42
43
        return $node;
44
    }
45
}
46