Passed
Push — master ( 880950...25abc4 )
by Bruno
08:17
created

Framework::getElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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\HTMLNode;
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 getElement(string $name): Element
46
    {
47
        return Element::factory($name, $this);
48
    }
49
50
    public function getName(): string
51
    {
52
        return $this->name;
53
    }
54
55
    /**
56
     * @param string $name
57
     * @param mixed $value
58
     * @return mixed
59
     */
60
    public function getOption(string $name, $value = null)
61
    {
62
        return $this->options[$name] ?? $value;
63
    }
64
65
    /**
66
     *
67
     * @param string $name
68
     * @param mixed $value
69
     * @return self
70
     */
71
    public function setOption(string $name, $value): self
72
    {
73
        $this->options[$name] = $value;
74
        return $this;
75
    }
76
77
    /**
78
     * Set a new option
79
     *
80
     * @param array $options
81
     * @return self
82
     */
83
    public function setOptions(array $options): self
84
    {
85
        $this->options = $options;
86
        return $this;
87
    }
88
89
    /**
90
     * Returns a string with the <head> HTML to generate standalone files.
91
     * This is used by the kitchensink generator.
92
     *
93
     * @param HTMLNode $head
94
     * @return void
95
     * @codeCoverageIgnore
96
     */
97
    public function htmlHead(HTMLNode &$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

97
    public function htmlHead(/** @scrutinizer ignore-unused */ HTMLNode &$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...
98
    {
99
    }
100
101
    /**
102
     * Returns a string with things to add to the footer of the page (such as scripts)
103
     * This is used by the kitchensink generator.
104
     *
105
     * @param HTMLNode $head
106
     * @return void
107
     * @codeCoverageIgnore
108
     */
109
    public function htmlFooter(HTMLNode &$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

109
    public function htmlFooter(/** @scrutinizer ignore-unused */ HTMLNode &$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...
110
    {
111
    }
112
113
    /**
114
     * @param Model $m
115
     * @param HTMLNode[] $elements
116
     * @param string $previousCompose
117
     * @return string
118
     */
119
    public function editableCompose(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

119
    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...
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

119
    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...
120
    {
121
        return $previousCompose;
122
    }
123
124
    /**
125
     * @param Model $m
126
     * @param HTMLNode[] $elements
127
     * @param string $previousCompose
128
     * @return string
129
     */
130
    public function viewableCompose(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

130
    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...
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

130
    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...
131
    {
132
        return $previousCompose;
133
    }
134
}
135