GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e8972a...3808bd )
by Cees-Jan
42:07
created

functions.php ➔ listClassesInFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 15
loc 15
ccs 8
cts 8
cp 1
crap 2
rs 9.7666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus;
4
5
use Roave\BetterReflection\BetterReflection;
6
use Roave\BetterReflection\Reflector\ClassReflector;
7
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
8
use Roave\BetterReflection\SourceLocator\Type\AutoloadSourceLocator;
9
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
10
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
11
12
/**
13
 * get a list of all classes in the given directories.
14
 *
15
 * Based on: https://github.com/Roave/BetterReflection/blob/396a07c9d276cb9ffba581b24b2dadbb542d542e/demo/parsing-whole-directory/example2.php.
16
 *
17
 * @param string[] $directories
18
 *
19
 * @return iterable
20
 */
21 View Code Duplication
function listClassesInDirectories(string ...$directories): iterable
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23 2
    $sourceLocator = new AggregateSourceLocator([
24 2
        new DirectoriesSourceLocator(
25 2
            $directories,
0 ignored issues
show
Documentation introduced by
$directories is of type array<integer,array<integer,string>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26 2
            (new BetterReflection())->astLocator()
27
        ),
28
        // ↓ required to autoload parent classes/interface from another directory than /src (e.g. /vendor)
29 2
        new AutoloadSourceLocator((new BetterReflection())->astLocator()),
30
    ]);
31
32 2
    foreach ((new ClassReflector($sourceLocator))->getAllClasses() as $class) {
33 2
        yield $class->getName();
34
    }
35 2
}
36
37
/**
38
 * get a list of all classes in the given directory.
39
 *
40
 * @param string $directory
41
 *
42
 * @return iterable
43
 */
44
function listClassesInDirectory(string $directory): iterable
45
{
46 1
    yield from listClassesInDirectories($directory);
47 1
}
48
49
/**
50
 * get a list of all classes in the given file.
51
 *
52
 * @param string $file
53
 *
54
 * @return iterable
55
 */
56 View Code Duplication
function listClassesInFile(string $file): iterable
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
{
58 2
    $sourceLocator = new AggregateSourceLocator([
59 2
        new SingleFileSourceLocator(
60 2
            $file,
61 2
            (new BetterReflection())->astLocator()
62
        ),
63
        // ↓ required to autoload parent classes/interface from another directory (e.g. /vendor)
64 2
        new AutoloadSourceLocator((new BetterReflection())->astLocator()),
65
    ]);
66
67 2
    foreach ((new ClassReflector($sourceLocator))->getAllClasses() as $class) {
68 2
        yield $class->getName();
69
    }
70 2
}
71
72
/**
73
 * get a list of all classes in the given files.
74
 *
75
 * @param string[] $files
76
 *
77
 * @return iterable
78
 */
79
function listClassesInFiles(string ...$files): iterable
80
{
81 1
    foreach ($files as $file) {
82 1
        foreach (listClassesInFile($file) as $class) {
83 1
            yield $class;
84
        }
85
    }
86
}
87