• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / class-finder / 16724626674

04 Aug 2025 01:32PM UTC coverage: 82.262% (-12.2%) from 94.493%
16724626674

push

github

web-flow
Update php.yml

320 of 389 relevant lines covered (82.26%)

3.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/Libraries/Files/FilesFactory.php
1
<?php
2

3
namespace Daycry\ClassFinder\Libraries\Files;
4

5
use Daycry\ClassFinder\Exceptions\ClassFinderException;
6
use Daycry\ClassFinder\Libraries\BaseFactory;
7

8
class FilesFactory extends BaseFactory
9
{
10
    private ?array $filesEntriesCache = null;
11
    private ?string $phpPathCache     = null;
12

13
    /**
14
     * @return list<FilesEntry>
15
     */
16
    public function getFilesEntries(): array
17
    {
18
        if ($this->filesEntriesCache !== null) {
3✔
19
            return $this->filesEntriesCache;
3✔
20
        }
21

22
        $files = array_merge(
3✔
23
            require (ROOTPATH . 'vendor/composer/autoload_files.php'),
3✔
24
            $this->loadAutoloadConfigFiles(),
3✔
25
        );
3✔
26

27
        if (empty($files)) {
3✔
28
            return $this->filesEntriesCache = [];
×
29
        }
30

31
        // PHP path is only needed for fallback dynamic analysis
32
        $phpPath      = $this->findPHP();
3✔
33
        $filesEntries = [];
3✔
34

35
        foreach (array_values($files) as $file) {
3✔
36
            $filesEntries[] = new FilesEntry($file, $phpPath);
3✔
37
        }
38

39
        return $this->filesEntriesCache = $filesEntries;
3✔
40
    }
41

42
    /**
43
     * Locates the PHP interpreter.
44
     *
45
     * If PHP 5.4 or newer is used, the PHP_BINARY value is used.
46
     * Otherwise we attempt to find it from shell commands.
47
     *
48
     * @throws ClassFinderException
49
     *
50
     * @codeCoverageIgnore
51
     */
52
    private function findPHP(): string
53
    {
54
        if ($this->phpPathCache !== null) {
55
            return $this->phpPathCache;
56
        }
57

58
        if (defined('PHP_BINARY') && ! empty(PHP_BINARY)) {
59
            return $this->phpPathCache = PHP_BINARY;
60
        }
61

62
        $isHostWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
63
        $command       = $isHostWindows ? 'where php' : 'which php';
64

65
        exec($command, $output, $return);
66

67
        if ($return === 0 && ! empty($output[0])) {
68
            return $this->phpPathCache = $output[0];
69
        }
70

71
        throw new ClassFinderException(sprintf(
72
            'Could not locate PHP interpreter. See "%s" for details.',
73
            'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/filesCouldNotLocatePHP.md',
74
        ));
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc