Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
8.33% covered (danger)
8.33%
1 / 12
16.67% covered (danger)
16.67%
1 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
FileWithDependency
8.33% covered (danger)
8.33%
1 / 12
16.67% covered (danger)
16.67%
1 / 6
33.73
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 7
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
 getPackageRelativePath
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    protected string $packageRelativePath;
16
17    /**
18     * The project dependency that this file belongs to.
19     */
20    protected ComposerPackage $dependency;
21
22    /**
23     * @var string[] The autoloader types that this file is included in.
24     */
25    protected array $autoloaderTypes = [];
26
27    public function __construct(ComposerPackage $dependency, string $vendorRelativePath, string $sourceAbsolutePath)
28    {
29        parent::__construct($sourceAbsolutePath, $vendorRelativePath);
30
31        /** @var string $packageAbsolutePath */
32        $packageAbsolutePath = $dependency->getPackageAbsolutePath();
33
34        $this->vendorRelativePath = ltrim($vendorRelativePath, '/\\');
35        $this->packageRelativePath = str_replace($packageAbsolutePath, '', $sourceAbsolutePath);
36
37        $this->dependency         = $dependency;
38
39        // Set this to null so we query the package's `isDelete` setting.
40        $this->doDelete = null;
41
42        $this->dependency->addFile($this);
43    }
44
45    public function getDependency(): ComposerPackage
46    {
47        return $this->dependency;
48    }
49
50    /**
51     * The target path to (maybe) copy the file to, and the target path to perform replacements in (which may be the
52     * original path).
53     */
54
55    /**
56     * Record the autoloader it is found in. Which could be all of them.
57     */
58    public function addAutoloader(string $autoloaderType): void
59    {
60        $this->autoloaderTypes = array_unique(array_merge($this->autoloaderTypes, array($autoloaderType)));
61    }
62
63    public function isFilesAutoloaderFile(): bool
64    {
65        return in_array('files', $this->autoloaderTypes, true);
66    }
67
68    public function getPackageRelativePath(): string
69    {
70        return $this->packageRelativePath;
71    }
72
73    public function isDoDelete(): bool
74    {
75        return $this->doDelete ?? $this->dependency->isDoDelete();
76    }
77}