Passed
Push — master ( b78bc9...3bbd58 )
by Bruno
15:37
created

Framework::setOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Formularium;
4
5
use Formularium\Exception\ClassNotFoundException;
6
use Formularium\Exception\Exception;
7
use Formularium\HTMLElement;
8
9
/**
10
 * Abstract base class for frameworks. Each framework should have a class inheriting
11
 * from this class.
12
 */
13
abstract class Framework
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $name;
19
20 6
    /**
21
     * Options for rendering
22 6
     * @var array
23 6
     */
24
    protected $options = [];
25 8
26
    public function __construct(string $name)
27 8
    {
28 8
        $this->name = $name;
29 2
    }
30
31 6
    public static function factory(string $framework = ''): Framework
32
    {
33
        $class = "\\Formularium\\Frontend\\$framework\\Framework";
34
        if (!class_exists($class)) {
35
            throw new ClassNotFoundException("Invalid framework $framework");
36
        }
37
        return new $class();
38
    }
39 2
40
    public function getRenderable(Datatype $datatype): Renderable
41 2
    {
42
        return Renderable::factory($datatype, $this);
43
    }
44
45
    public function getName(): string
46
    {
47
        return $this->name;
48
    }
49
50
    /**
51
     * @param string $name
52
     * @param mixed $value
53
     * @return mixed
54
     */
55
    public function getOption(string $name, $value = null)
56
    {
57
        return $this->options[$name] ?? $value;
58
    }
59
60
    /**
61
     *
62
     * @param string $name
63
     * @param mixed $value
64
     * @return self
65
     */
66
    public function setOption(string $name, $value): self
67
    {
68
        $this->options[$name] = $value;
69
        return $this;
70
    }
71
72
    /**
73
     * Set a new option
74
     *
75
     * @param array $options
76
     * @return self
77
     */
78
    public function setOptions(array $options): self
79
    {
80
        $this->options = $options;
81
        return $this;
82
    }
83
84
    /**
85
     * Returns a string with the <head> HTML to generate standalone files.
86
     * This is used by the kitchensink generator.
87
     *
88
     * @param HTMLElement $head
89
     * @return void
90
     * @codeCoverageIgnore
91
     */
92
    public function htmlHead(HTMLElement &$head)
0 ignored issues
show
Unused Code introduced by
The parameter $head is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

92
    public function htmlHead(/** @scrutinizer ignore-unused */ HTMLElement &$head)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
    }
95
96
    /**
97
     * Returns a string with things to add to the footer of the page (such as scripts)
98
     * This is used by the kitchensink generator.
99
     *
100
     * @param HTMLElement $head
101
     * @return void
102
     * @codeCoverageIgnore
103
     */
104
    public function htmlFooter(HTMLElement &$head)
0 ignored issues
show
Unused Code introduced by
The parameter $head is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

104
    public function htmlFooter(/** @scrutinizer ignore-unused */ HTMLElement &$head)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
    {
106
    }
107
108
    /**
109
     * @param Model $m
110
     * @param HTMLElement[] $elements
111
     * @param string $previousCompose
112
     * @return string
113
     */
114
    public function editableCompose(Model $m, array $elements, string $previousCompose): string
0 ignored issues
show
Unused Code introduced by
The parameter $m is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

114
    public function editableCompose(/** @scrutinizer ignore-unused */ Model $m, array $elements, string $previousCompose): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $elements is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

114
    public function editableCompose(Model $m, /** @scrutinizer ignore-unused */ array $elements, string $previousCompose): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
115
    {
116
        return $previousCompose;
117
    }
118
119
    /**
120
     * @param Model $m
121
     * @param HTMLElement[] $elements
122
     * @param string $previousCompose
123
     * @return string
124
     */
125
    public function viewableCompose(Model $m, array $elements, string $previousCompose): string
0 ignored issues
show
Unused Code introduced by
The parameter $elements is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

125
    public function viewableCompose(Model $m, /** @scrutinizer ignore-unused */ array $elements, string $previousCompose): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $m is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

125
    public function viewableCompose(/** @scrutinizer ignore-unused */ Model $m, array $elements, string $previousCompose): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
126
    {
127
        return $previousCompose;
128
    }
129
}
130