Passed
Push — master ( e82656...5198fb )
by Thierry
03:06
created

Package::factory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Package.php
5
 *
6
 * Package.
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
11
 * @link https://github.com/jaxon-php/jaxon-core
12
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
13
14
namespace Jaxon\Plugin;
15
16
use Jaxon\Plugin\Contract\CodeGeneratorInterface;
17
use Jaxon\Request\Factory;
18
use Jaxon\Ui\View\ViewRenderer;
19
use Jaxon\Utils\Config\Config;
20
21
abstract class Package implements CodeGeneratorInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Package
Loading history...
22
{
23
    /**
24
     * The configuration options of the package
25
     *
26
     * @var Config
27
     */
28
    protected $xPkgConfig;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
29
30
    /**
31
     * The request factory
32
     * 
33
     * @var Factory
34
     */
35
    protected $xFactory;
36
37
    /**
38
     * The view renderer
39
     *
40
     * @var ViewRenderer
41
     */
42
    protected $xRenderer;
43
44
    /**
45
     * Whether to include the getReadyScript() in the generated code.
46
     *
47
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
48
     */
49
    protected $bReadyEnabled = false;
50
51
    /**
52
     * Get the path to the config file, or the config options in an array.
53
     *
54
     * @return string|array
55
     */
56
    abstract public static function config();
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
57
58
    /**
59
     * Get the value of a given package option
60
     *
61
     * @param string $sOption    The option name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
62
     * @param mixed $xDefault    The default value
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
63
     *
64
     * @return mixed
65
     */
66
    public function getOption(string $sOption, $xDefault = null)
67
    {
68
        return $this->xPkgConfig->getOption($sOption, $xDefault);
69
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
70
71
    /**
72
     * Get the request factory
73
     *
74
     * @return Factory
75
     */
76
    public function factory(): Factory
77
    {
78
        return $this->xFactory;
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
80
81
    /**
82
     * Get the view renderer
83
     *
84
     * @return ViewRenderer
85
     */
86
    public function view(): ViewRenderer
87
    {
88
        return $this->xRenderer;
89
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
90
91
    /**
92
     * Include the getReadyScript() in the generated code.
93
     *
94
     * @return void
95
     */
96
    public function ready()
97
    {
98
        $this->bReadyEnabled = true;
99
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
100
101
    /**
102
     * @inheritDoc
103
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
104
    public function readyEnabled(): bool
105
    {
106
        return $this->bReadyEnabled;
107
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
108
109
    /**
110
     * @inheritDoc
111
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
112
    public final function readyInlined(): bool
113
    {
114
        // For packages, the getReadyScript() is never exported to external files.
115
        return true;
116
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
117
118
    /**
119
     * @inheritDoc
120
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
121
    public final function getHash(): string
122
    {
123
        // Packages do not generate hash on their own. So we make this method final.
124
        return '';
125
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
126
127
    /**
128
     * @inheritDoc
129
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
130
    public function getCss(): string
131
    {
132
        return '';
133
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
134
135
    /**
136
     * @inheritDoc
137
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
138
    public function getJs(): string
139
    {
140
        return '';
141
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
142
143
    /**
144
     * @inheritDoc
145
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
146
    public function getScript(): string
147
    {
148
        return '';
149
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
150
151
    /**
152
     * @inheritDoc
153
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
154
    public function getReadyScript(): string
155
    {
156
        return '';
157
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
158
159
    /**
160
     * Get the HTML code of the package home page
161
     *
162
     * @return string
163
     */
164
    abstract public function getHtml(): string;
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
165
166
    /**
167
     * Get the HTML code of the package home page
168
     *
169
     * This method is an alias for getHtml().
170
     *
171
     * @return string
172
     */
173
    public function html(): string
174
    {
175
        return $this->getHtml();
176
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
177
}
178