Completed
Push — master ( 8c2f21...ccb7a3 )
by Gabriel
02:31
created

Oop::basename()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Nip\Utility;
4
5
/**
6
 * Class Oop
7
 * @package Nip\Utility
8
 */
9
class Oop
10
{
11
12
    /**
13
     * @param $class
14
     * @return string
15
     */
16 1
    public static function basename($class)
17
    {
18 1
        $class = is_object($class) ? get_class($class) : $class;
19
20 1
        return basename(str_replace('\\', '/', $class));
21
    }
22
23
    /**
24
     * @param $class
25
     * @param bool $recursive
26
     * @return array
27
     */
28 1
    public static function uses($class, $recursive = true)
29
    {
30 1
        if (is_object($class)) {
31
            $class = get_class($class);
32
        }
33 1
        if (class_exists($class) && $recursive == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
34
            return class_uses($class);
35
        }
36 1
        $results = [];
37
38 1
        foreach (array_reverse(class_parents($class)) + [$class => $class] as $class) {
0 ignored issues
show
introduced by
$class is overwriting one of the parameters of this function.
Loading history...
39 1
            $results += static::traitUses($class);
40
        }
41
42 1
        return array_unique($results);
43
    }
44
45
    /**
46
     * @param $trait
47
     * @param bool $recursive
48
     * @return array
49
     */
50 1
    public static function traitUses($trait, $recursive = true)
0 ignored issues
show
Unused Code introduced by
The parameter $recursive is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

50
    public static function traitUses($trait, /** @scrutinizer ignore-unused */ $recursive = true)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52 1
        $traits = class_uses($trait);
53
54 1
        foreach ($traits as $trait) {
0 ignored issues
show
introduced by
$trait is overwriting one of the parameters of this function.
Loading history...
55 1
            $traits += static::traitUses($trait);
56
        }
57
58 1
        return $traits;
59
    }
60
61
    /**
62
     * @param $name
63
     * @return bool
64
     */
65
    public static function isTrait($name)
66
    {
67
        return trait_exists($name);
68
    }
69
}