kakserpom /
phpdaemon
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 PHPDaemon\Config; |
||
| 3 | |||
| 4 | use PHPDaemon\Config\Entry\Generic; |
||
| 5 | |||
| 6 | /** |
||
| 7 | * Config section |
||
| 8 | * |
||
| 9 | * @property Entry\Boolean enable |
||
| 10 | * @property Entry\Boolean allowoverridebinpath |
||
| 11 | * @property Entry\Boolean allowoverridechroot |
||
| 12 | * @property Entry\Boolean allowoverrideuser |
||
| 13 | * @property Entry\Boolean allowoverridegroup |
||
| 14 | * @property Entry\Boolean allowoverridecwd |
||
| 15 | * @property Entry\Generic cwd |
||
| 16 | * @property Entry\Generic indexfiles |
||
| 17 | * @property Entry\Generic mastersocket |
||
| 18 | * @package Core |
||
| 19 | * @subpackage Config |
||
| 20 | * |
||
| 21 | * @author Vasily Zorin <[email protected]> |
||
| 22 | * @dynamic_fields |
||
| 23 | */ |
||
| 24 | class Section implements \ArrayAccess |
||
| 25 | { |
||
| 26 | use \PHPDaemon\Traits\ClassWatchdog; |
||
| 27 | |||
| 28 | /** @var */ |
||
| 29 | public $source; |
||
| 30 | /** @var */ |
||
| 31 | public $revision; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Constructor |
||
| 35 | * @param hash |
||
| 36 | * @return object |
||
|
0 ignored issues
–
show
|
|||
| 37 | */ |
||
| 38 | public function __construct($arr = []) |
||
| 39 | { |
||
| 40 | foreach ($arr as $k => $v) { |
||
| 41 | if (!is_object($v)) { |
||
| 42 | $e = new Generic; |
||
| 43 | $e->setHumanValue($v); |
||
| 44 | $this->{$k} = $e; |
||
| 45 | } else { |
||
| 46 | $this->{$k} = $v; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Count elements |
||
| 53 | * @return integer |
||
| 54 | */ |
||
| 55 | public function count() |
||
| 56 | { |
||
| 57 | return count($this) - 2; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * toArray handler |
||
| 62 | * @return hash |
||
|
0 ignored issues
–
show
|
|||
| 63 | */ |
||
| 64 | public function toArray() |
||
| 65 | { |
||
| 66 | $arr = []; |
||
| 67 | foreach ($this as $k => $entry) { |
||
|
0 ignored issues
–
show
|
|||
| 68 | if (!$entry instanceof Generic) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | $arr[$k] = $entry->value; |
||
| 72 | } |
||
| 73 | return $arr; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Checks if property exists |
||
| 78 | * @param string Property name |
||
| 79 | * @return boolean Exists? |
||
| 80 | */ |
||
| 81 | |||
| 82 | public function offsetExists($prop) |
||
| 83 | { |
||
| 84 | $prop = $this->getRealPropertyName($prop); |
||
| 85 | return property_exists($this, $prop); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Get real property name |
||
| 90 | * @param string Property name |
||
| 91 | * @return string Real property name |
||
| 92 | */ |
||
| 93 | public function getRealPropertyName($prop) |
||
| 94 | { |
||
| 95 | return str_replace('-', '', strtolower($prop)); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Get property by name |
||
| 100 | * @param string Property name |
||
| 101 | * @return mixed |
||
| 102 | */ |
||
| 103 | public function offsetGet($prop) |
||
| 104 | { |
||
| 105 | $prop = $this->getRealPropertyName($prop); |
||
| 106 | return isset($this->{$prop}) ? $this->{$prop}->value : null; |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Set property |
||
| 111 | * @param string Property name |
||
| 112 | * @param mixed Value |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | public function offsetSet($prop, $value) |
||
| 116 | { |
||
| 117 | $prop = $this->getRealPropertyName($prop); |
||
| 118 | $this->{$prop} = $value; |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Unset property |
||
| 123 | * @param string Property name |
||
| 124 | * @return void |
||
| 125 | */ |
||
| 126 | public function offsetUnset($prop) |
||
| 127 | { |
||
| 128 | $prop = $this->getRealPropertyName($prop); |
||
| 129 | unset($this->{$prop}); |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Impose default config |
||
| 134 | * @param array {"setting": "value"} |
||
| 135 | * @return void |
||
| 136 | */ |
||
| 137 | public function imposeDefault($settings = []) |
||
| 138 | { |
||
| 139 | foreach ($settings as $name => $value) { |
||
| 140 | $name = strtolower(str_replace('-', '', $name)); |
||
| 141 | if (!isset($this->{$name})) { |
||
| 142 | if (is_scalar($value)) { |
||
| 143 | $this->{$name} = new Generic($value); |
||
| 144 | } else { |
||
| 145 | $this->{$name} = $value; |
||
| 146 | } |
||
| 147 | } elseif ($value instanceof Section) { |
||
| 148 | $value->imposeDefault($value); |
||
|
0 ignored issues
–
show
$value is of type object<PHPDaemon\Config\Section>, but the function expects a array.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 149 | } else { |
||
| 150 | $current = $this->{$name}; |
||
| 151 | if (!is_object($value)) { |
||
| 152 | $this->{$name} = new Generic($value); |
||
| 153 | } else { |
||
| 154 | $this->{$name} = $value; |
||
| 155 | } |
||
| 156 | $this->{$name}->setHumanValue($current->value); |
||
| 157 | $this->{$name}->source = $current->source; |
||
| 158 | $this->{$name}->revision = $current->revision; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.