Protoqol /
Prequel
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Protoqol\Prequel\Http\Requests; |
||||
| 4 | |||||
| 5 | use Illuminate\Foundation\Http\FormRequest; |
||||
| 6 | use Protoqol\Prequel\Classes\Database\DatabaseTraverser; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * Class PrequelDatabaseRequest |
||||
| 10 | * |
||||
| 11 | * @property mixed database |
||||
| 12 | * @property mixed table |
||||
| 13 | * @property mixed model |
||||
| 14 | * @property mixed qualifiedName |
||||
| 15 | * @package Protoqol\Prequel\Http\Requests |
||||
| 16 | */ |
||||
| 17 | class PrequelDatabaseRequest extends FormRequest |
||||
| 18 | { |
||||
| 19 | |||||
| 20 | /** |
||||
| 21 | * Determine if the user is authorized to make this request. |
||||
| 22 | * |
||||
| 23 | * @return bool |
||||
| 24 | */ |
||||
| 25 | public function authorize() |
||||
| 26 | { |
||||
| 27 | return true; |
||||
| 28 | } |
||||
| 29 | |||||
| 30 | /** |
||||
| 31 | * Get the validation rules that apply to the request. |
||||
| 32 | * |
||||
| 33 | * @return array |
||||
| 34 | */ |
||||
| 35 | public function rules() |
||||
| 36 | { |
||||
| 37 | return [ |
||||
| 38 | 'database' => 'required|string', |
||||
| 39 | 'table' => 'required|string', |
||||
| 40 | 'qualifiedName' => 'required|string', |
||||
| 41 | ]; |
||||
| 42 | } |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * Get the validator instance for the request. |
||||
| 46 | * |
||||
| 47 | * @return \Illuminate\Contracts\Validation\Validator |
||||
| 48 | */ |
||||
| 49 | public function getValidatorInstance() |
||||
| 50 | { |
||||
| 51 | $request = $this->validationData(); |
||||
| 52 | |||||
| 53 | try { |
||||
| 54 | $request['database'] = $this->route('database'); |
||||
| 55 | $request['table'] = $this->route('table'); |
||||
| 56 | |||||
| 57 | $request['qualifiedName'] = $request['database'].'.' |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 58 | .$request['table']; |
||||
|
0 ignored issues
–
show
Are you sure
$request['table'] of type Illuminate\Routing\Route|object|string can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 59 | |||||
| 60 | $request['model'] = app(DatabaseTraverser::class) |
||||
| 61 | ->getModel($request['table']); |
||||
|
0 ignored issues
–
show
It seems like
$request['table'] can also be of type Illuminate\Routing\Route and object; however, parameter $tableName of Protoqol\Prequel\Classes...seTraverser::getModel() does only seem to accept null|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 62 | } catch (\Exception $exception) { |
||||
| 63 | return parent::getValidatorInstance(); |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | $this->getInputSource()->replace($request); |
||||
| 67 | return parent::getValidatorInstance(); |
||||
| 68 | } |
||||
| 69 | |||||
| 70 | /** |
||||
| 71 | * Get the error messages for the defined validation rules. |
||||
| 72 | * |
||||
| 73 | * @return array |
||||
| 74 | */ |
||||
| 75 | public function messages() |
||||
| 76 | { |
||||
| 77 | return [ |
||||
| 78 | 'database.required' => 'Database name is required', |
||||
| 79 | 'table.required' => 'Table name is required', |
||||
| 80 | 'qualifiedName.required' => 'Could not construct sensible table name.', |
||||
| 81 | ]; |
||||
| 82 | } |
||||
| 83 | } |
||||
| 84 |