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 | namespace PlaygroundGame\Service; |
||
4 | |||
5 | use DoctrineModule\Validator\NoObjectExists as NoObjectExistsValidator; |
||
6 | use Zend\ServiceManager\ServiceManager; |
||
7 | use Zend\EventManager\EventManagerAwareTrait; |
||
8 | use PlaygroundGame\Options\ModuleOptions; |
||
9 | use PlaygroundGame\Mapper\Prize as PrizeMapper; |
||
10 | use Zend\ServiceManager\ServiceLocatorInterface; |
||
11 | |||
12 | class Prize |
||
13 | { |
||
14 | use EventManagerAwareTrait; |
||
15 | |||
16 | /** |
||
17 | * @var prizeMapper |
||
18 | */ |
||
19 | protected $prizeMapper; |
||
20 | |||
21 | /** |
||
22 | * @var ServiceManager |
||
23 | */ |
||
24 | protected $serviceManager; |
||
25 | |||
26 | /** |
||
27 | * @var UserServiceOptionsInterface |
||
28 | */ |
||
29 | protected $options; |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | * @var ServiceManager |
||
34 | */ |
||
35 | protected $serviceLocator; |
||
36 | |||
37 | public function __construct(ServiceLocatorInterface $locator) |
||
38 | { |
||
39 | $this->serviceLocator = $locator; |
||
0 ignored issues
–
show
|
|||
40 | } |
||
41 | |||
42 | /** |
||
43 | * |
||
44 | * This service is ready for all types of games |
||
45 | * |
||
46 | * @param array $data |
||
47 | * @param string $formClass |
||
48 | * @return \PlaygroundGame\Entity\Game |
||
49 | */ |
||
50 | public function create(array $data, $prize, $formClass) |
||
51 | { |
||
52 | $form = $this->serviceLocator->get($formClass); |
||
53 | $form->bind($prize); |
||
54 | |||
55 | // If the identifier has not been set, I use the title to create one. |
||
56 | View Code Duplication | if (empty($data['identifier']) && !empty($data['title'])) { |
|
0 ignored issues
–
show
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. ![]() |
|||
57 | $data['identifier'] = $data['title']; |
||
58 | } |
||
59 | |||
60 | $form->setData($data); |
||
61 | |||
62 | if (!$form->isValid()) { |
||
63 | return false; |
||
0 ignored issues
–
show
The return type of
return false; (false ) is incompatible with the return type documented by PlaygroundGame\Service\Prize::create of type PlaygroundGame\Entity\Game .
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 ![]() |
|||
64 | } |
||
65 | |||
66 | $prize = $this->getPrizeMapper()->insert($prize); |
||
67 | |||
68 | return $prize; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * @param array $data |
||
74 | * @param string $formClass |
||
75 | * @return \PlaygroundGame\Entity\Game |
||
76 | */ |
||
77 | public function edit(array $data, $prize, $formClass) |
||
78 | { |
||
79 | $entityManager = $this->serviceLocator->get('doctrine.entitymanager.orm_default'); |
||
80 | $form = $this->serviceLocator->get($formClass); |
||
81 | $form->bind($prize); |
||
82 | |||
83 | $identifierInput = $form->getInputFilter()->get('identifier'); |
||
84 | $noObjectExistsValidator = new NoObjectExistsValidator(array( |
||
85 | 'object_repository' => $entityManager->getRepository('PlaygroundGame\Entity\Prize'), |
||
86 | 'fields' => 'identifier', |
||
87 | 'messages' => array('objectFound' => 'This url already exists !') |
||
88 | )); |
||
89 | |||
90 | if ($prize->getIdentifier() != $data['identifier']) { |
||
91 | $identifierInput->getValidatorChain()->addValidator($noObjectExistsValidator); |
||
92 | } |
||
93 | |||
94 | $form->setData($data); |
||
95 | |||
96 | if (!$form->isValid()) { |
||
97 | return false; |
||
0 ignored issues
–
show
The return type of
return false; (false ) is incompatible with the return type documented by PlaygroundGame\Service\Prize::edit of type PlaygroundGame\Entity\Game .
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 ![]() |
|||
98 | } |
||
99 | |||
100 | $prize = $this->getPrizeMapper()->update($prize); |
||
101 | |||
102 | return $prize; |
||
103 | } |
||
104 | |||
105 | |||
106 | /** |
||
107 | * getPrizeMapper |
||
108 | * |
||
109 | * @return PrizeMapper |
||
110 | */ |
||
111 | View Code Duplication | public function getPrizeMapper() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
112 | { |
||
113 | if (null === $this->prizeMapper) { |
||
114 | $this->prizeMapper = $this->serviceLocator->get('playgroundgame_prize_mapper'); |
||
115 | } |
||
116 | |||
117 | return $this->prizeMapper; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * setPrizeMapper |
||
122 | * |
||
123 | * @param PrizeMapper $prizeMapper |
||
124 | * @return Prize |
||
125 | */ |
||
126 | public function setPrizeMapper(PrizeMapper $prizeMapper) |
||
127 | { |
||
128 | $this->prizeMapper = $prizeMapper; |
||
0 ignored issues
–
show
It seems like
$prizeMapper of type object<PlaygroundGame\Mapper\Prize> is incompatible with the declared type object<PlaygroundGame\Service\prizeMapper> of property $prizeMapper .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
129 | |||
130 | return $this; |
||
131 | } |
||
132 | |||
133 | public function setOptions(ModuleOptions $options) |
||
134 | { |
||
135 | $this->options = $options; |
||
0 ignored issues
–
show
It seems like
$options of type object<PlaygroundGame\Options\ModuleOptions> is incompatible with the declared type object<PlaygroundGame\Se...erviceOptionsInterface> of property $options .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
136 | |||
137 | return $this; |
||
138 | } |
||
139 | |||
140 | public function getOptions() |
||
141 | { |
||
142 | if (!$this->options instanceof ModuleOptions) { |
||
143 | $this->setOptions($this->serviceLocator->get('playgroundgame_module_options')); |
||
144 | } |
||
145 | |||
146 | return $this->options; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Retrieve service manager instance |
||
151 | * |
||
152 | * @return ServiceManager |
||
153 | */ |
||
154 | public function getServiceManager() |
||
155 | { |
||
156 | return $this->serviceManager; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Set service manager instance |
||
161 | * |
||
162 | * @param ServiceManager $serviceManager |
||
163 | * @return Prize |
||
164 | */ |
||
165 | public function setServiceManager(ServiceManager $serviceManager) |
||
166 | { |
||
167 | $this->serviceManager = $serviceManager; |
||
168 | |||
169 | return $this; |
||
170 | } |
||
171 | } |
||
172 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.