Utils::getTraitsList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
3
namespace EmanueleMinotto\HwiOauthBridge;
4
5
class Utils
6
{
7
    /**
8
     * Get Traits list.
9
     *
10
     * @param string $globPattern
11
     *
12
     * @return array
13
     */
14 15
    public static function getTraitsList($globPattern = '{Document,Entity}')
15
    {
16 15
        $files = glob(__DIR__.'/Traits/'.$globPattern.'/*.php', GLOB_BRACE);
17
18
        return array_map(function ($path) {
19 15
            $class = basename($path, '.php');
20 15
            $namespace = basename(dirname($path));
21
22 15
            return 'EmanueleMinotto\HwiOauthBridge\Traits\\'.$namespace.'\\'.$class;
23 15
        }, $files);
24
    }
25
26
    /**
27
     * Get Providers List.
28
     *
29
     * @param string $type Document or Entity.
30
     *
31
     * @return array
32
     */
33 6
    public static function getProvidersList($type = 'Document')
34
    {
35 6
        $traitsList = static::getTraitsList($type);
36
37 6
        $providers = array();
38
39 6
        foreach ($traitsList as $trait) {
40 6
            $class = preg_replace_callback('/(.*\\\)([a-z0-9]+)(Trait)/i', function ($match) {
41 6
                return strtolower($match[2]);
42 6
            }, $trait);
43
44
            // special case
45 6
            if ('signals' === $class) {
46 6
                $class = sprintf('37%s', $class);
47 6
            }
48
49 6
            $providers[$trait] = $class;
50 6
        }
51
52 6
        return $providers;
53
    }
54
}
55