| Conditions | 2 |
| Paths | 2 |
| Total Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 35 | public function authorizePermissionResource(string $resource, array $options = []) |
||
| 36 | { |
||
| 37 | $permissions = $this->resourcePermissionMap(); |
||
| 38 | $collection = new Collection; |
||
| 39 | foreach ($permissions as $method => $ability) { |
||
| 40 | $collection->push(new Fluent([ |
||
| 41 | 'ability' => $ability, |
||
| 42 | 'method' => $method, |
||
| 43 | ])); |
||
| 44 | } |
||
| 45 | |||
| 46 | $collection->groupBy('ability')->each(function ($permission, $ability) use ($resource, $options) { |
||
| 47 | $this->middleware("can:{$resource}.{$ability}") |
||
|
|
|||
| 48 | ->only($permission->pluck('method')->toArray()); |
||
| 49 | }); |
||
| 50 | } |
||
| 51 | |||
| 66 |
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
Idableprovides a methodequalsIdthat 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.