Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 20
CRAP
0.00% covered (danger)
0.00%
0 / 1
File
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 20
462
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getDependency
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSourcePath
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTargetRelativePath
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isPhpFile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addNamespace
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addClass
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addTrait
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
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
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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
 addAutoloader
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isFilesAutoloaderFile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addDiscoveredSymbol
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getContents
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace BrianHenryIE\Strauss;
4
5use BrianHenryIE\Strauss\Composer\ComposerPackage;
6
7class File
8{
9    /**
10     * The project dependency that this file belongs to.
11     */
12    protected ComposerPackage $dependency;
13
14    /**
15     * @var string The path to the file relative to the package root.
16     */
17    protected string $packageRelativePath;
18
19    /**
20     * @var string The absolute path to the file on disk.
21     */
22    protected string $sourceAbsolutePath;
23
24    /**
25     * @var string[] The autoloader types that this file is included in.
26     */
27    protected array $autoloaderTypes = [];
28
29    /**
30     * Should this file be copied to the target directory?
31     */
32    protected bool $doCopy = true;
33
34    /**
35     * Should this file be deleted from the source directory?
36     */
37    protected bool $doDelete = false;
38
39    /** @var DiscoveredSymbol[] */
40    protected array $discoveredSymbols = [];
41
42    public function __construct(ComposerPackage $dependency, string $packageRelativePath, string $sourceAbsolutePath)
43    {
44        $this->packageRelativePath = $packageRelativePath;
45        $this->dependency          = $dependency;
46        $this->sourceAbsolutePath  = $sourceAbsolutePath;
47    }
48
49    public function getDependency(): ComposerPackage
50    {
51        return $this->dependency;
52    }
53
54    public function getSourcePath(string $relativeTo = ''): string
55    {
56        return str_replace($relativeTo, '', $this->sourceAbsolutePath);
57    }
58
59    public function getTargetRelativePath(): string
60    {
61        return $this->dependency->getRelativePath() . $this->packageRelativePath;
62    }
63
64    public function isPhpFile(): bool
65    {
66        return substr($this->sourceAbsolutePath, -4) === '.php';
67    }
68
69    public function addNamespace(string $namespaceName): void
70    {
71    }
72    public function addClass(string $className): void
73    {
74    }
75    public function addTrait(string $traitName): void
76    {
77    }
78    // isTrait();
79
80    public function setDoCopy(bool $doCopy): void
81    {
82        $this->doCopy = $doCopy;
83    }
84    public function isDoCopy(): bool
85    {
86        return $this->doCopy;
87    }
88
89    public function setDoPrefix(bool $doPrefix): void
90    {
91    }
92    public function isDoPrefix(): bool
93    {
94        return true;
95    }
96
97    /**
98     * Used to mark files that are symlinked as not-to-be-deleted.
99     *
100     * @param bool $doDelete
101     *
102     * @return void
103     */
104    public function setDoDelete(bool $doDelete): void
105    {
106        $this->doDelete = $doDelete;
107    }
108
109    /**
110     * Should file be deleted?
111     *
112     * NB: Also respect the "delete_vendor_files"|"delete_vendor_packages" settings.
113     */
114    public function isDoDelete(): bool
115    {
116        return $this->doDelete;
117    }
118
119    public function setDidDelete(bool $didDelete): void
120    {
121    }
122    public function getDidDelete(): bool
123    {
124        return false;
125    }
126
127    /**
128     * Record the autoloader it is found in. Which could be all of them.
129     */
130    public function addAutoloader(string $autoloaderType): void
131    {
132        $this->autoloaderTypes = array_unique(array_merge($this->autoloaderTypes, array($autoloaderType)));
133    }
134
135    public function isFilesAutoloaderFile(): bool
136    {
137        return in_array('files', $this->autoloaderTypes, true);
138    }
139
140    public function addDiscoveredSymbol(DiscoveredSymbol $symbol): void
141    {
142        $this->discoveredSymbols[$symbol->getOriginalSymbol()] = $symbol;
143    }
144
145    public function getContents(): string
146    {
147
148        // TODO: use flysystem
149        // $contents = $this->filesystem->read($targetFile);
150
151        $contents = file_get_contents($this->sourceAbsolutePath);
152        if (false === $contents) {
153            throw new \Exception("Failed to read file at {$this->sourceAbsolutePath}");
154        }
155
156        return $contents;
157    }
158}