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 Germania\Coupons; |
||
3 | |||
4 | class CouponSheet extends CouponSheetAbstract implements CouponSheetInterface |
||
5 | { |
||
6 | |||
7 | /** |
||
8 | * @param string $id |
||
9 | * @return self Fluid Interface |
||
10 | */ |
||
11 | 5 | public function setId( $id ) { |
|
12 | 5 | $this->id = $id; |
|
13 | 5 | return $this; |
|
14 | } |
||
15 | |||
16 | |||
17 | /** |
||
18 | * @param int $quantity |
||
19 | * @return self Fluid Interface |
||
20 | */ |
||
21 | public function setQuantity( $quantity ) { |
||
22 | $this->quantity = $quantity; |
||
23 | return $this; |
||
24 | } |
||
25 | |||
26 | |||
27 | /** |
||
28 | * @param string $id |
||
0 ignored issues
–
show
|
|||
29 | * @return self Fluid Interface |
||
30 | */ |
||
31 | 5 | public function setSlug( $slug ) { |
|
32 | 5 | $this->slug = $slug; |
|
33 | 5 | return $this; |
|
34 | } |
||
35 | |||
36 | |||
37 | /** |
||
38 | * @param string $id |
||
0 ignored issues
–
show
There is no parameter named
$id . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
39 | * @return self Fluid Interface |
||
40 | */ |
||
41 | 5 | public function setName( $name ) { |
|
42 | 5 | $this->name = $name; |
|
43 | 5 | return $this; |
|
44 | } |
||
45 | |||
46 | |||
47 | |||
48 | |||
49 | |||
50 | /** |
||
51 | * @param DateTimeInterface $valid_from |
||
52 | * @return self Fluid Interface |
||
53 | */ |
||
54 | 10 | public function setValidFrom( \DateTimeInterface $valid_from ) { |
|
55 | 10 | $this->valid_from = $valid_from; |
|
0 ignored issues
–
show
It seems like
$valid_from of type object<DateTimeInterface> is incompatible with the declared type object<Germania\Coupons\DateTime>|null of property $valid_from .
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.. ![]() |
|||
56 | 10 | return $this; |
|
57 | } |
||
58 | |||
59 | |||
60 | /** |
||
61 | * @inheritdoc |
||
62 | * |
||
63 | * If the valid_from value is a datetime string (like "Y-m-d H:i:s"), |
||
64 | * the value will be converted to a DateTime object. |
||
65 | * |
||
66 | * @return DateTime |
||
67 | * @implements CouponSheetInterface |
||
68 | */ |
||
69 | 10 | public function getValidFrom() { |
|
70 | 10 | if ($this->valid_from and is_string($this->valid_from)): |
|
71 | 5 | $this->setValidFrom( \DateTime::createFromFormat("Y-m-d H:i:s", $this->valid_from) ); |
|
0 ignored issues
–
show
It seems like
\DateTime::createFromFor...:s', $this->valid_from) targeting DateTime::createFromFormat() can also be of type false ; however, Germania\Coupons\CouponSheet::setValidFrom() does only seem to accept object<DateTimeInterface> , did you maybe forget to handle an error condition?
![]() |
|||
72 | 1 | endif; |
|
73 | 10 | return $this->valid_from; |
|
0 ignored issues
–
show
|
|||
74 | } |
||
75 | |||
76 | |||
77 | |||
78 | /** |
||
79 | * @param DateTimeInterface $valid_until |
||
80 | * @return self Fluid Interface |
||
81 | */ |
||
82 | 10 | public function setValidUntil( \DateTimeInterface $valid_until ) { |
|
83 | 10 | $this->valid_until = $valid_until; |
|
0 ignored issues
–
show
It seems like
$valid_until of type object<DateTimeInterface> is incompatible with the declared type object<Germania\Coupons\DateTime>|null of property $valid_until .
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.. ![]() |
|||
84 | 10 | return $this; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | * |
||
90 | * If the valid_until value is a datetime string (like "Y-m-d H:i:s"), |
||
91 | * the value will be converted to a DateTime object. |
||
92 | * |
||
93 | * @return DateTime |
||
94 | * @implements CouponSheetInterface |
||
95 | */ |
||
96 | 10 | public function getValidUntil() { |
|
97 | 10 | if ($this->valid_until and is_string($this->valid_until)): |
|
98 | 5 | $this->setValidUntil( \DateTime::createFromFormat("Y-m-d H:i:s", $this->valid_until) ); |
|
0 ignored issues
–
show
It seems like
\DateTime::createFromFor...s', $this->valid_until) targeting DateTime::createFromFormat() can also be of type false ; however, Germania\Coupons\CouponSheet::setValidUntil() does only seem to accept object<DateTimeInterface> , did you maybe forget to handle an error condition?
![]() |
|||
99 | 1 | endif; |
|
100 | |||
101 | 10 | return $this->valid_until; |
|
0 ignored issues
–
show
The expression
$this->valid_until; of type null|Germania\Coupons\DateTime|string adds the type string to the return on line 101 which is incompatible with the return type declared by the interface Germania\Coupons\CouponS...nterface::getValidUntil of type Germania\Coupons\DateTime .
![]() |
|||
102 | } |
||
103 | |||
104 | |||
105 | |||
106 | /** |
||
107 | * @return CouponInterface[] |
||
108 | * @implements CouponSheetInterface |
||
109 | */ |
||
110 | 10 | public function getCoupons() { |
|
111 | 10 | if ($this->coupons and is_string( $this->coupons )) |
|
112 | 6 | $this->setCoupons( $this->coupons ); |
|
0 ignored issues
–
show
$this->coupons is of type string , but the function expects a array|object<Traversable> .
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);
![]() |
|||
113 | |||
114 | 10 | return $this->coupons; |
|
0 ignored issues
–
show
The return type of
return $this->coupons; (string ) is incompatible with the return type declared by the interface Germania\Coupons\CouponSheetInterface::getCoupons of type Germania\Coupons\CouponInterface[] .
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 ![]() |
|||
115 | } |
||
116 | |||
117 | |||
118 | /** |
||
119 | * @param array|\Traversable $coupons |
||
120 | * @return self Fluid Interface |
||
121 | */ |
||
122 | 10 | public function setCoupons( $coupons ) |
|
123 | { |
||
124 | 10 | if ($coupons instanceOf \Traversable ): |
|
125 | 5 | $coupons = iterator_to_array( $coupons, "use_keys"); |
|
126 | |||
127 | 10 | elseif (is_string( $coupons )): |
|
128 | 10 | $instances = array(); |
|
129 | 10 | foreach(explode(",", $coupons) as $raw_coupon) |
|
130 | 10 | array_push($instances, Coupon::fromArray([ |
|
131 | 10 | 'code' => $raw_coupon, |
|
132 | 8 | 'coupon_sheet' => $this |
|
133 | 2 | ])); |
|
134 | 10 | $coupons = $instances; |
|
135 | |||
136 | 6 | elseif (!is_array( $coupons )): |
|
137 | 5 | throw new \InvalidArgumentException("Array or Traversable expected"); |
|
138 | |||
139 | endif; |
||
140 | |||
141 | 10 | $this->coupons = $coupons; |
|
0 ignored issues
–
show
It seems like
$coupons of type array is incompatible with the declared type string of property $coupons .
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.. ![]() |
|||
142 | 10 | return $this; |
|
143 | } |
||
144 | |||
145 | |||
146 | } |
||
147 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.