Passed
Push — main ( aa41db...017a71 )
by Thierry
02:06
created

Package::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Package.php
5
 *
6
 * Base class for the Jaxon packages.
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\App\View\ViewRenderer;
17
use Jaxon\Request\Factory\Factory;
18
use Jaxon\Utils\Config\Config;
19
20
abstract class Package implements CodeGeneratorInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Package
Loading history...
21
{
22
    /**
23
     * The configuration options of the package
24
     *
25
     * @var Config
26
     */
27
    protected $xPkgConfig;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
28
29
    /**
30
     * The request factory
31
     * 
32
     * @var Factory
33
     */
34
    protected $xFactory;
35
36
    /**
37
     * The view renderer
38
     *
39
     * @var ViewRenderer
40
     */
41
    protected $xRenderer;
42
43
    /**
44
     * Whether to include the getReadyScript() in the generated code.
45
     *
46
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
47
     */
48
    protected $bReadyEnabled = false;
49
50
    /**
51
     * Get the path to the config file, or the config options in an array.
52
     *
53
     * @return string|array
54
     */
55
    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...
56
57
    /**
58
     * Get the package config object
59
     *
60
     * @return Config
61
     */
62
    public function getConfig()
63
    {
64
        return $this->xPkgConfig;
65
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
66
67
    /**
68
     * @param Config $xPkgConfig
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
69
     * @param Factory $xFactory
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
70
     * @param ViewRenderer $xRenderer
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
71
     *
72
     * @return void
73
     */
74
    protected function _init(Config $xPkgConfig, Factory $xFactory, ViewRenderer $xRenderer)
75
    {
76
        $this->xPkgConfig = $xPkgConfig;
77
        $this->xFactory = $xFactory;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
78
        $this->xRenderer = $xRenderer;
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
80
81
    /**
82
     * This method is automatically called after the package instance is created and configured.
83
     *
84
     * @return void
85
     */
86
    public function init()
87
    {}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
88
89
    /**
90
     * Get the value of a given package option
91
     *
92
     * @param string $sOption    The option name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
93
     * @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...
94
     *
95
     * @return mixed
96
     */
97
    public function getOption(string $sOption, $xDefault = null)
98
    {
99
        return $this->xPkgConfig->getOption($sOption, $xDefault);
100
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
101
102
    /**
103
     * Get the request factory
104
     *
105
     * @return Factory
106
     */
107
    public function factory(): Factory
108
    {
109
        return $this->xFactory;
110
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
111
112
    /**
113
     * Get the view renderer
114
     *
115
     * @return ViewRenderer
116
     */
117
    public function view(): ViewRenderer
118
    {
119
        return $this->xRenderer;
120
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
121
122
    /**
123
     * Include the getReadyScript() in the generated code.
124
     *
125
     * @return void
126
     */
127
    public function ready()
128
    {
129
        $this->bReadyEnabled = true;
130
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
131
132
    /**
133
     * @inheritDoc
134
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
135
    public function readyEnabled(): bool
136
    {
137
        return $this->bReadyEnabled;
138
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
139
140
    /**
141
     * @inheritDoc
142
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
143
    public final function readyInlined(): bool
144
    {
145
        // For packages, the getReadyScript() is never exported to external files.
146
        return true;
147
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
148
149
    /**
150
     * @inheritDoc
151
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
152
    public final function getHash(): string
153
    {
154
        // Packages do not generate hash on their own. So we make this method final.
155
        return '';
156
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
157
158
    /**
159
     * @inheritDoc
160
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
161
    public function getCss(): string
162
    {
163
        return '';
164
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
165
166
    /**
167
     * @inheritDoc
168
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
169
    public function getJs(): string
170
    {
171
        return '';
172
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
173
174
    /**
175
     * @inheritDoc
176
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
177
    public function getScript(): string
178
    {
179
        return '';
180
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
181
182
    /**
183
     * @inheritDoc
184
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
185
    public function getReadyScript(): string
186
    {
187
        return '';
188
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
189
190
    /**
191
     * Get the HTML code of the package home page
192
     *
193
     * @return string
194
     */
195
    abstract public function getHtml(): string;
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
196
197
    /**
198
     * Get the HTML code of the package home page
199
     *
200
     * This method is an alias for getHtml().
201
     *
202
     * @return string
203
     */
204
    public function html(): string
205
    {
206
        return $this->getHtml();
207
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
208
}
209