code4interactive /
forms
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 | namespace Code4\Forms\Traits; |
||
| 3 | |||
| 4 | trait checkedTrait |
||
| 5 | { |
||
| 6 | protected $checked = false; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Sprawdza czy pole powinno być zaznaczone |
||
| 10 | * @param string|array $value |
||
| 11 | * @param string $oKey |
||
| 12 | * @return $this |
||
| 13 | */ |
||
| 14 | public function checked($value = null, $oKey = null) { |
||
| 15 | |||
| 16 | if (is_null($value)) { |
||
| 17 | return $this; |
||
| 18 | } |
||
| 19 | |||
| 20 | //Checkboxy $this->value powinny mieć wyłącznie jako "string" |
||
| 21 | if (is_array($this->value)) { |
||
| 22 | $this->value = $this->value[0]; |
||
|
0 ignored issues
–
show
|
|||
| 23 | } |
||
| 24 | |||
| 25 | $this->checked = false; |
||
| 26 | |||
| 27 | if (is_array($value)) { |
||
| 28 | if (isAssoc($value)) { |
||
| 29 | //W przypadku tablicy asocjacyjnej ($key=>$val) jeśli $val jest typu bool to znaczy że $key == $this->value |
||
| 30 | if (is_bool(array_values($value)[0])) { |
||
| 31 | if (array_key_exists($this->value, $value)) { |
||
| 32 | $this->checked = $value[$this->value]; |
||
| 33 | return $this; |
||
| 34 | } |
||
| 35 | } else { |
||
| 36 | //W przeciwnym przypdaku uznajemy że tablica przechowuje pary klucz => wartosc odpowiadające $this->name => $this->value |
||
| 37 | if (array_key_exists($this->name, $value)) { |
||
| 38 | $this->checked = $value[$this->name] == $this->value; |
||
|
0 ignored issues
–
show
The property
name does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | } else { |
||
| 43 | $this->checked = in_array($this->value, $value); |
||
| 44 | return $this; |
||
| 45 | } |
||
| 46 | |||
| 47 | return $this; |
||
| 48 | } |
||
| 49 | |||
| 50 | //Jeżeli jest kolekcją obiektów to obowiązkowo należy podać drugi parametr jakim jest nazwa pola |
||
| 51 | View Code Duplication | if (is_object($value) && $oKey) { |
|
|
0 ignored issues
–
show
The expression
$oKey of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
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. Loading history...
|
|||
| 52 | foreach($value as $v) |
||
| 53 | { |
||
| 54 | if (property_exists($v, $oKey)) |
||
| 55 | { |
||
| 56 | $prop = $v->$oKey; |
||
| 57 | if (is_bool($prop)) |
||
| 58 | { |
||
| 59 | $this->checked = $prop; |
||
| 60 | } else |
||
| 61 | { |
||
| 62 | $this->checked = $prop == $this->value; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | return $this; |
||
| 67 | } |
||
| 68 | |||
| 69 | //Jeżeli jest obiektem |
||
| 70 | View Code Duplication | if (is_object($value) && $oKey) { |
|
|
0 ignored issues
–
show
The expression
$oKey of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
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. Loading history...
|
|||
| 71 | if (property_exists($value, $oKey)) |
||
| 72 | { |
||
| 73 | $prop = $value->$oKey; |
||
| 74 | if (is_bool($prop)) |
||
| 75 | { |
||
| 76 | $this->checked = $prop; |
||
| 77 | } else |
||
| 78 | { |
||
| 79 | $this->checked = $prop == $this->value; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | if (is_bool($value)) { |
||
| 85 | $this->checked = $value; |
||
| 86 | return $this; |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->checked = $this->value == $value; |
||
| 90 | |||
| 91 | return $this; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Pobiera atrybut checked dla html |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | public function getChecked() { |
||
| 99 | return $this->checked ? 'checked' : ''; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Dla pól checkbox value powinno ustawiać checked na true lub false a nie zastepowac warość |
||
| 104 | * @param null $value |
||
| 105 | * @param null $key |
||
| 106 | * @return null|string |
||
| 107 | */ |
||
| 108 | public function value($value = null, $key = null) { |
||
| 109 | if (is_null($value)) { |
||
| 110 | return parent::value(); |
||
| 111 | } |
||
| 112 | return $this->checked($value, $key); |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Jeżeli chcemy zastąpić wartość |
||
| 117 | * @param null $value |
||
| 118 | * @param null $key |
||
| 119 | */ |
||
| 120 | public function setValue($value = null, $key = null) { |
||
| 121 | return parent::value($value, $key); |
||
|
0 ignored issues
–
show
It seems like you call parent on a different method (
value() instead of setValue()). Are you sure this is correct? If so, you might want to change this to $this->value().
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 Loading history...
|
|||
| 122 | } |
||
| 123 | |||
| 124 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: