Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
38.10% covered (danger)
38.10%
8 / 21
35.00% covered (danger)
35.00%
7 / 20
CRAP
0.00% covered (danger)
0.00%
0 / 1
File
38.10% covered (danger)
38.10%
8 / 21
35.00% covered (danger)
35.00%
7 / 20
125.62
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getSourcePath
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isPhpFile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setDoCopy
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isDoCopy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIsAutoloaded
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isAutoloaded
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setDoPrefix
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isDoPrefix
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setDoDelete
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isDoDelete
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setDidDelete
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDidDelete
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addDiscoveredSymbol
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDiscoveredSymbols
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setAbsoluteTargetPath
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAbsoluteTargetPath
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 setDidUpdate
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDidUpdate
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
1<?php
2/**
3 * A file without a dependency means the project src files and the vendor/composer autoload files.
4 */
5
6namespace BrianHenryIE\Strauss\Files;
7
8use BrianHenryIE\Strauss\Types\DiscoveredSymbol;
9
10class 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 $absoluteTargetPath;
37
38    protected bool $didDelete = false;
39
40    protected bool $doPrefix = false;
41
42    public function __construct(string $sourceAbsolutePath, string $vendorRelativePath)
43    {
44        $this->sourceAbsolutePath = $sourceAbsolutePath;
45        $this->vendorRelativePath = $vendorRelativePath;
46    }
47
48    public function getSourcePath(): string
49    {
50        return $this->sourceAbsolutePath;
51    }
52
53    public function isPhpFile(): bool
54    {
55        return substr($this->sourceAbsolutePath, -4) === '.php';
56    }
57
58    /**
59     * Some combination of file copy exclusions and vendor-dir == target-dir
60     *
61     * @param bool $doCopy
62     *
63     * @return void
64     */
65    public function setDoCopy(bool $doCopy): void
66    {
67        $this->doCopy = $doCopy;
68    }
69    public function isDoCopy(): bool
70    {
71        return $this->doCopy;
72    }
73
74    public function setIsAutoloaded(bool $isAutoloaded): void
75    {
76        $this->isAutoloaded = $isAutoloaded;
77    }
78
79    public function isAutoloaded(): bool
80    {
81        return $this->isAutoloaded;
82    }
83
84    /**
85     * Should symbols discovered in this file be prefixed. (i.e. class definitions etc., not usages)
86     */
87    public function setDoPrefix(bool $doPrefix): void
88    {
89        $this->doPrefix = $doPrefix;
90    }
91
92    /**
93     * Is this correct? Is there ever a time that NO changes should be made to a file? I.e. another file would have its
94     * namespace changed and it needs to be updated throughout.
95     *
96     * Is this really a Symbol level function?
97     */
98    public function isDoPrefix(): bool
99    {
100        return $this->doPrefix;
101    }
102
103    /**
104     * Used to mark files that are symlinked as not-to-be-deleted.
105     *
106     * @param bool $doDelete
107     */
108    public function setDoDelete(bool $doDelete): void
109    {
110        $this->doDelete = $doDelete;
111    }
112
113    /**
114     * Should file be deleted?
115     *
116     * NB: Also respect the "delete_vendor_files"|"delete_vendor_packages" settings.
117     */
118    public function isDoDelete(): bool
119    {
120        return (bool) $this->doDelete;
121    }
122
123    public function setDidDelete(bool $didDelete): void
124    {
125        $this->didDelete = $didDelete;
126    }
127
128    public function getDidDelete(): bool
129    {
130        return $this->didDelete;
131    }
132
133    public function addDiscoveredSymbol(DiscoveredSymbol $symbol): void
134    {
135        $this->discoveredSymbols[$symbol->getOriginalSymbol()] = $symbol;
136    }
137
138    /**
139     * @return array<string, DiscoveredSymbol> The discovered symbols in the file, indexed by their original string name.
140     */
141    public function getDiscoveredSymbols(): array
142    {
143        return $this->discoveredSymbols;
144    }
145
146    public function setAbsoluteTargetPath(string $absoluteTargetPath): void
147    {
148        $this->absoluteTargetPath = $absoluteTargetPath;
149    }
150
151    /**
152     * The target path to (maybe) copy the file to, and the target path to perform replacements in (which may be the
153     * original path).
154     */
155    public function getAbsoluteTargetPath(): string
156    {
157        // TODO: Maybe this is a mistake and should better be an exception.
158        return isset($this->absoluteTargetPath) ? $this->absoluteTargetPath : $this->sourceAbsolutePath;
159    }
160
161    protected bool $didUpdate = false;
162
163    public function setDidUpdate(): void
164    {
165        $this->didUpdate = true;
166    }
167
168    public function getDidUpdate(): bool
169    {
170        return $this->didUpdate;
171    }
172
173    public function getVendorRelativePath(): string
174    {
175        return $this->vendorRelativePath;
176    }
177}