| Total Complexity | 8 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class Guard |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * return collection of (guard_name) property if exist on class or object |
||
| 15 | * otherwise will return collection of guards names that exists in config/auth.php. |
||
| 16 | * |
||
| 17 | * @param $model |
||
| 18 | * |
||
| 19 | * @return Collection |
||
| 20 | * @throws \ReflectionException |
||
| 21 | */ |
||
| 22 | 123 | public function getNames($model) : Collection |
|
| 23 | { |
||
| 24 | 123 | $guardName = null; |
|
| 25 | 98 | $class = null; |
|
| 26 | |||
| 27 | if (\is_object($model)) { |
||
| 28 | 123 | $guardName = $model->guard_name ?? null; |
|
| 29 | 123 | } |
|
| 30 | 123 | ||
| 31 | if ($guardName === null) { |
||
| 32 | $class = \is_object($model) ? \get_class($model) : $model; |
||
| 33 | 123 | $guardName = (new \ReflectionClass($class))->getDefaultProperties()['guard_name'] ?? null; |
|
| 34 | 35 | } |
|
| 35 | |||
| 36 | 123 | if ($guardName) { |
|
| 37 | 123 | return collect($guardName); |
|
| 38 | 123 | } |
|
| 39 | 1 | ||
| 40 | return collect(config('auth.guards')) |
||
| 41 | 123 | ->map(function ($guard) { |
|
| 42 | 123 | if (! isset($guard['provider'])) { |
|
| 43 | 123 | return; |
|
| 44 | 123 | } |
|
| 45 | 123 | return config("auth.providers.{$guard['provider']}.model"); |
|
| 46 | 123 | }) |
|
| 47 | ->filter(function ($model) use ($class) { |
||
| 48 | return $class === $model; |
||
| 49 | }) |
||
| 50 | ->keys(); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Return Default Guard name |
||
| 55 | * |
||
| 56 | * @param $class |
||
| 57 | 123 | * |
|
| 58 | * @return string |
||
| 59 | 123 | * @throws \ReflectionException |
|
| 60 | 123 | */ |
|
| 61 | public function getDefaultName($class): string |
||
| 65 | } |
||
| 66 | } |
||
| 67 |