Completed
Push — master ( 78679a...aac6ad )
by Freek
11s
created

Composer::getAutoloadedFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\EventProjector;
4
5
use Illuminate\Support\Str;
6
7
final class Composer
8
{
9
    public static function getAutoloadedFiles($composerJsonPath): array
10
    {
11
        if (! file_exists($composerJsonPath)) {
12
            return [];
13
        }
14
15
        $basePath = Str::before($composerJsonPath, 'composer.json');
16
17
        $composerContents = json_decode(file_get_contents($composerJsonPath), true);
18
19
        $paths = array_merge(
20
            $composerContents['autoload']['files'] ?? [],
21
            $composerContents['autoload-dev']['files'] ?? []
22
        );
23
24
        return array_map(function (string $path) use ($basePath) {
25
            return realpath($basePath.$path);
26
        }, $paths);
27
    }
28
}
29