1 | <?php |
||
13 | trait ValidatesInput |
||
14 | { |
||
15 | /** |
||
16 | * @author Andrea Marco Sartori |
||
17 | * @var Illuminate\Validation\Validator $validator Input validator. |
||
18 | */ |
||
19 | protected $validator; |
||
20 | |||
21 | /** |
||
22 | * Execute the console command. |
||
23 | * |
||
24 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
25 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
26 | * @return mixed |
||
27 | */ |
||
28 | protected function execute(InputInterface $input, OutputInterface $output) |
||
36 | |||
37 | /** |
||
38 | * Retrieve the input validator. |
||
39 | * |
||
40 | * @author Andrea Marco Sartori |
||
41 | * @return Illuminate\Validation\Validator |
||
42 | */ |
||
43 | protected function validator() |
||
49 | |||
50 | /** |
||
51 | * Format console command input for validation. |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | protected function getValidationArray() |
||
63 | |||
64 | /** |
||
65 | * Retrieve and format the validation errors. |
||
66 | * |
||
67 | * @author Andrea Marco Sartori |
||
68 | * @return string |
||
69 | */ |
||
70 | protected function getFormattedErrors() |
||
76 | |||
77 | /** |
||
78 | * Retrieve the validation rules. |
||
79 | * |
||
80 | * @author Andrea Marco Sartori |
||
81 | * @return array |
||
82 | */ |
||
83 | abstract protected function rules(); |
||
84 | |||
85 | /** |
||
86 | * Retrieve the custom error messages. |
||
87 | * |
||
88 | * @author Andrea Marco Sartori |
||
89 | * @return array |
||
90 | */ |
||
91 | protected function messages() |
||
95 | |||
96 | /** |
||
97 | * Retrieve the custom attributes for error messages. |
||
98 | * |
||
99 | * @author Andrea Marco Sartori |
||
100 | * @return array |
||
101 | */ |
||
102 | protected function attributes() |
||
106 | } |
||
107 |
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.