Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
2 / 4
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DiscoveredFiles
50.00% covered (danger)
50.00%
2 / 4
50.00% covered (danger)
50.00%
2 / 4
6.00
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
 getFile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 sort
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BrianHenryIE\Strauss\Files;
4
5class DiscoveredFiles
6{
7    /** @var array<string,FileBase|File|FileWithDependency> */
8    protected array $files = [];
9
10    public function add(FileBase $file): void
11    {
12        $this->files[$file->getSourcePath()] = $file;
13    }
14
15    /**
16     * @return array<string,FileBase|File|FileWithDependency>
17     */
18    public function getFiles(): array
19    {
20        return $this->files;
21    }
22
23    /**
24     * Fetch/check if a file exists in the discovered files.
25     *
26     * @param string $sourceAbsolutePath Full path to the file.
27     */
28    public function getFile(string $sourceAbsolutePath): ?FileBase
29    {
30        return $this->files[$sourceAbsolutePath] ?? null;
31    }
32
33    public function sort(): void
34    {
35        ksort($this->files);
36    }
37}