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