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\Template\Helper; |
||
3 | |||
4 | use Redaxscript\Db; |
||
5 | use Redaxscript\Model; |
||
6 | use function is_numeric; |
||
7 | use function is_string; |
||
8 | |||
9 | /** |
||
10 | * helper class to provide a canonical helper |
||
11 | * |
||
12 | * @since 3.0.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category Template |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Canonical extends HelperAbstract |
||
20 | { |
||
21 | /** |
||
22 | * process |
||
23 | * |
||
24 | * @since 3.0.0 |
||
25 | * |
||
26 | * @return string|null |
||
27 | */ |
||
28 | |||
29 | 6 | public function process() : ?string |
|
30 | { |
||
31 | 6 | $contentModel = new Model\Content(); |
|
32 | 6 | $lastTable = $this->_registry->get('lastTable'); |
|
33 | 6 | $lastId = $this->_registry->get('lastId'); |
|
34 | 6 | $parameterRoute = $this->_registry->get('parameterRoute'); |
|
35 | 6 | $root = $this->_registry->get('root'); |
|
36 | 6 | $route = null; |
|
37 | |||
38 | /* find route */ |
||
39 | |||
40 | 6 | if ($lastTable === 'categories') |
|
41 | { |
||
42 | 2 | $articles = Db::forTablePrefix('articles')->where('category', $lastId); |
|
43 | 2 | $articlesTotal = $articles->count(); |
|
44 | 2 | if ($articlesTotal === 1) |
|
45 | { |
||
46 | 1 | $lastTable = 'articles'; |
|
47 | 1 | $lastId = $articles->findOne()->id; |
|
48 | } |
||
49 | } |
||
50 | 6 | if (is_string($lastTable) && is_numeric($lastId)) |
|
51 | { |
||
52 | 5 | $route = $contentModel->getRouteByTableAndId($lastTable, $lastId); |
|
53 | } |
||
54 | |||
55 | /* handle route */ |
||
56 | |||
57 | 6 | if ($route) |
|
0 ignored issues
–
show
|
|||
58 | { |
||
59 | 5 | return $root . '/' . $parameterRoute . $route; |
|
60 | } |
||
61 | 1 | return $root; |
|
62 | } |
||
63 | } |
||
64 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: