AbstractSpecConfig::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WebinoDomLib\Dom\Config;
4
5
use WebinoConfigLib\AbstractConfig;
6
use WebinoConfigLib\Feature\FeatureInterface;
7
8
/**
9
 * Class AbstractSpecConfig
10
 */
11
abstract class AbstractSpecConfig extends AbstractConfig implements
12
    FeatureInterface
13
{
14
    /**
15
     * Spec key
16
     *
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @param string $name
23
     */
24
    public function __construct($name)
25
    {
26
        $this->name = (string) $name;
27
    }
28
29
    /**
30
     * @return mixed
31
     */
32
    public function getName()
33
    {
34
        return $this->name;
35
    }
36
37
    /**
38
     * @param string $locator
39
     * @return $this
40
     */
41
    public function setLocator($locator)
42
    {
43
        $this->mergeArray(['locator' => (string) $locator]);
44
        return $this;
45
    }
46
47
    /**
48
     * @param int $priority
49
     * @return $this
50
     */
51
    public function setPriority($priority)
52
    {
53
        $this->mergeArray(['priority' => (int) $priority]);
54
        return $this;
55
    }
56
57
    /**
58
     * @param array $options
59
     * @return $this
60
     */
61
    public function setOptions(array $options)
62
    {
63
        $this->mergeArray(['options' => $options]);
64
        return $this;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function toArray()
71
    {
72
        // set default locator by component name
73
        $this->getData()->offsetExists('locator') or $this->setLocator($this->getName());
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
74
        return parent::toArray();
75
    }
76
}
77