Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
13.33% covered (danger)
13.33%
2 / 15
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DiscoveredFiles
13.33% covered (danger)
13.33%
2 / 15
50.00% covered (danger)
50.00%
2 / 4
29.43
0.00% covered (danger)
0.00%
0 / 1
 add
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFiles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAllFilesAndDependencyList
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
 getPhpFilesAndDependencyList
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BrianHenryIE\Strauss;
4
5use ArrayAccess;
6use BrianHenryIE\Strauss\Composer\ComposerPackage;
7
8class DiscoveredFiles
9{
10    /** @var array<string,File> */
11    protected array $files = [];
12
13    /**
14     * @param File $file
15     */
16    public function add(File $file): void
17    {
18        $this->files[$file->getTargetRelativePath()] = $file;
19    }
20
21    /**
22     * @return File[]
23     */
24    public function getFiles(): array
25    {
26        return $this->files;
27    }
28
29    /**
30     * Returns all found files.
31     *
32     * @return array<string,array{dependency:ComposerPackage,sourceAbsoluteFilepath:string,targetRelativeFilepath:string}>
33     */
34    public function getAllFilesAndDependencyList(): array
35    {
36        $allFiles = [];
37        foreach ($this->files as $file) {
38            if (!$file->isDoCopy()) {
39                continue;
40            }
41            $allFiles[ $file->getTargetRelativePath() ] = [
42                'dependency'             => $file->getDependency(),
43                'sourceAbsoluteFilepath' => $file->getSourcePath(),
44                'targetRelativeFilepath' => $file->getTargetRelativePath(),
45            ];
46        }
47        return $allFiles;
48    }
49
50
51    /**
52     * Returns found PHP files.
53     *
54     * @return array<string,array{dependency:ComposerPackage,sourceAbsoluteFilepath:string,targetRelativeFilepath:string}>
55     */
56    public function getPhpFilesAndDependencyList(): array
57    {
58        // Filter out non .php files by checking the key.
59        return array_filter($this->getAllFilesAndDependencyList(), function ($value, $key) {
60            return false !== strpos($key, '.php');
61        }, ARRAY_FILTER_USE_BOTH);
62    }
63}