Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
11.11% covered (danger)
11.11%
1 / 9
16.67% covered (danger)
16.67%
1 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
FileWithDependency
11.11% covered (danger)
11.11%
1 / 9
16.67% covered (danger)
16.67%
1 / 6
31.28
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getDependency
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addAutoloader
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isFilesAutoloaderFile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVendorRelativePath
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isDoDelete
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BrianHenryIE\Strauss\Files;
4
5use BrianHenryIE\Strauss\Composer\ComposerPackage;
6
7class FileWithDependency extends File implements HasDependency
8{
9
10    /**
11     * @var string The path to the file relative to the package root.
12     */
13    protected string $vendorRelativePath;
14
15    /**
16     * The project dependency that this file belongs to.
17     */
18    protected ComposerPackage $dependency;
19
20    /**
21     * @var string[] The autoloader types that this file is included in.
22     */
23    protected array $autoloaderTypes = [];
24
25    public function __construct(ComposerPackage $dependency, string $vendorRelativePath, string $sourceAbsolutePath)
26    {
27        parent::__construct($sourceAbsolutePath);
28
29        $this->vendorRelativePath = ltrim($vendorRelativePath, '/\\');
30        $this->dependency         = $dependency;
31
32        // Set this to null so we query the package's `isDelete` setting.
33        $this->doDelete = null;
34    }
35
36    public function getDependency(): ComposerPackage
37    {
38        return $this->dependency;
39    }
40
41    /**
42     * The target path to (maybe) copy the file to, and the target path to perform replacements in (which may be the
43     * original path).
44     */
45
46    /**
47     * Record the autoloader it is found in. Which could be all of them.
48     */
49    public function addAutoloader(string $autoloaderType): void
50    {
51        $this->autoloaderTypes = array_unique(array_merge($this->autoloaderTypes, array($autoloaderType)));
52    }
53
54    public function isFilesAutoloaderFile(): bool
55    {
56        return in_array('files', $this->autoloaderTypes, true);
57    }
58
59    public function getVendorRelativePath(): string
60    {
61        return $this->vendorRelativePath;
62    }
63
64    public function isDoDelete(): bool
65    {
66        return $this->doDelete ?? $this->dependency->isDoDelete();
67    }
68}