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 namespace nyx\console\input\parameter\definitions; |
||
2 | |||
3 | // External dependencies |
||
4 | use nyx\core; |
||
5 | |||
6 | // Internal dependencies |
||
7 | use nyx\console\input; |
||
8 | |||
9 | /** |
||
10 | * Input Option Definitions |
||
11 | * |
||
12 | * @version 0.1.0 |
||
13 | * @author Michal Chojnacki <[email protected]> |
||
14 | * @copyright 2012-2017 Nyx Dev Team |
||
15 | * @link https://github.com/unyx/nyx |
||
16 | */ |
||
17 | class Options extends input\parameter\Definitions |
||
18 | { |
||
19 | /** |
||
20 | * @var input\Option[] A map of Option names to their Definitions. |
||
21 | */ |
||
22 | protected $items = []; |
||
23 | |||
24 | /** |
||
25 | * @var input\Option[] A map of Option shortcuts to their Definitions. |
||
26 | */ |
||
27 | protected $shortcuts = []; |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function __construct($options = null) |
||
33 | { |
||
34 | $this->setCollectedType(input\Option::class); |
||
35 | |||
36 | parent::__construct($options); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function replace($items) : core\collections\interfaces\Collection |
||
43 | { |
||
44 | $this->items = []; |
||
45 | $this->shortcuts = []; |
||
46 | |||
47 | foreach ($this->extractItems($items) as $item) { |
||
48 | $this->add(is_array($item) ? $this->unpack($item) : $item); |
||
49 | } |
||
50 | |||
51 | return $this; |
||
0 ignored issues
–
show
|
|||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | public function add(core\interfaces\Named $option) : core\collections\interfaces\NamedObjectSet |
||
58 | { |
||
59 | parent::add($option); |
||
60 | |||
61 | // If the Option has a shortcut... |
||
62 | /* @var input\Option $option */ |
||
63 | if ($shortcut = $option->getShortcut()) { |
||
64 | if (isset($this->shortcuts[$shortcut])) { |
||
65 | throw new core\collections\exceptions\KeyAlreadyExists($this, $shortcut, $option, "An option with this shortcut [$shortcut] has already been defined."); |
||
66 | } |
||
67 | |||
68 | $this->shortcuts[$shortcut] = $option; |
||
69 | } |
||
70 | |||
71 | return $this; |
||
0 ignored issues
–
show
The return type of
return $this; (nyx\console\input\parameter\definitions\Options ) is incompatible with the return type of the parent method nyx\core\collections\NamedObjectSet::add of type nyx\core\collections\traits\NamedObjectSet .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function remove(string $name): core\collections\interfaces\NamedObjectSet |
||
78 | { |
||
79 | if (!isset($this->items[$name])) { |
||
80 | return $this; |
||
0 ignored issues
–
show
The return type of
return $this; (nyx\console\input\parameter\definitions\Options ) is incompatible with the return type of the parent method nyx\core\collections\NamedObjectSet::remove of type nyx\core\collections\traits\NamedObjectSet .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
81 | } |
||
82 | |||
83 | if ($shortcut = $this->items[$name]->getShortcut()) { |
||
84 | unset($this->shortcuts[$shortcut]); |
||
85 | } |
||
86 | |||
87 | return parent::remove($name); |
||
0 ignored issues
–
show
The return type of
return parent::remove($name); (nyx\console\input\parameter\definitions\Options ) is incompatible with the return type of the parent method nyx\core\collections\NamedObjectSet::remove of type nyx\core\collections\traits\NamedObjectSet .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Returns the map of Option shortcuts to their Definitions. |
||
92 | * |
||
93 | * @return input\Option[] |
||
94 | */ |
||
95 | public function getShortcuts() : array |
||
96 | { |
||
97 | return $this->shortcuts; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Returns the Option matching a given shortcut name. |
||
102 | * |
||
103 | * @param string $shortcut The name of the shortcut. |
||
104 | * @return input\Option The Option matching the shortcut name. |
||
105 | * @throws core\collections\exceptions\KeyNotExists When the given shortcut is not defined. |
||
106 | */ |
||
107 | public function getByShortcut(string $shortcut) : input\Option |
||
108 | { |
||
109 | if (!isset($this->shortcuts[$shortcut])) { |
||
110 | throw new core\collections\exceptions\KeyNotExists($this, $shortcut, "The short option [$shortcut] is not defined."); |
||
111 | } |
||
112 | |||
113 | return $this->shortcuts[$shortcut]; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Unpacks a sequence of Option constructor arguments into an Option instance. |
||
118 | * |
||
119 | * @see \nyx\console\input\Option::__construct() |
||
120 | * |
||
121 | * @param array $definition The arguments to unpack. The order must match the constructor's signature. |
||
122 | * @return input\Option |
||
123 | */ |
||
124 | protected function unpack(array $definition) : input\Option |
||
125 | { |
||
126 | // If the 4th argument is an integer, we are going to assume it's one of the input\Value |
||
127 | // class constants defining the mode and attempt to instantiate a input\Value with such. |
||
128 | if (isset($definition[3]) && is_int($definition[3])) { |
||
129 | $definition[3] = new input\Value($definition[3]); |
||
130 | } |
||
131 | |||
132 | return new input\Option(...$definition); |
||
0 ignored issues
–
show
$definition is of type array<integer,?,{"3":"?"}> , but the function expects a string .
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);
![]() |
|||
133 | } |
||
134 | } |
||
135 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.