Conditions | 3 |
Paths | 3 |
Total Lines | 25 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 3.4326 |
Changes | 0 |
1 | <?php |
||
17 | 2 | protected function askWithValidation(string $question, string $field): string |
|
18 | { |
||
19 | // Ask the question and get the answer |
||
20 | 2 | $input = $this->ask($question); |
|
|
|||
21 | |||
22 | // Populate the model |
||
23 | 2 | $this->getEntity()->fill([ |
|
24 | 2 | $field => $input, |
|
25 | ]); |
||
26 | |||
27 | // Validate the model data |
||
28 | 2 | $validator = $this->getEntity()->getValidator(); |
|
29 | 2 | if ($validator->fails()) { |
|
30 | // Get error message for the field |
||
31 | $message = (string) $validator->errors()->first($field); |
||
32 | // Display warning message if exists |
||
33 | if (!empty($message)) { |
||
34 | $this->warn($message); |
||
35 | // Ask the question again |
||
36 | return $this->askWithValidation($question, $field); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | 2 | return (string) $input; |
|
41 | } |
||
42 | |||
50 |
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.