Conditions | 3 |
Paths | 3 |
Total Lines | 25 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
20 | protected function askWithValidation(string $question, string $field): string |
||
21 | { |
||
22 | // Ask the question and get the answer |
||
23 | $input = $this->ask($question); |
||
|
|||
24 | |||
25 | // Populate the model |
||
26 | $this->getEntity()->fill([ |
||
27 | $field => $input, |
||
28 | ]); |
||
29 | |||
30 | // Validate the model data |
||
31 | $validator = $this->getEntity()->getValidator(); |
||
32 | if ($validator->fails()) { |
||
33 | // Get error message for the field |
||
34 | $message = (string)$validator->errors()->first($field); |
||
35 | // Display warning message if exists |
||
36 | if (!empty($message)) { |
||
37 | $this->warn($message); |
||
38 | // Ask the question again |
||
39 | return $this->askWithValidation($question, $field); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | return (string)$input; |
||
44 | } |
||
45 | |||
53 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.