Completed
Push — master ( 124fdd...8c2f21 )
by Gabriel
01:32
created

Oop::isTrait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
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
     * @param $class
13
     * @param bool $recursive
14
     * @return array
15
     */
16 1
    public static function uses($class, $recursive = true)
17
    {
18 1
        if (is_object($class)) {
19
            $class = get_class($class);
20
        }
21 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...
22
            return class_uses($class);
23
        }
24 1
        $results = [];
25
26 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...
27 1
            $results += static::traitUses($class);
28
        }
29
30 1
        return array_unique($results);
31
    }
32
33
    /**
34
     * @param $trait
35
     * @param bool $recursive
36
     * @return array
37
     */
38 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

38
    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...
39
    {
40 1
        $traits = class_uses($trait);
41
42 1
        foreach ($traits as $trait) {
0 ignored issues
show
introduced by
$trait is overwriting one of the parameters of this function.
Loading history...
43 1
            $traits += static::traitUses($trait);
44
        }
45
46 1
        return $traits;
47
    }
48
49
    /**
50
     * @param $name
51
     * @return bool
52
     */
53
    public static function isTrait($name)
54
    {
55
        return trait_exists($name);
56
    }
57
}