Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
41.18% |
7 / 17 |
|
41.18% |
7 / 17 |
CRAP | |
0.00% |
0 / 1 |
| File | |
41.18% |
7 / 17 |
|
41.18% |
7 / 17 |
83.95 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
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 | |||
| 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 | |||
| setAbsoluteTargetPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAbsoluteTargetPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| setDidUpdate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDidUpdate | |
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 | /** |
| 18 | * Should this file be copied to the target directory? |
| 19 | */ |
| 20 | protected bool $doCopy = true; |
| 21 | |
| 22 | /** |
| 23 | * Should this file be deleted from the source directory? |
| 24 | * |
| 25 | * `null` means defer to the package's `isDelete` setting. |
| 26 | */ |
| 27 | protected ?bool $doDelete = false; |
| 28 | |
| 29 | /** @var DiscoveredSymbol[] */ |
| 30 | protected array $discoveredSymbols = []; |
| 31 | |
| 32 | protected string $absoluteTargetPath; |
| 33 | |
| 34 | protected bool $didDelete = false; |
| 35 | |
| 36 | protected bool $doPrefix = true; |
| 37 | |
| 38 | public function __construct(string $sourceAbsolutePath) |
| 39 | { |
| 40 | $this->sourceAbsolutePath = $sourceAbsolutePath; |
| 41 | } |
| 42 | |
| 43 | public function getSourcePath(): string |
| 44 | { |
| 45 | return $this->sourceAbsolutePath; |
| 46 | } |
| 47 | |
| 48 | public function isPhpFile(): bool |
| 49 | { |
| 50 | return substr($this->sourceAbsolutePath, -4) === '.php'; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Some combination of file copy exclusions and vendor-dir == target-dir |
| 55 | * |
| 56 | * @param bool $doCopy |
| 57 | * |
| 58 | * @return void |
| 59 | */ |
| 60 | public function setDoCopy(bool $doCopy): void |
| 61 | { |
| 62 | $this->doCopy = $doCopy; |
| 63 | } |
| 64 | public function isDoCopy(): bool |
| 65 | { |
| 66 | return $this->doCopy; |
| 67 | } |
| 68 | |
| 69 | public function setDoPrefix(bool $doPrefix): void |
| 70 | { |
| 71 | $this->doPrefix = $doPrefix; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Is this correct? Is there ever a time that NO changes should be made to a file? I.e. another file would have its |
| 76 | * namespace changed and it needs to be updated throughout. |
| 77 | * |
| 78 | * Is this really a Symbol level function? |
| 79 | */ |
| 80 | public function isDoPrefix(): bool |
| 81 | { |
| 82 | return $this->doPrefix; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Used to mark files that are symlinked as not-to-be-deleted. |
| 87 | * |
| 88 | * @param bool $doDelete |
| 89 | */ |
| 90 | public function setDoDelete(bool $doDelete): void |
| 91 | { |
| 92 | $this->doDelete = $doDelete; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Should file be deleted? |
| 97 | * |
| 98 | * NB: Also respect the "delete_vendor_files"|"delete_vendor_packages" settings. |
| 99 | */ |
| 100 | public function isDoDelete(): bool |
| 101 | { |
| 102 | return $this->doDelete; |
| 103 | } |
| 104 | |
| 105 | public function setDidDelete(bool $didDelete): void |
| 106 | { |
| 107 | $this->didDelete = $didDelete; |
| 108 | } |
| 109 | public function getDidDelete(): bool |
| 110 | { |
| 111 | return $this->didDelete; |
| 112 | } |
| 113 | |
| 114 | public function addDiscoveredSymbol(DiscoveredSymbol $symbol): void |
| 115 | { |
| 116 | $this->discoveredSymbols[$symbol->getOriginalSymbol()] = $symbol; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @return array<string, DiscoveredSymbol> The discovered symbols in the file, indexed by their original string name. |
| 121 | */ |
| 122 | public function getDiscoveredSymbols(): array |
| 123 | { |
| 124 | return $this->discoveredSymbols; |
| 125 | } |
| 126 | |
| 127 | public function setAbsoluteTargetPath(string $absoluteTargetPath): void |
| 128 | { |
| 129 | $this->absoluteTargetPath = $absoluteTargetPath; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * The target path to (maybe) copy the file to, and the target path to perform replacements in (which may be the |
| 134 | * original path). |
| 135 | */ |
| 136 | public function getAbsoluteTargetPath(): string |
| 137 | { |
| 138 | // TODO: Maybe this is a mistake and should better be an exception. |
| 139 | return isset($this->absoluteTargetPath) ? $this->absoluteTargetPath : $this->sourceAbsolutePath; |
| 140 | } |
| 141 | |
| 142 | protected bool $didUpdate = false; |
| 143 | public function setDidUpdate(): void |
| 144 | { |
| 145 | $this->didUpdate = true; |
| 146 | } |
| 147 | public function getDidUpdate(): bool |
| 148 | { |
| 149 | return $this->didUpdate; |
| 150 | } |
| 151 | } |