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