These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\View; |
||
3 | |||
4 | use Redaxscript\Admin; |
||
5 | use Redaxscript\Config; |
||
6 | use Redaxscript\Content; |
||
7 | use Redaxscript\Html; |
||
8 | use Redaxscript\Language; |
||
9 | use Redaxscript\Model; |
||
10 | use Redaxscript\Module; |
||
11 | use Redaxscript\Registry; |
||
12 | use Redaxscript\Request; |
||
13 | use Redaxscript\Validator; |
||
14 | use function array_replace_recursive; |
||
15 | |||
16 | /** |
||
17 | * children class to create the article |
||
18 | * |
||
19 | * @since 4.0.0 |
||
20 | * |
||
21 | * @package Redaxscript |
||
22 | * @category View |
||
23 | * @author Henry Ruhs |
||
24 | */ |
||
25 | |||
26 | class Article extends ViewAbstract |
||
27 | { |
||
28 | /** |
||
29 | * instance of the request class |
||
30 | * |
||
31 | * @var Request |
||
32 | */ |
||
33 | |||
34 | protected $_request; |
||
35 | |||
36 | /** |
||
37 | * instance of the config class |
||
38 | * |
||
39 | * @var Config |
||
40 | */ |
||
41 | |||
42 | protected $_config; |
||
43 | |||
44 | /** |
||
45 | * options of the article |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | |||
50 | protected $_optionArray = |
||
51 | [ |
||
52 | 'tag' => |
||
53 | [ |
||
54 | 'title' => 'h2', |
||
55 | 'box' => 'div' |
||
56 | ], |
||
57 | 'className' => |
||
58 | [ |
||
59 | 'title' => 'rs-title-content', |
||
60 | 'box' => 'rs-box-content' |
||
61 | ], |
||
62 | 'orderColumn' => 'rank' |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * constructor of the class |
||
67 | * |
||
68 | * @since 4.0.0 |
||
69 | * |
||
70 | * @param Registry $registry instance of the registry class |
||
71 | * @param Request $request instance of the request class |
||
72 | * @param Language $language instance of the language class |
||
73 | * @param Config $config instance of the config class |
||
74 | */ |
||
75 | |||
76 | 5 | public function __construct(Registry $registry, Request $request, Language $language, Config $config) |
|
77 | { |
||
78 | 5 | parent::__construct($registry, $language); |
|
79 | 5 | $this->_request = $request; |
|
80 | 5 | $this->_config = $config; |
|
81 | 5 | } |
|
82 | |||
83 | /** |
||
84 | * init the class |
||
85 | * |
||
86 | * @since 4.0.0 |
||
87 | * |
||
88 | * @param array $optionArray options of the article |
||
89 | * |
||
90 | * @return self |
||
91 | */ |
||
92 | |||
93 | 5 | public function init(array $optionArray = []) : self |
|
94 | { |
||
95 | 5 | $this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray); |
|
96 | 5 | return $this; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * render the view |
||
101 | * |
||
102 | * @since 4.0.0 |
||
103 | * |
||
104 | * @param int $categoryId identifier of the category |
||
105 | * @param int $articleId identifier of the article |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | |||
110 | 5 | public function render(int $categoryId = null, int $articleId = null) : string |
|
111 | { |
||
112 | 5 | if ($this->_registry->get('articleReplace')) |
|
113 | { |
||
114 | return Module\Hook::trigger('articleReplace'); |
||
115 | } |
||
116 | 5 | $output = Module\Hook::trigger('articleStart'); |
|
117 | 5 | $outputItem = null; |
|
118 | 5 | $accessValidator = new Validator\Access(); |
|
119 | 5 | $articleModel = new Model\Article(); |
|
120 | 5 | $articles = null; |
|
0 ignored issues
–
show
|
|||
121 | 5 | $contentParser = new Content\Parser($this->_registry, $this->_request, $this->_language, $this->_config); |
|
122 | 5 | $byline = new Helper\Byline($this->_registry, $this->_language); |
|
123 | 5 | $byline->init(); |
|
124 | 5 | $adminDock = new Admin\View\Helper\Dock($this->_registry, $this->_language); |
|
125 | 5 | $adminDock->init(); |
|
126 | 5 | $loggedIn = $this->_registry->get('loggedIn'); |
|
127 | 5 | $token = $this->_registry->get('token'); |
|
128 | 5 | $firstParameter = $this->_registry->get('firstParameter'); |
|
129 | 5 | $lastTable = $this->_registry->get('lastTable'); |
|
130 | 5 | $parameterRoute = $this->_registry->get('parameterRoute'); |
|
131 | 5 | $myGroups = $this->_registry->get('myGroups'); |
|
132 | |||
133 | /* html element */ |
||
134 | |||
135 | 5 | $element = new Html\Element(); |
|
136 | $titleElement = $element |
||
137 | 5 | ->copy() |
|
138 | 5 | ->init($this->_optionArray['tag']['title'], |
|
139 | [ |
||
140 | 5 | 'class' => $this->_optionArray['className']['title'] |
|
141 | ]); |
||
142 | 5 | $linkElement = $element->copy()->init('a'); |
|
143 | $boxElement = $element |
||
144 | 5 | ->copy() |
|
145 | 5 | ->init($this->_optionArray['tag']['box'], |
|
146 | [ |
||
147 | 5 | 'class' => $this->_optionArray['className']['box'] |
|
148 | ]); |
||
149 | 5 | $articles = $this->queryArticles($categoryId, $articleId); |
|
150 | |||
151 | /* process articles */ |
||
152 | |||
153 | 5 | foreach ($articles as $value) |
|
154 | { |
||
155 | 5 | if ($accessValidator->validate($value->access, $myGroups)) |
|
156 | { |
||
157 | 5 | $outputItem .= Module\Hook::trigger('articleFragmentStart', (array)$value); |
|
158 | 5 | if ($value->headline) |
|
159 | { |
||
160 | $outputItem .= $titleElement |
||
161 | 5 | ->attr('id', 'article-' . $value->alias) |
|
162 | 5 | ->html($lastTable === 'categories' ? $linkElement |
|
163 | 1 | ->attr('href', $parameterRoute . $articleModel->getRouteById($value->id)) |
|
164 | 5 | ->text($value->title) : $value->title |
|
165 | ); |
||
166 | } |
||
167 | 5 | $contentParser->process($value->text, $articleModel->getRouteById($value->id)); |
|
168 | 5 | $outputItem .= $boxElement->html($contentParser->getOutput()); |
|
169 | 5 | if ($value->byline) |
|
170 | { |
||
171 | 5 | $outputItem .= $byline->render($value->date, $value->author); |
|
172 | } |
||
173 | 5 | $outputItem .= Module\Hook::trigger('articleFragmentEnd', (array)$value); |
|
174 | |||
175 | /* admin dock */ |
||
176 | |||
177 | 5 | if ($loggedIn === $token && $firstParameter !== 'logout') |
|
178 | { |
||
179 | 1 | $outputItem .= $adminDock->render('articles', $value->id); |
|
180 | } |
||
181 | } |
||
182 | } |
||
183 | |||
184 | /* collect output */ |
||
185 | |||
186 | 5 | $output .= $outputItem . Module\Hook::trigger('articleEnd'); |
|
187 | 5 | return $output; |
|
188 | } |
||
189 | |||
190 | /** |
||
191 | * query the articles |
||
192 | * |
||
193 | * @since 4.0.0 |
||
194 | * |
||
195 | * @param int $categoryId identifier of the category |
||
196 | * @param int $articleId identifier of the article |
||
197 | * |
||
198 | * @return object|null |
||
199 | */ |
||
200 | |||
201 | 5 | public function queryArticles(int $categoryId = null, int $articleId = null) : ?object |
|
202 | { |
||
203 | 5 | $articleModel = new Model\Article(); |
|
204 | 5 | $settingModel = new Model\Setting(); |
|
205 | 5 | $lastSubParameter = $this->_registry->get('lastSubParameter'); |
|
206 | 5 | $language = $this->_registry->get('language'); |
|
207 | |||
208 | /* query articles */ |
||
209 | |||
210 | 5 | if ($categoryId) |
|
211 | { |
||
212 | 1 | $limitStep = $settingModel->get('pagination') ? $lastSubParameter - 1 : null; |
|
213 | 1 | return $articleModel->getSiblingByCategoryAndLanguageAndOrderAndStep($categoryId, $language, $this->_optionArray['orderColumn'], $limitStep); |
|
214 | } |
||
215 | 4 | if ($articleId) |
|
216 | { |
||
217 | 2 | return $articleModel->getSiblingByIdAndLanguageAndOrder($articleId, $language, $this->_optionArray['orderColumn']); |
|
218 | } |
||
219 | 2 | return $articleModel->getByLanguageAndOrder($language, $this->_optionArray['orderColumn']); |
|
220 | } |
||
221 | } |
||
222 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.