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 | abstract class Ajde_Crud_Field extends Ajde_Object_Standard |
||
4 | { |
||
5 | /** |
||
6 | * @var Ajde_Crud |
||
7 | */ |
||
8 | protected $_crud; |
||
9 | |||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $_type; |
||
14 | |||
15 | protected $_useSpan = 12; |
||
16 | protected $_attributes = []; |
||
17 | |||
18 | public function __construct(Ajde_Crud $crud, $fieldOptions) |
||
19 | { |
||
20 | $explode = explode('_', get_class($this)); |
||
21 | end($explode); |
||
22 | $this->_type = strtolower(current($explode)); |
||
23 | $this->_crud = $crud; |
||
24 | |||
25 | /* defaults */ |
||
26 | $this->_data = [ |
||
27 | 'name' => isset($fieldOptions['name']) ? $fieldOptions['name'] : false, |
||
28 | 'type' => 'text', |
||
29 | 'length' => 255, |
||
30 | 'default' => '', |
||
31 | 'label' => isset($fieldOptions['name']) ? ucfirst($fieldOptions['name']) : false, |
||
32 | 'isRequired' => false, |
||
33 | 'isPK' => false, |
||
34 | 'isAutoIncrement' => false, |
||
35 | 'isAutoUpdate' => false, |
||
36 | ]; |
||
37 | |||
38 | /* options */ |
||
39 | foreach ($fieldOptions as $key => $value) { |
||
40 | $this->set($key, $value); |
||
41 | } |
||
42 | |||
43 | $this->prepare(); |
||
44 | } |
||
45 | |||
46 | protected function prepare() |
||
47 | { |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Getters and setters. |
||
52 | */ |
||
53 | public function getName() |
||
54 | { |
||
55 | return parent::getName(); |
||
0 ignored issues
–
show
|
|||
56 | } |
||
57 | |||
58 | public function getDbType() |
||
59 | { |
||
60 | return parent::getDbType(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getDbType() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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.
![]() |
|||
61 | } |
||
62 | |||
63 | public function getLabel() |
||
64 | { |
||
65 | return parent::getLabel(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getLabel() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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.
![]() |
|||
66 | } |
||
67 | |||
68 | public function getLength() |
||
69 | { |
||
70 | return parent::getLength(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getLength() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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 | } |
||
72 | |||
73 | public function getIsRequired() |
||
74 | { |
||
75 | return parent::getIsRequired(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getIsRequired() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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 | } |
||
77 | |||
78 | public function getDefault() |
||
79 | { |
||
80 | return parent::getDefault(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getDefault() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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.
![]() |
|||
81 | } |
||
82 | |||
83 | public function getIsAutoIncrement() |
||
84 | { |
||
85 | return parent::getIsAutoIncrement(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getIsAutoIncrement() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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.
![]() |
|||
86 | } |
||
87 | |||
88 | public function getIsAutoUpdate() |
||
89 | { |
||
90 | return parent::getIsAutoUpdate(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getIsAutoUpdate() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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.
![]() |
|||
91 | } |
||
92 | |||
93 | public function getIsUnique() |
||
94 | { |
||
95 | return parent::getIsUnique(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getIsUnique() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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.
![]() |
|||
96 | } |
||
97 | |||
98 | public function getValue() |
||
99 | { |
||
100 | if (parent::hasValue()) { |
||
0 ignored issues
–
show
The method
hasValue() does not seem to exist on object<Ajde_Object_Standard> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() It seems like you call parent on a different method (
hasValue() instead of getValue() ). Are you sure this is correct? If so, you might want to change this to $this->hasValue() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
101 | return parent::getValue(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Ajde_Object_Standard as the method getValue() does only exist in the following sub-classes of Ajde_Object_Standard : Ajde_Crud_Field , Ajde_Crud_Field_Boolean , Ajde_Crud_Field_Date , Ajde_Crud_Field_Enum , Ajde_Crud_Field_File , Ajde_Crud_Field_Fk , Ajde_Crud_Field_Header , Ajde_Crud_Field_I18n , Ajde_Crud_Field_Icon , Ajde_Crud_Field_Media , Ajde_Crud_Field_Multiple , Ajde_Crud_Field_Numeric , Ajde_Crud_Field_Publish , Ajde_Crud_Field_Sort , Ajde_Crud_Field_Spatial , Ajde_Crud_Field_Text , Ajde_Crud_Field_Time , Ajde_Crud_Field_Timespan , Ajde_Model_ValidatorAbstract , Ajde_Model_Validator_Date , Ajde_Model_Validator_Enum , Ajde_Model_Validator_HasChildren , Ajde_Model_Validator_Numeric , Ajde_Model_Validator_Required , Ajde_Model_Validator_Spatial , Ajde_Model_Validator_Text , Ajde_Model_Validator_Unique . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends 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 sub-classes 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.
![]() |
|||
102 | } else { |
||
103 | return false; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | public function getType() |
||
108 | { |
||
109 | return $this->_type; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Template functions. |
||
114 | */ |
||
115 | public function getHtml() |
||
116 | { |
||
117 | $template = $this->_getFieldTemplate(); |
||
118 | $template->assign('field', $this); |
||
119 | |||
120 | return $template->render(); |
||
121 | } |
||
122 | |||
123 | public function getInput($id = null) |
||
124 | { |
||
125 | $template = $this->_getInputTemplate(); |
||
126 | $template->assign('field', $this); |
||
127 | $template->assign('id', $id); |
||
128 | |||
129 | return $template->render(); |
||
130 | } |
||
131 | |||
132 | protected function _getFieldTemplate() |
||
133 | { |
||
134 | return $this->_getTemplate('field'); |
||
135 | } |
||
136 | |||
137 | protected function _getInputTemplate() |
||
138 | { |
||
139 | return $this->_getTemplate('field/'.$this->_type); |
||
140 | } |
||
141 | |||
142 | protected function _getTemplate($action) |
||
143 | { |
||
144 | $template = null; |
||
145 | if (Ajde_Template::exist(MODULE_DIR.'_core/', 'crud/'.$action) !== false) { |
||
146 | $template = new Ajde_Template(MODULE_DIR.'_core/', 'crud/'.$action); |
||
147 | Ajde::app()->getDocument()->autoAddResources($template); |
||
0 ignored issues
–
show
|
|||
148 | } |
||
149 | View Code Duplication | if ($this->_hasCustomTemplate($action)) { |
|
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. ![]() |
|||
150 | $base = $this->_getCustomTemplateBase(); |
||
151 | $action = $this->_getCustomTemplateAction($action); |
||
152 | $template = new Ajde_Template($base, $action); |
||
153 | } |
||
154 | if ($template instanceof Ajde_Template) { |
||
155 | return $template; |
||
156 | } else { |
||
157 | // TODO: |
||
158 | throw new Ajde_Exception('No crud template found for field '.$action); |
||
159 | } |
||
160 | } |
||
161 | |||
162 | View Code Duplication | protected function _hasCustomTemplate($action) |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
163 | { |
||
164 | $base = $this->_getCustomTemplateBase(); |
||
165 | $action = $this->_getCustomTemplateAction($action); |
||
166 | |||
167 | return Ajde_Template::exist($base, $action) !== false; |
||
168 | } |
||
169 | |||
170 | protected function _getCustomTemplateBase() |
||
171 | { |
||
172 | return MODULE_DIR.$this->_crud->getCustomTemplateModule().'/'; |
||
173 | } |
||
174 | |||
175 | protected function _getCustomTemplateAction($action) |
||
176 | { |
||
177 | return 'crud/'.(string) $this->_crud->getModel()->getTable().'/'.$action; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * HTML functions. |
||
182 | */ |
||
183 | public function getHtmlRequired() |
||
184 | { |
||
185 | //return '<span class="required">*</span>'; |
||
186 | return ''; |
||
187 | } |
||
188 | |||
189 | public function getHtmlPK() |
||
190 | { |
||
191 | return " <img src='".MEDIA_DIR."icons/16/key_login.png' style='vertical-align: middle;' title='Primary key' />"; |
||
192 | } |
||
193 | |||
194 | public function getHtmlAttributesAsArray() |
||
195 | { |
||
196 | if (empty($this->_attributes)) { |
||
197 | $attributes = []; |
||
198 | if (method_exists($this, '_getHtmlAttributes')) { |
||
199 | $attributes = $this->_getHtmlAttributes(); |
||
0 ignored issues
–
show
|
|||
200 | } |
||
201 | $attributes['name'] = $this->getName(); |
||
202 | if (!array_key_exists('id', $attributes)) { |
||
203 | $attributes['id'] = 'in_'.$this->getName(); |
||
204 | } |
||
205 | if ($this->hasNotEmpty('class')) { |
||
206 | if (array_key_exists('class', $attributes)) { |
||
207 | $attributes['class'] .= ' '.$this->getClass(); |
||
0 ignored issues
–
show
The method
getClass does not exist on object<Ajde_Crud_Field> ? 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 { }
![]() |
|||
208 | } else { |
||
209 | $attributes['class'] = $this->getClass(); |
||
0 ignored issues
–
show
The method
getClass does not exist on object<Ajde_Crud_Field> ? 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 { }
![]() |
|||
210 | } |
||
211 | } |
||
212 | if ($this->_useSpan !== false) { |
||
213 | if (array_key_exists('class', $attributes)) { |
||
214 | $attributes['class'] .= ' span'.$this->_useSpan; |
||
215 | } else { |
||
216 | $attributes['class'] = 'span'.$this->_useSpan; |
||
217 | } |
||
218 | } |
||
219 | $this->_attributes = $attributes; |
||
220 | } |
||
221 | |||
222 | return $this->_attributes; |
||
223 | } |
||
224 | |||
225 | public function getHtmlAttribute($name) |
||
226 | { |
||
227 | $attributes = $this->getHtmlAttributesAsArray(); |
||
228 | if (isset($attributes[$name])) { |
||
229 | return $attributes[$name]; |
||
230 | } |
||
231 | |||
232 | return false; |
||
233 | } |
||
234 | |||
235 | public function getHtmlAttributes() |
||
236 | { |
||
237 | $attributes = $this->getHtmlAttributesAsArray(); |
||
238 | |||
239 | $text = ''; |
||
240 | foreach ($attributes as $k => $v) { |
||
241 | if (strlen($v)) { |
||
242 | $text .= $k.'="'.$v.'" '; |
||
243 | } |
||
244 | } |
||
245 | |||
246 | return $text; |
||
247 | } |
||
248 | |||
249 | /** |
||
250 | * @return Ajde_Crud |
||
251 | */ |
||
252 | public function getCrud() |
||
253 | { |
||
254 | return $this->_crud; |
||
255 | } |
||
256 | } |
||
257 |
Let’s take a look at an example:
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 sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: