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 | * Purple - Run tasks on collections |
||
4 | * |
||
5 | * PHP version 5 |
||
6 | * |
||
7 | * Copyright (C) 2016 Jake Johns |
||
8 | * |
||
9 | * This software may be modified and distributed under the terms |
||
10 | * of the MIT license. See the LICENSE file for details. |
||
11 | * |
||
12 | * @category Task |
||
13 | * @package Jnjxp\Purple |
||
14 | * @author Jake Johns <[email protected]> |
||
15 | * @copyright 2016 Jake Johns |
||
16 | * @license http://jnj.mit-license.org/2016 MIT License |
||
17 | * @link https://github.com/jnjxp/jnjxp.purple |
||
18 | */ |
||
19 | |||
20 | namespace Jnjxp\Purple; |
||
21 | |||
22 | /** |
||
23 | * Task |
||
24 | * |
||
25 | * @category Task |
||
26 | * @package Jnjxp\Purple |
||
27 | * @author Jake Johns <[email protected]> |
||
28 | * @license http://jnj.mit-license.org/ MIT License |
||
29 | * @link https://github.com/jnjxp/jnjxp.purple |
||
30 | * |
||
31 | * @see TaskInterface |
||
32 | */ |
||
33 | class Task implements TaskInterface |
||
34 | { |
||
35 | /** |
||
36 | * Collection |
||
37 | * |
||
38 | * @var mixed |
||
39 | * |
||
40 | * @access protected |
||
41 | */ |
||
42 | protected $collection; |
||
43 | |||
44 | /** |
||
45 | * Item tasks |
||
46 | * |
||
47 | * @var QueueInterface |
||
48 | * |
||
49 | * @access protected |
||
50 | */ |
||
51 | protected $itemTasks; |
||
52 | |||
53 | /** |
||
54 | * Collection tasks |
||
55 | * |
||
56 | * @var QueueInterface |
||
57 | * |
||
58 | * @access protected |
||
59 | */ |
||
60 | protected $collectionTasks; |
||
61 | |||
62 | /** |
||
63 | * __construct |
||
64 | * |
||
65 | * @param mixed $collection DESCRIPTION |
||
66 | * @param QueueInterface $itemTaskQueue DESCRIPTION |
||
67 | * @param QueueInterface $collectionTaskQueue DESCRIPTION |
||
68 | * |
||
69 | * @access public |
||
70 | */ |
||
71 | 3 | public function __construct( |
|
72 | $collection, |
||
73 | QueueInterface $itemTaskQueue = null, |
||
74 | QueueInterface $collectionTaskQueue = null |
||
75 | ) { |
||
76 | 3 | $this->collection = $collection; |
|
77 | 3 | $this->itemTasks = $itemTaskQueue ?: new Queue; |
|
78 | 3 | $this->collectionTasks = $collectionTaskQueue ?: new Queue; |
|
79 | 3 | } |
|
80 | |||
81 | /** |
||
82 | * Add an item task |
||
83 | * |
||
84 | * @param mixed $task task or task spec |
||
85 | * @param int $priority priority of task |
||
86 | * |
||
87 | * @return $this |
||
88 | * |
||
89 | * @access public |
||
90 | */ |
||
91 | 3 | public function each($task, $priority = 1000) |
|
92 | { |
||
93 | 3 | $this->itemTasks->insert($task, $priority); |
|
94 | 3 | return $this; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Add Item Tasks |
||
99 | * |
||
100 | * @param mixed $tasks tasks to add |
||
101 | * @param int $priority task priority |
||
102 | * |
||
103 | * @return $this |
||
104 | * |
||
105 | * @access public |
||
106 | */ |
||
107 | 1 | public function addItemTasks($tasks, $priority = 1000) |
|
108 | { |
||
109 | 1 | foreach ($tasks as $task) { |
|
110 | 1 | $this->each($task, $priority); |
|
111 | 1 | } |
|
112 | 1 | return $this; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Set Item Tasks |
||
117 | * |
||
118 | * @param mixed $tasks Tasks to set |
||
119 | * @param int $priority Task priority |
||
120 | * |
||
121 | * @return $this |
||
122 | * |
||
123 | * @access public |
||
124 | */ |
||
125 | 1 | public function setItemTasks($tasks, $priority = 1000) |
|
126 | { |
||
127 | 1 | $this->itemTasks->clear(); |
|
128 | 1 | return $this->addItemTasks($tasks, $priority); |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * Add a collection task |
||
133 | * |
||
134 | * @param mixed $task task |
||
135 | * @param int $priority order priority |
||
136 | * |
||
137 | * @return $this |
||
138 | * |
||
139 | * @access public |
||
140 | */ |
||
141 | 3 | public function all($task, $priority = 1000) |
|
142 | { |
||
143 | 3 | $this->collectionTasks->insert($task, $priority); |
|
144 | 3 | return $this; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * Add Collection Tasks |
||
149 | * |
||
150 | * @param mixed $tasks tasks to add |
||
151 | * @param int $priority task priority |
||
152 | * |
||
153 | * @return $this |
||
154 | * |
||
155 | * @access public |
||
156 | */ |
||
157 | 1 | public function addCollectionTasks($tasks, $priority = 1000) |
|
158 | { |
||
159 | 1 | foreach ($tasks as $task) { |
|
160 | 1 | $this->all($task, $priority); |
|
161 | 1 | } |
|
162 | 1 | return $this; |
|
163 | } |
||
164 | |||
165 | /** |
||
166 | * Set Collection Tasks |
||
167 | * |
||
168 | * @param mixed $tasks tasks to set |
||
169 | * @param int $priority priority of tasks |
||
170 | * |
||
171 | * @return $this |
||
172 | * |
||
173 | * @access public |
||
174 | */ |
||
175 | 1 | public function setCollectionTasks($tasks, $priority = 1000) |
|
176 | { |
||
177 | 1 | $this->collectionTasks->clear(); |
|
178 | 1 | return $this->addCollectionTasks($tasks, $priority); |
|
179 | } |
||
180 | |||
181 | /** |
||
182 | * Get collection |
||
183 | * |
||
184 | * @return mixed |
||
185 | * |
||
186 | * @access public |
||
187 | */ |
||
188 | 2 | public function getCollection() |
|
189 | { |
||
190 | 2 | return $this->collection; |
|
191 | } |
||
192 | |||
193 | /** |
||
194 | * Get item tasks |
||
195 | * |
||
196 | * @return QueueInterface |
||
197 | * |
||
198 | * @access public |
||
199 | */ |
||
200 | 3 | public function getItemTasks() |
|
201 | { |
||
202 | 3 | return $this->itemTasks; |
|
0 ignored issues
–
show
|
|||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Get collection tasks |
||
207 | * |
||
208 | * @return QueueInterface |
||
209 | * |
||
210 | * @access public |
||
211 | */ |
||
212 | 3 | public function getCollectionTasks() |
|
213 | { |
||
214 | 3 | return $this->collectionTasks; |
|
0 ignored issues
–
show
The return type of
return $this->collectionTasks; (Jnjxp\Purple\QueueInterface ) is incompatible with the return type declared by the interface Jnjxp\Purple\TaskInterface::getCollectionTasks of type array .
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
Loading history...
|
|||
215 | } |
||
216 | } |
||
217 |
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.