-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathImposter.php
More file actions
135 lines (115 loc) · 2.87 KB
/
Copy pathImposter.php
File metadata and controls
135 lines (115 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
declare(strict_types=1);
namespace TypistTech\Imposter;
class Imposter implements ImposterInterface
{
/**
* @var string[]
*/
private $autoloads;
/**
* @var string[]
*/
private $invalidAutoloads;
/**
* @var ConfigCollectionInterface
*/
private $configCollection;
/**
* @var TransformerInterface
*/
private $transformer;
/**
* @var FilesystemInterface
*/
private $filesystem;
/**
* Imposter constructor.
*
* @param ConfigCollectionInterface $configCollection
* @param TransformerInterface $transformer
* @param FilesystemInterface $filesystem
*/
public function __construct(
ConfigCollectionInterface $configCollection,
TransformerInterface $transformer,
FilesystemInterface $filesystem
) {
$this->configCollection = $configCollection;
$this->transformer = $transformer;
$this->filesystem = $filesystem;
}
/**
* @return ConfigCollectionInterface
*/
public function getConfigCollection(): ConfigCollectionInterface
{
return $this->configCollection;
}
/**
* @return TransformerInterface
*/
public function getTransformer(): TransformerInterface
{
return $this->transformer;
}
/**
* Transform all autoload files.
*
* @return void
*/
public function run()
{
$autoloads = $this->getAutoloads();
array_walk($autoloads, [$this, 'transform']);
}
/**
* Get all valid (exist) autoload paths.
*
* @return string[]
*/
public function getAutoloads(): array
{
if ($this->autoloads === null) {
$this->setAutoloads();
}
return $this->autoloads;
}
/**
* Get all autoload paths which defined in composer.json but not exist.
*
* @return string[]
*/
public function getInvalidAutoloads(): array
{
if ($this->invalidAutoloads === null) {
$this->setAutoloads();
}
return $this->invalidAutoloads;
}
protected function setAutoloads(): void
{
$this->autoloads = [];
$this->invalidAutoloads = [];
$autoloads = $this->configCollection->getAutoloads();
foreach ($autoloads as $autoload) {
$isValid = $this->filesystem->isFile($autoload) || $this->filesystem->isDir($autoload);
if ($isValid) {
$this->autoloads[] = $autoload;
} else {
$this->invalidAutoloads[] = $autoload;
}
}
}
/**
* Transform a file or directory recursively.
*
* @param string $target Path to the target file or directory.
*
* @return void
*/
public function transform(string $target)
{
$this->transformer->transform($target);
}
}