Completed
Push — master ( 867c5a...b7baf0 )
by ARCANEDEV
14:52
created

Policy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 27
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0
wmc 2
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A policies() 0 15 2
1
<?php namespace Arcanedev\Support\Bases;
2
3
use Arcanedev\Support\Exceptions\MissingPolicyException;
4
use Illuminate\Support\Str;
5
6
/**
7
 * Class     Policy
8
 *
9
 * @package  Arcanedev\Support\Bases
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
abstract class Policy
13
{
14
    /* -----------------------------------------------------------------
15
     |  Main Methods
16
     | -----------------------------------------------------------------
17
     */
18
    /**
19
     * Get the policies.
20
     *
21
     * @return array
22
     */
23
    public static function policies()
24
    {
25
        $values = array_values(
26
            (new \ReflectionClass($instance = new static))->getConstants()
27
        );
28
29
        return array_map(function ($constant) use ($instance) {
30
            $method = Str::camel(last(explode('.', $constant)).'Policy');
31
32
            if ( ! method_exists($instance, $method))
33
                throw new MissingPolicyException("Missing policy [$method] method in ".get_class($instance).".");
34
35
            return $method;
36
        }, array_combine($values, $values));
37
    }
38
}
39