| Conditions | 8 |
| Paths | 10 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 19 | public function passes($attribute, $value) |
||
| 20 | { |
||
| 21 | [$validEmails, $invalidEmails] = collect(explode(',', $value)) |
||
| 22 | ->map(function (string $rawEmail) { |
||
| 23 | return trim($rawEmail); |
||
| 24 | }) |
||
| 25 | ->partition(function (string $email) { |
||
| 26 | return $this->isValidEmail($email); |
||
| 27 | }); |
||
| 28 | |||
| 29 | if ($invalidEmails->count() === 1) { |
||
| 30 | $this->message = __('validation.email', ['attribute' => $invalidEmails->first()]); |
||
| 31 | |||
| 32 | return false; |
||
| 33 | } |
||
| 34 | |||
| 35 | if ($invalidEmails->count() > 1) { |
||
| 36 | $this->message = __('validation.emails', ['attribute' => $invalidEmails->implode(',')]); |
||
| 37 | |||
| 38 | return false; |
||
| 39 | } |
||
| 40 | |||
| 41 | if ($validEmails->unique()->count() !== $validEmails->count()) { |
||
| 42 | $this->message = __('validation.unique_emails'); |
||
| 43 | return false; |
||
| 44 | } |
||
| 45 | |||
| 46 | |||
| 47 | |||
| 48 | if (! is_null($this->minimum)) { |
||
| 49 | if ($validEmails->count() < $this->minimum) { |
||
| 50 | $this->message = __('validation.minimum_emails', [ |
||
| 51 | 'actualCount' => $invalidEmails->implode(','), |
||
| 52 | 'expectedMinimum' => $this->minimum, |
||
| 53 | 'emailword' => Str::plural('e-mail address', $this->minimum) |
||
| 54 | ]); |
||
| 55 | |||
| 56 | return false; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | if (! is_null($this->maximum)) { |
||
| 61 | if ($validEmails->count() > $this->maximum) { |
||
| 62 | $this->message = __('validation.maximum_emails', [ |
||
| 63 | 'actualCount' => $invalidEmails->implode(','), |
||
| 64 | 'expectedMaximum' => $this->maximum, |
||
| 65 | 'emailword' => Str::plural('e-mail address', $this->maximum) |
||
| 66 | ]); |
||
| 67 | |||
| 68 | return false; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | return true; |
||
| 73 | } |
||
| 74 | |||
| 100 |
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.