ConfigurationFormBuilder::setScope()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php namespace Anomaly\ConfigurationModule\Configuration\Form;
2
3
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
4
5
/**
6
 * Class ConfigurationFormBuilder
7
 *
8
 * @link          http://pyrocms.com/
9
 * @author        PyroCMS, Inc. <[email protected]>
10
 * @author        Ryan Thompson <[email protected]>
11
 */
12
class ConfigurationFormBuilder extends FormBuilder
13
{
14
15
    /**
16
     * The configuration scope.
17
     *
18
     * @var null|string
19
     */
20
    protected $scope = null;
21
22
    /**
23
     * No model needed.
24
     *
25
     * @var bool
26
     */
27
    protected $model = false;
28
29
    /**
30
     * The form fields.
31
     *
32
     * @var ConfigurationFormFields
33
     */
34
    protected $fields = ConfigurationFormFields::class;
35
36
    /**
37
     * The form actions handler.
38
     *
39
     * @var string
40
     */
41
    protected $actions = [
42
        'save',
43
    ];
44
45
    /**
46
     * The form buttons handler.
47
     *
48
     * @var string
49
     */
50
    protected $buttons = [
51
        'cancel',
52
    ];
53
54
    /**
55
     * Fired when the builder is ready to build.
56
     *
57
     * @throws \Exception
58
     */
59
    public function onReady()
60
    {
61
        if (!$this->getScope() && !$this->getEntry()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getScope() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
62
            throw new \Exception('The $scope parameter is required when creating configuration.');
63
        }
64
    }
65
66
    /**
67
     * Get the scope.
68
     *
69
     * @return null|string
70
     */
71
    public function getScope()
72
    {
73
        return $this->scope;
74
    }
75
76
    /**
77
     * Set the scope.
78
     *
79
     * @param $scope
80
     * @return $this
81
     */
82
    public function setScope($scope)
83
    {
84
        $this->scope = $scope;
85
86
        return $this;
87
    }
88
}
89