SourcesPreloader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Package;
7
8
use Composer\Package\PackageInterface;
9
10
class SourcesPreloader
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Package\InfoResolver
14
     */
15
    private $infoResolver;
16
17
    /**
18
     * @var \Vaimo\ComposerPatches\Utils\FileSystemUtils
19
     */
20
    private $fileSystemUtils;
21
22
    /**
23
     * @param \Vaimo\ComposerPatches\Package\InfoResolver $infoResolver
24
     */
25
    public function __construct(
26
        \Vaimo\ComposerPatches\Package\InfoResolver $infoResolver
27
    ) {
28
        $this->infoResolver = $infoResolver;
29
30
        $this->fileSystemUtils = new \Vaimo\ComposerPatches\Utils\FileSystemUtils();
31
    }
32
33
    public function preload(PackageInterface $package)
34
    {
35
        $sourcePaths = $this->infoResolver->getAutoLoadPaths($package);
36
37
        $matchGroups = array();
38
39
        foreach ($sourcePaths as $sourcePath) {
40
            $matchGroups[] = $this->fileSystemUtils->collectPathsRecursively($sourcePath, '/.*\.php/');
41
        }
42
43
        $sourceFilePaths = array_unique(
44
            array_reduce($matchGroups, 'array_merge', array())
45
        );
46
47
        foreach ($sourceFilePaths as $filePath) {
48
            class_exists($filePath);
49
        }
50
    }
51
}
52