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 Spatie\ValidationRules\Rules; |
||
4 | |||
5 | use Illuminate\Support\Str; |
||
6 | use Illuminate\Contracts\Validation\Rule; |
||
7 | use Illuminate\Support\Facades\Validator; |
||
8 | |||
9 | class CommaSeparatedEmails implements Rule |
||
10 | { |
||
11 | /** @var int|null */ |
||
12 | protected $minimum; |
||
13 | |||
14 | /** @var int|null */ |
||
15 | protected $maximum; |
||
16 | |||
17 | protected $message = ''; |
||
18 | |||
19 | 24 | public function passes($attribute, $value) |
|
20 | { |
||
21 | 24 | [$validEmails, $invalidEmails] = collect(explode(',', $value)) |
|
0 ignored issues
–
show
The variable
$invalidEmails does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.
Loading history...
|
|||
22 | ->map(function (string $rawEmail) { |
||
23 | 24 | return trim($rawEmail); |
|
24 | 24 | }) |
|
25 | ->partition(function (string $email) { |
||
26 | 24 | return $this->isValidEmail($email); |
|
27 | 24 | }); |
|
28 | |||
29 | 24 | if ($invalidEmails->count() === 1) { |
|
30 | 6 | $this->message = __('validation.email', ['attribute' => $invalidEmails->first()]); |
|
0 ignored issues
–
show
It seems like
__('validation.email', a...nvalidEmails->first())) can also be of type array . However, the property $message is declared as type string . Maybe add an additional type check?
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 mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
31 | |||
32 | 6 | return false; |
|
33 | } |
||
34 | |||
35 | 24 | if ($invalidEmails->count() > 1) { |
|
36 | $this->message = __('validation.emails', ['attribute' => $invalidEmails->implode(',')]); |
||
0 ignored issues
–
show
It seems like
__('validation.emails', ...dEmails->implode(','))) can also be of type array . However, the property $message is declared as type string . Maybe add an additional type check?
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 mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
37 | |||
38 | return false; |
||
39 | } |
||
40 | |||
41 | 24 | if ($validEmails->unique()->count() !== $validEmails->count()) { |
|
42 | 6 | $this->message = __('validation.unique_emails'); |
|
0 ignored issues
–
show
It seems like
__('validation.unique_emails') can also be of type array . However, the property $message is declared as type string . Maybe add an additional type check?
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 mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
43 | 6 | ||
44 | return false; |
||
45 | } |
||
46 | |||
47 | if (! is_null($this->minimum)) { |
||
48 | 18 | if ($validEmails->count() < $this->minimum) { |
|
49 | 6 | $this->message = __('validation.minimum_emails', [ |
|
0 ignored issues
–
show
It seems like
__('validation.minimum_e...ess', $this->minimum))) can also be of type array . However, the property $message is declared as type string . Maybe add an additional type check?
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 mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
50 | 6 | 'actualCount' => $invalidEmails->implode(','), |
|
51 | 6 | 'expectedMinimum' => $this->minimum, |
|
52 | 6 | 'emailword' => Str::plural('e-mail address', $this->minimum), |
|
53 | 6 | ]); |
|
54 | |||
55 | return false; |
||
56 | 6 | } |
|
57 | } |
||
58 | |||
59 | if (! is_null($this->maximum)) { |
||
60 | 18 | if ($validEmails->count() > $this->maximum) { |
|
61 | 6 | $this->message = __('validation.maximum_emails', [ |
|
0 ignored issues
–
show
It seems like
__('validation.maximum_e...ess', $this->maximum))) can also be of type array . However, the property $message is declared as type string . Maybe add an additional type check?
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 mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
62 | 6 | 'actualCount' => $invalidEmails->implode(','), |
|
63 | 6 | 'expectedMaximum' => $this->maximum, |
|
64 | 6 | 'emailword' => Str::plural('e-mail address', $this->maximum), |
|
65 | 6 | ]); |
|
66 | |||
67 | return false; |
||
68 | 6 | } |
|
69 | } |
||
70 | |||
71 | return true; |
||
72 | 18 | } |
|
73 | |||
74 | public function message() |
||
75 | { |
||
76 | return $this->message; |
||
77 | } |
||
78 | |||
79 | public function min(int $minimum) |
||
80 | 6 | { |
|
81 | $this->minimum = $minimum; |
||
82 | 6 | ||
83 | return $this; |
||
84 | 6 | } |
|
85 | |||
86 | public function max(int $maximum) |
||
87 | 6 | { |
|
88 | $this->maximum = $maximum; |
||
89 | 6 | ||
90 | return $this; |
||
91 | 6 | } |
|
92 | |||
93 | protected function isValidEmail(string $email): bool |
||
94 | 24 | { |
|
95 | return Validator::make(['email' => $email], ['email' => 'email'])->passes(); |
||
96 | 24 | } |
|
97 | } |
||
98 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.