Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
36.36% |
8 / 22 |
|
30.00% |
6 / 20 |
CRAP | |
0.00% |
0 / 1 |
| File | |
36.36% |
8 / 22 |
|
30.00% |
6 / 20 |
123.08 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getSourcePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isPhpFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDoCopy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isDoCopy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setIsAutoloaded | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isAutoloaded | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDoPrefix | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isDoPrefix | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDoDelete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isDoDelete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDidDelete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDidDelete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addDiscoveredSymbol | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDiscoveredSymbols | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setTargetAbsolutePath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTargetAbsolutePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDidUpdate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDidUpdate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getVendorRelativePath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * A file without a dependency means the project src files and the vendor/composer autoload files. |
| 4 | */ |
| 5 | |
| 6 | namespace BrianHenryIE\Strauss\Files; |
| 7 | |
| 8 | use BrianHenryIE\Strauss\Types\DiscoveredSymbol; |
| 9 | |
| 10 | class File implements FileBase |
| 11 | { |
| 12 | /** |
| 13 | * @var string The absolute path to the file on disk. |
| 14 | */ |
| 15 | protected string $sourceAbsolutePath; |
| 16 | |
| 17 | protected string $vendorRelativePath; |
| 18 | |
| 19 | /** |
| 20 | * Should this file be copied to the target directory? |
| 21 | */ |
| 22 | protected bool $doCopy = true; |
| 23 | |
| 24 | protected bool $isAutoloaded = false; |
| 25 | |
| 26 | /** |
| 27 | * Should this file be deleted from the source directory? |
| 28 | * |
| 29 | * `null` means defer to the package's `isDelete` setting. |
| 30 | */ |
| 31 | protected ?bool $doDelete = false; |
| 32 | |
| 33 | /** @var DiscoveredSymbol[] */ |
| 34 | protected array $discoveredSymbols = []; |
| 35 | |
| 36 | protected string $targetAbsolutePath; |
| 37 | |
| 38 | protected bool $didDelete = false; |
| 39 | |
| 40 | protected bool $doPrefix = false; |
| 41 | |
| 42 | public function __construct( |
| 43 | string $sourceAbsolutePath, |
| 44 | string $vendorRelativePath, |
| 45 | string $targetAbsolutePath |
| 46 | ) { |
| 47 | $this->sourceAbsolutePath = $sourceAbsolutePath; |
| 48 | $this->vendorRelativePath = $vendorRelativePath; |
| 49 | $this->targetAbsolutePath = $targetAbsolutePath; |
| 50 | } |
| 51 | |
| 52 | public function getSourcePath(): string |
| 53 | { |
| 54 | return $this->sourceAbsolutePath; |
| 55 | } |
| 56 | |
| 57 | public function isPhpFile(): bool |
| 58 | { |
| 59 | return substr($this->sourceAbsolutePath, -4) === '.php'; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Some combination of file copy exclusions and vendor-dir == target-dir |
| 64 | * |
| 65 | * @param bool $doCopy |
| 66 | * |
| 67 | * @return void |
| 68 | */ |
| 69 | public function setDoCopy(bool $doCopy): void |
| 70 | { |
| 71 | $this->doCopy = $doCopy; |
| 72 | } |
| 73 | public function isDoCopy(): bool |
| 74 | { |
| 75 | return $this->doCopy; |
| 76 | } |
| 77 | |
| 78 | public function setIsAutoloaded(bool $isAutoloaded): void |
| 79 | { |
| 80 | $this->isAutoloaded = $isAutoloaded; |
| 81 | } |
| 82 | |
| 83 | public function isAutoloaded(): bool |
| 84 | { |
| 85 | return $this->isAutoloaded; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Should symbols discovered in this file be prefixed. (i.e. class definitions etc., not usages) |
| 90 | */ |
| 91 | public function setDoPrefix(bool $doPrefix): void |
| 92 | { |
| 93 | $this->doPrefix = $doPrefix; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Is this correct? Is there ever a time that NO changes should be made to a file? I.e. another file would have its |
| 98 | * namespace changed and it needs to be updated throughout. |
| 99 | * |
| 100 | * Is this really a Symbol level function? |
| 101 | */ |
| 102 | public function isDoPrefix(): bool |
| 103 | { |
| 104 | return $this->doPrefix; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * For marking moved files to be deleted when delete_vendor_files is enabled. (should that be deprecated?) |
| 109 | * For marking files that are symlinked as not-to-be-deleted. |
| 110 | * |
| 111 | * @param bool $doDelete |
| 112 | */ |
| 113 | public function setDoDelete(bool $doDelete): void |
| 114 | { |
| 115 | $this->doDelete = $doDelete; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Should file be deleted? |
| 120 | * |
| 121 | * NB: Also respect the "delete_vendor_files"|"delete_vendor_packages" settings. |
| 122 | */ |
| 123 | public function isDoDelete(): bool |
| 124 | { |
| 125 | return (bool) $this->doDelete; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @see Cleanup::doIsDeleteVendorFiles() |
| 130 | */ |
| 131 | public function setDidDelete(bool $didDelete): void |
| 132 | { |
| 133 | $this->didDelete = $didDelete; |
| 134 | } |
| 135 | |
| 136 | public function getDidDelete(): bool |
| 137 | { |
| 138 | return $this->didDelete; |
| 139 | } |
| 140 | |
| 141 | public function addDiscoveredSymbol(DiscoveredSymbol $symbol): void |
| 142 | { |
| 143 | $this->discoveredSymbols[$symbol->getOriginalSymbol()] = $symbol; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @return array<string, DiscoveredSymbol> The discovered symbols in the file, indexed by their original string name. |
| 148 | */ |
| 149 | public function getDiscoveredSymbols(): array |
| 150 | { |
| 151 | return $this->discoveredSymbols; |
| 152 | } |
| 153 | |
| 154 | public function setTargetAbsolutePath(string $targetAbsolutePath): void |
| 155 | { |
| 156 | $this->targetAbsolutePath = $targetAbsolutePath; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * The target path to (maybe) copy the file to, and the target path to perform replacements in (which may be the |
| 161 | * original path). |
| 162 | */ |
| 163 | public function getTargetAbsolutePath(): string |
| 164 | { |
| 165 | return $this->targetAbsolutePath; |
| 166 | } |
| 167 | |
| 168 | protected bool $didUpdate = false; |
| 169 | |
| 170 | public function setDidUpdate(): void |
| 171 | { |
| 172 | $this->didUpdate = true; |
| 173 | } |
| 174 | |
| 175 | public function getDidUpdate(): bool |
| 176 | { |
| 177 | return $this->didUpdate; |
| 178 | } |
| 179 | |
| 180 | public function getVendorRelativePath(): string |
| 181 | { |
| 182 | return $this->vendorRelativePath; |
| 183 | } |
| 184 | } |