Issues (41)

src/Oop.php (4 issues)

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
     * @return string
14
     */
15 1
    public static function basename($class)
16
    {
17 1
        $class = is_object($class) ? get_class($class) : $class;
18
19 1
        return basename(str_replace('\\', '/', $class));
20
    }
21
22
    public static function classUsesTrait($class, $trait): bool
23
    {
24
        $traits = static::uses($class);
25
        return isset($traits[$trait]);
26
    }
27 1
28
    /**
29 1
     * @param $class
30
     * @param bool $recursive
31
     * @return array
32 1
     */
33
    public static function uses($class, $recursive = true)
34
    {
35 1
        if (is_object($class)) {
36
            $class = get_class($class);
37 1
        }
38 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...
39
            return class_uses($class);
40
        }
41 1
        $results = [];
42
43
        foreach (array_reverse(class_parents($class)) + [$class => $class] as $class) {
0 ignored issues
show
$class is overwriting one of the parameters of this function.
Loading history...
44
            $results += static::traitUses($class);
45
        }
46
47
        return array_unique($results);
48
    }
49 1
50
    /**
51 1
     * @param $trait
52
     * @param bool $recursive
53 1
     * @return array
54 1
     */
55
    public static function traitUses($trait, $recursive = true)
0 ignored issues
show
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

55
    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...
56
    {
57 1
        $traits = class_uses($trait);
58
59
        foreach ($traits as $trait) {
0 ignored issues
show
$trait is overwriting one of the parameters of this function.
Loading history...
60
            $traits += static::traitUses($trait);
61
        }
62
63
        return $traits;
64
    }
65
66
    /**
67
     * @param $name
68
     * @return bool
69
     */
70
    public static function isTrait($name)
71
    {
72
        return trait_exists($name);
73
    }
74
}
75