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\Admin\View\Helper; |
||
3 | |||
4 | use Redaxscript\Admin\View\ViewAbstract; |
||
5 | use Redaxscript\Html; |
||
6 | use Redaxscript\Module; |
||
7 | use function array_replace_recursive; |
||
8 | |||
9 | /** |
||
10 | * helper class to create the admin dock |
||
11 | * |
||
12 | * @since 4.0.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category View |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Dock extends ViewAbstract |
||
20 | { |
||
21 | /** |
||
22 | * options of the dock |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | |||
27 | protected $_optionArray = |
||
28 | [ |
||
29 | 'className' => |
||
30 | [ |
||
31 | 'wrapper' => 'rs-admin-wrapper-dock', |
||
32 | 'box' => 'rs-admin-js-dock rs-admin-box-dock', |
||
33 | 'link' => |
||
34 | [ |
||
35 | 'unpublish' => 'rs-admin-link-dock rs-admin-link-unpublish', |
||
36 | 'edit' => 'rs-admin-link-dock rs-admin-link-edit', |
||
37 | 'delete' => 'rs-admin-js-delete rs-admin-link-dock rs-admin-link-delete' |
||
38 | ] |
||
39 | ] |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * init the class |
||
44 | * |
||
45 | * @since 4.0.0 |
||
46 | * |
||
47 | * @param array $optionArray options of the dock |
||
48 | */ |
||
49 | |||
50 | 4 | public function init(array $optionArray = []) : void |
|
51 | { |
||
52 | 4 | $this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray); |
|
53 | 4 | } |
|
54 | |||
55 | /** |
||
56 | * render the view |
||
57 | * |
||
58 | * @since 4.0.0 |
||
59 | * |
||
60 | * @param string $table name of the table |
||
61 | * @param int $id identifier of the item |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | |||
66 | 4 | public function render(string $table = null, int $id = null) : string |
|
67 | { |
||
68 | 4 | $output = Module\Hook::trigger('adminDockStart'); |
|
69 | 4 | $tableEdit = $this->_registry->get($table . 'Edit'); |
|
70 | 4 | $tableDelete = $this->_registry->get($table . 'Delete'); |
|
71 | 4 | $parameterRoute = $this->_registry->get('parameterRoute'); |
|
72 | 4 | $token = $this->_registry->get('token'); |
|
73 | |||
74 | /* html element */ |
||
75 | |||
76 | 4 | $element = new Html\Element(); |
|
77 | $wrapperElement = $element |
||
78 | 4 | ->copy() |
|
79 | 4 | ->init('div', |
|
80 | [ |
||
81 | 4 | 'class' => $this->_optionArray['className']['wrapper'] |
|
82 | ]); |
||
83 | $boxElement = $element |
||
84 | 4 | ->copy() |
|
85 | 4 | ->init('div', |
|
86 | [ |
||
87 | 4 | 'class' => $this->_optionArray['className']['box'] |
|
88 | ]); |
||
89 | $linkUnpublishElement = $element |
||
90 | 4 | ->copy() |
|
91 | 4 | ->init('a', |
|
92 | [ |
||
93 | 4 | 'href' => $parameterRoute . 'admin/unpublish/' . $table . '/' . $id . '/' . $token, |
|
94 | 4 | 'class' => $this->_optionArray['className']['link']['unpublish'], |
|
95 | 4 | 'data-description' => $this->_language->get('unpublish') |
|
96 | ]) |
||
97 | 4 | ->text($this->_language->get('unpublish')); |
|
0 ignored issues
–
show
|
|||
98 | $linkEditElement = $element |
||
99 | 4 | ->copy() |
|
100 | 4 | ->init('a', |
|
101 | [ |
||
102 | 4 | 'href' => $parameterRoute . 'admin/edit/' . $table . '/' . $id, |
|
103 | 4 | 'class' => $this->_optionArray['className']['link']['edit'], |
|
104 | 4 | 'data-description' => $this->_language->get('edit') |
|
105 | ]) |
||
106 | 4 | ->text($this->_language->get('edit')); |
|
0 ignored issues
–
show
It seems like
$this->_language->get('edit') targeting Redaxscript\Language::get() can also be of type array ; however, Redaxscript\Html\Element::text() does only seem to accept string|integer|null , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble.
Loading history...
|
|||
107 | $linkDeleteElement = $element |
||
108 | 4 | ->copy() |
|
109 | 4 | ->init('a', |
|
110 | [ |
||
111 | 4 | 'href' => $parameterRoute . 'admin/delete/' . $table . '/' . $id . '/' . $token, |
|
112 | 4 | 'class' => $this->_optionArray['className']['link']['delete'], |
|
113 | 4 | 'data-description' => $this->_language->get('delete') |
|
114 | ]) |
||
115 | 4 | ->text($this->_language->get('delete')); |
|
0 ignored issues
–
show
It seems like
$this->_language->get('delete') targeting Redaxscript\Language::get() can also be of type array ; however, Redaxscript\Html\Element::text() does only seem to accept string|integer|null , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble.
Loading history...
|
|||
116 | |||
117 | /* collect output */ |
||
118 | |||
119 | 4 | if ($tableEdit || $tableDelete) |
|
120 | { |
||
121 | 3 | if ($tableEdit) |
|
122 | { |
||
123 | 2 | $boxElement->append($linkUnpublishElement . $linkEditElement); |
|
124 | } |
||
125 | 3 | if ($tableDelete) |
|
126 | { |
||
127 | 2 | $boxElement->append($linkDeleteElement); |
|
128 | } |
||
129 | 3 | $output .= $wrapperElement->html($boxElement); |
|
130 | } |
||
131 | 4 | $output .= Module\Hook::trigger('adminDockEnd'); |
|
132 | 4 | return $output; |
|
133 | } |
||
134 | } |
||
135 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.