This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace AtAdmin\Controller; |
||
4 | |||
5 | use AtDataGrid\DataGrid; |
||
6 | use AtDataGrid\Form\FormBuilder; |
||
7 | use AtDataGrid\Manager as GridManager; |
||
8 | use AtDataGrid\Manager; |
||
9 | use Zend\EventManager\EventManager; |
||
10 | use Zend\Form\Form; |
||
11 | use Zend\View\Model\ViewModel; |
||
12 | |||
13 | class GridController extends AbstractAdminController |
||
14 | { |
||
15 | // Events |
||
16 | const EVENT_CHECK_PERMISSIONS_LIST = 'at-admin.check-permissions.list'; |
||
17 | const EVENT_CHECK_PERMISSIONS_CREATE = 'at-admin.check-permissions.create'; |
||
18 | const EVENT_CHECK_PERMISSIONS_EDIT = 'at-admin.check-permissions.edit'; |
||
19 | const EVENT_CHECK_PERMISSIONS_DELETE = 'at-admin.check-permissions.delete'; |
||
20 | |||
21 | const EVENT_VALIDATION_EDIT_PRE = 'at-admin.validation.edit.pre'; |
||
22 | |||
23 | const EVENT_SAVE_PRE = 'at-admin.save.pre'; |
||
24 | const EVENT_SAVE_POST = 'at-admin.save.post'; |
||
25 | const EVENT_DELETE_PRE = 'at-admin.delete.pre'; |
||
26 | const EVENT_DELETE_POST = 'at-admin.delete.post'; |
||
27 | |||
28 | const EVENT_SET_TEMPLATE_CREATE = 'at-admin.set-template.create'; |
||
29 | const EVENT_SET_TEMPLATE_EDIT = 'at-admin.set-template.edit'; |
||
30 | |||
31 | // Page titles |
||
32 | // @todo Remove |
||
33 | const TITLE_ACTION_LIST = ''; |
||
34 | const TITLE_ACTION_CREATE = 'Create'; |
||
35 | const TITLE_ACTION_EDIT = 'Edit'; |
||
36 | const TITLE_ACTION_DELETE = 'Delete'; |
||
37 | |||
38 | /** |
||
39 | * @var GridManager |
||
40 | */ |
||
41 | protected $gridManager; |
||
42 | |||
43 | /** |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function getAction() |
||
0 ignored issues
–
show
|
|||
47 | { |
||
48 | $this->getEventManager()->trigger(self::EVENT_CHECK_PERMISSIONS_LIST, $this); |
||
49 | |||
50 | // Save back url to redirect after actions |
||
51 | $this->backTo()->setBackUrl(); |
||
0 ignored issues
–
show
The method
backTo does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
52 | |||
53 | // Check for mass actions |
||
54 | if (isset($_POST['cmd'])) { |
||
55 | $this->forward($_POST['cmd']); // @todo refactor this |
||
0 ignored issues
–
show
The call to
GridController::forward() has too many arguments starting with $_POST['cmd'] .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
56 | } |
||
57 | |||
58 | $gridManager = $this->getGridManager(); |
||
59 | $grid = $gridManager->getGrid(); |
||
60 | |||
61 | if ($this->request->getQuery('order')) { |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getQuery() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
62 | $order = explode('~', $this->request->getQuery('order')); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getQuery() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
63 | $grid->setOrder([$order[0] => $order[1]]); |
||
64 | } |
||
65 | |||
66 | if ($this->request->getQuery('page')) { |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getQuery() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
67 | $grid->setCurrentPage($this->request->getQuery('page')); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getQuery() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
68 | } |
||
69 | |||
70 | if ($this->request->getQuery('show_items')) { |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getQuery() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
71 | $grid->setItemsPerPage($this->request->getQuery('show_items')); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getQuery() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
72 | } |
||
73 | |||
74 | $filtersForm = $gridManager->getFiltersForm(); |
||
75 | $filtersForm->setData($this->request->getQuery()); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getQuery() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
76 | if (!$filtersForm->isValid()) { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
77 | //$this->flashMessenger()->addMessage($filtersForm->getMessages()); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
80% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
78 | } |
||
79 | |||
80 | $grid->setFiltersData($filtersForm->getData()); |
||
81 | |||
82 | return $gridManager->render(); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return mixed|ViewModel |
||
87 | * @throws \Exception |
||
88 | */ |
||
89 | public function createAction() |
||
90 | { |
||
91 | /** @var EventManager $eventManager */ |
||
92 | $eventManager = $this->getEventManager(); |
||
93 | $eventManager->trigger(self::EVENT_CHECK_PERMISSIONS_CREATE, $this); |
||
94 | |||
95 | /** @var GridManager $gridManager */ |
||
96 | $gridManager = $this->getGridManager(); |
||
97 | if (! $gridManager->isAllowCreate()) { |
||
98 | throw new \Exception('Creating is disabled'); |
||
99 | } |
||
100 | |||
101 | /** @var FormBuilder $formManager */ |
||
102 | $formBuilder = $gridManager->getFormBuilder(); |
||
103 | |||
104 | /** @var DataGrid $grid */ |
||
105 | $grid = $gridManager->getGrid(); |
||
106 | |||
107 | /** @var Form $form */ |
||
108 | $form = $formBuilder->build($grid); |
||
109 | |||
110 | if ($this->getRequest()->isPost()) { |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
111 | $post = $this->getRequest()->getPost(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
112 | $form->setData($post); |
||
113 | |||
114 | View Code Duplication | if ($form->isValid()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
115 | // Replace POST data with filtered and validated form values |
||
116 | // POST data may contains not only form data |
||
117 | $data = array_replace($post->toArray(), $form->getData()); |
||
118 | |||
119 | $eventManager->trigger(self::EVENT_SAVE_PRE, null, $data); |
||
120 | $item = $grid->save($data); |
||
121 | $eventManager->trigger(self::EVENT_SAVE_POST, $item, $data); |
||
122 | |||
123 | return $this->backTo()->previous('Record created'); |
||
0 ignored issues
–
show
The method
backTo does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
124 | } else { |
||
125 | $this->flashMessenger()->addMessage('Check form data.'); |
||
0 ignored issues
–
show
The method
flashMessenger does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
126 | } |
||
127 | } |
||
128 | |||
129 | $viewModel = new ViewModel([ |
||
130 | 'title' => static::TITLE_ACTION_CREATE, |
||
131 | 'form' => $form, |
||
132 | 'customJs' => $formBuilder->getCustomJs(), |
||
133 | 'formSections' => $formBuilder->getFormSections(), |
||
134 | 'backUrl' => $this->backTo()->getBackUrl(false), |
||
0 ignored issues
–
show
The method
backTo does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
135 | ]); |
||
136 | |||
137 | $viewModel->setTemplate('at-admin/create.phtml'); |
||
138 | $eventResult = $eventManager->trigger(self::EVENT_SET_TEMPLATE_CREATE, $viewModel)->last(); |
||
139 | if ($eventResult) { |
||
140 | $viewModel = $eventResult; |
||
141 | } |
||
142 | |||
143 | return $viewModel; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @return array|mixed|ViewModel |
||
148 | * @throws \Exception |
||
149 | */ |
||
150 | public function editAction() |
||
151 | { |
||
152 | /** @var Manager $gridManager */ |
||
153 | $gridManager = $this->getGridManager(); |
||
154 | if (!$gridManager->isAllowEdit()) { |
||
155 | throw new \Exception('Editing is disabled'); |
||
156 | } |
||
157 | |||
158 | /** @var DataGrid $grid */ |
||
159 | $grid = $gridManager->getGrid(); |
||
160 | |||
161 | $id = $this->params($grid->getIdentifierColumnName()); |
||
162 | if (!$id) { |
||
163 | return $this->notFoundAction(); |
||
164 | } |
||
165 | |||
166 | $item = $grid->getRow($id); |
||
167 | if (!$item) { |
||
168 | return $this->notFoundAction(); |
||
169 | } |
||
170 | |||
171 | /** @var EventManager $eventManager */ |
||
172 | $eventManager = $this->getEventManager(); |
||
173 | $eventManager->trigger(self::EVENT_CHECK_PERMISSIONS_EDIT, $item); |
||
174 | |||
175 | /** @var FormBuilder $formBuilder */ |
||
176 | $formBuilder = $gridManager->getFormBuilder(); |
||
177 | |||
178 | /** @var Form $form */ |
||
179 | $form = $formBuilder->build($grid, FormBuilder::FORM_CONTEXT_EDIT, $item); |
||
180 | |||
181 | if ($this->getRequest()->isPost()) { |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
182 | $post = $this->getRequest()->getPost(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\Stdlib\RequestInterface as the method getPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request , Zend\Http\Request .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
183 | $form->setData($post); |
||
184 | |||
185 | $this->getEventManager()->trigger(self::EVENT_VALIDATION_EDIT_PRE, $form, ['oldData' => $item, 'newData' => $post]); |
||
186 | |||
187 | View Code Duplication | if ($form->isValid()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
188 | // Replace POST data with filtered and validated form values |
||
189 | // POST data may contains not only form data (extra data from sections) |
||
190 | $data = array_replace($post->toArray(), $form->getData()); |
||
191 | |||
192 | $eventManager->trigger(self::EVENT_SAVE_PRE, $item, $data); |
||
193 | $item = $grid->save($data, $id); |
||
194 | $eventManager->trigger(self::EVENT_SAVE_POST, $item, $data); |
||
195 | |||
196 | $this->backTo()->previous('Record was updated'); |
||
0 ignored issues
–
show
The method
backTo does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
197 | } else { |
||
198 | $this->flashMessenger()->addMessage('Check form data'); |
||
0 ignored issues
–
show
The method
flashMessenger does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
199 | } |
||
200 | } |
||
201 | |||
202 | $viewModel = new ViewModel([ |
||
203 | 'title' => static::TITLE_ACTION_EDIT, |
||
204 | 'item' => $item, |
||
205 | 'form' => $form, |
||
206 | 'customJs' => $formBuilder->getCustomJs(), |
||
207 | 'formSections' => $formBuilder->getFormSections(), |
||
208 | 'backUrl' => $this->backTo()->getBackUrl(false), |
||
0 ignored issues
–
show
The method
backTo does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
209 | ]); |
||
210 | |||
211 | $viewModel->setTemplate('at-admin/edit.phtml'); |
||
212 | $eventResult = $this->getEventManager()->trigger(self::EVENT_SET_TEMPLATE_EDIT, $viewModel, ['item' => $item])->last(); |
||
213 | if ($eventResult) { |
||
214 | $viewModel = $eventResult; |
||
215 | } |
||
216 | |||
217 | return $viewModel; |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * @return array |
||
222 | * @throws \Exception |
||
223 | */ |
||
224 | public function deleteAction() |
||
225 | { |
||
226 | $gridManager = $this->getGridManager(); |
||
227 | if (!$gridManager->isAllowDelete()) { |
||
228 | throw new \Exception('Deleting is disabled.'); |
||
229 | } |
||
230 | |||
231 | $id = $this->params('id'); |
||
232 | if (!$id) { |
||
233 | return $this->notFoundAction(); |
||
234 | } |
||
235 | |||
236 | $grid = $gridManager->getGrid(); |
||
237 | $item = $grid->getRow($id); |
||
238 | if (!$item) { |
||
239 | return $this->notFoundAction(); |
||
240 | } |
||
241 | |||
242 | $evm = $this->getEventManager(); |
||
243 | $evm->trigger(self::EVENT_CHECK_PERMISSIONS_DELETE, $item); |
||
244 | |||
245 | // Get additional params |
||
246 | $params = array_merge_recursive( |
||
247 | $this->params()->fromQuery(), |
||
248 | $this->params()->fromPost() |
||
249 | ); |
||
250 | |||
251 | $evm->trigger(self::EVENT_DELETE_PRE, $item, $params); |
||
252 | $grid->delete($id); |
||
253 | $evm->trigger(self::EVENT_DELETE_POST, $item, $params); |
||
254 | |||
255 | $this->backTo()->previous('Record deleted.'); |
||
0 ignored issues
–
show
The method
backTo does not exist on object<AtAdmin\Controller\GridController> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
256 | } |
||
257 | |||
258 | /** |
||
259 | * @param Manager $manager |
||
260 | */ |
||
261 | public function setGridManager(GridManager $manager) |
||
262 | { |
||
263 | $this->gridManager = $manager; |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * @return Manager |
||
268 | */ |
||
269 | public function getGridManager() |
||
270 | { |
||
271 | if (!$this->gridManager) { |
||
272 | throw new \RuntimeException('Grid manager was not set'); |
||
273 | } |
||
274 | |||
275 | return $this->gridManager; |
||
276 | } |
||
277 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: