| Total Complexity | 6 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php namespace Pz\LaravelDoctrine\Rest; |
||
| 11 | abstract class RestRequest extends FormRequest implements RestRequestInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Authorization gateway ability. |
||
| 15 | * Return `false` for pass auth. |
||
| 16 | * |
||
| 17 | * @return null|string |
||
| 18 | */ |
||
| 19 | abstract public function ability(); |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return $this |
||
| 23 | */ |
||
| 24 | 5 | public function http() |
|
| 25 | { |
||
| 26 | 5 | return $this; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return array |
||
| 31 | */ |
||
| 32 | 4 | public function rules() |
|
| 33 | { |
||
| 34 | 4 | return []; |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param object|string $entity |
||
| 39 | * @throws AuthorizationException |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | 5 | public function authorize($entity) |
|
| 43 | { |
||
| 44 | 5 | $this->gate()->authorize($this->ability(), $entity); |
|
| 45 | 5 | } |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @param Validator $validator |
||
| 49 | * |
||
| 50 | * @throws ValidationException |
||
| 51 | */ |
||
| 52 | 2 | protected function failedValidation(Validator $validator) |
|
| 53 | { |
||
| 54 | 2 | throw (new ValidationException($validator))->errorBag($this->errorBag); |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Laravel authorization gate. |
||
| 59 | * |
||
| 60 | * @return Gate |
||
| 61 | */ |
||
| 62 | 5 | public function gate() |
|
| 63 | { |
||
| 64 | 5 | return $this->container->make(Gate::class); |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Pass default request authorization. |
||
| 69 | * |
||
| 70 | * @return bool |
||
| 71 | */ |
||
| 72 | 5 | protected function passesAuthorization() |
|
| 75 | } |
||
| 76 | } |
||
| 77 |