Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Task.php (2 issues)

Upgrade to new PHP Analysis Engine

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
Bug Best Practice introduced by
The return type of return $this->itemTasks; (Jnjxp\Purple\QueueInterface) is incompatible with the return type declared by the interface Jnjxp\Purple\TaskInterface::getItemTasks 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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
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
Bug Best Practice introduced by
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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
215
    }
216
}
217