1 | <?php |
||||
2 | |||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
3 | namespace Hhxsv5\LaravelS\Illuminate; |
||||
4 | |||||
5 | use Hhxsv5\LaravelS\Illuminate\Cleaners\BaseCleaner; |
||||
6 | use Hhxsv5\LaravelS\Illuminate\Cleaners\CleanerInterface; |
||||
7 | use Hhxsv5\LaravelS\Illuminate\Cleaners\ConfigCleaner; |
||||
8 | use Hhxsv5\LaravelS\Illuminate\Cleaners\ContainerCleaner; |
||||
9 | use Hhxsv5\LaravelS\Illuminate\Cleaners\CookieCleaner; |
||||
10 | use Hhxsv5\LaravelS\Illuminate\Cleaners\RequestCleaner; |
||||
11 | use Illuminate\Container\Container; |
||||
0 ignored issues
–
show
The type
Illuminate\Container\Container was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
12 | |||||
13 | class CleanerManager |
||||
0 ignored issues
–
show
|
|||||
14 | { |
||||
15 | /** |
||||
0 ignored issues
–
show
|
|||||
16 | * @var Container |
||||
17 | */ |
||||
18 | protected $currentApp; |
||||
19 | /** |
||||
0 ignored issues
–
show
|
|||||
20 | * @var Container |
||||
21 | */ |
||||
22 | protected $snapshotApp; |
||||
23 | |||||
24 | /**@var ReflectionApp */ |
||||
0 ignored issues
–
show
|
|||||
25 | protected $reflectionApp; |
||||
26 | |||||
27 | /** |
||||
28 | * All cleaners |
||||
29 | * @var CleanerInterface[] |
||||
0 ignored issues
–
show
|
|||||
30 | */ |
||||
31 | protected $cleaners = [ |
||||
32 | ContainerCleaner::class, |
||||
33 | ConfigCleaner::class, |
||||
34 | CookieCleaner::class, |
||||
35 | RequestCleaner::class, |
||||
36 | ]; |
||||
37 | |||||
38 | /** |
||||
39 | * Service providers to be cleaned up |
||||
40 | * @var array |
||||
0 ignored issues
–
show
|
|||||
41 | */ |
||||
42 | protected $providers = []; |
||||
43 | |||||
44 | /** |
||||
45 | * White list of controllers to be destroyed |
||||
46 | * @var array |
||||
0 ignored issues
–
show
|
|||||
47 | */ |
||||
48 | protected $whiteListControllers = []; |
||||
49 | |||||
50 | /** |
||||
0 ignored issues
–
show
|
|||||
51 | * @var array |
||||
52 | */ |
||||
53 | protected $config = []; |
||||
54 | |||||
55 | /** |
||||
56 | * CleanerManager constructor. |
||||
57 | * |
||||
58 | * @param Container $currentApp |
||||
0 ignored issues
–
show
|
|||||
59 | * @param Container $snapshotApp |
||||
0 ignored issues
–
show
|
|||||
60 | * @param array $config |
||||
0 ignored issues
–
show
|
|||||
61 | */ |
||||
62 | public function __construct(Container $currentApp, Container $snapshotApp, array $config) |
||||
63 | { |
||||
64 | $this->currentApp = $currentApp; |
||||
65 | $this->snapshotApp = $snapshotApp; |
||||
66 | $this->reflectionApp = new ReflectionApp($this->currentApp); |
||||
67 | $this->config = $config; |
||||
68 | $this->registerCleaners(isset($this->config['cleaners']) ? $this->config['cleaners'] : []); |
||||
69 | $this->registerCleanProviders(isset($config['register_providers']) ? $config['register_providers'] : []); |
||||
70 | $this->registerCleanControllerWhiteList(isset($this->config['destroy_controllers']['excluded_list']) ? $this->config['destroy_controllers']['excluded_list'] : []); |
||||
71 | } |
||||
72 | |||||
73 | /** |
||||
74 | * Register singleton cleaners to application container. |
||||
75 | * @param array $cleaners |
||||
0 ignored issues
–
show
|
|||||
76 | */ |
||||
0 ignored issues
–
show
|
|||||
77 | protected function registerCleaners(array $cleaners) |
||||
78 | { |
||||
79 | $this->cleaners = array_unique(array_merge($cleaners, $this->cleaners)); |
||||
80 | foreach ($this->cleaners as $class) { |
||||
81 | $this->currentApp->singleton($class, function () use ($class) { |
||||
0 ignored issues
–
show
|
|||||
82 | $cleaner = new $class($this->currentApp, $this->snapshotApp); |
||||
83 | if (!($cleaner instanceof BaseCleaner)) { |
||||
84 | throw new \InvalidArgumentException(sprintf( |
||||
0 ignored issues
–
show
|
|||||
85 | '%s must extend the abstract class %s', |
||||
0 ignored issues
–
show
|
|||||
86 | $cleaner, |
||||
0 ignored issues
–
show
$cleaner of type object is incompatible with the type double|integer|string expected by parameter $values of sprintf() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
87 | BaseCleaner::class |
||||
0 ignored issues
–
show
|
|||||
88 | ) |
||||
0 ignored issues
–
show
|
|||||
89 | ); |
||||
90 | } |
||||
91 | return $cleaner; |
||||
92 | }); |
||||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||||
93 | } |
||||
94 | } |
||||
95 | |||||
96 | /** |
||||
97 | * Clean app after request finished. |
||||
98 | */ |
||||
0 ignored issues
–
show
|
|||||
99 | public function clean() |
||||
100 | { |
||||
101 | foreach ($this->cleaners as $class) { |
||||
102 | /**@var BaseCleaner $cleaner */ |
||||
0 ignored issues
–
show
|
|||||
103 | $cleaner = $this->currentApp->make($class); |
||||
104 | $cleaner->clean(); |
||||
105 | } |
||||
106 | } |
||||
107 | |||||
108 | /** |
||||
0 ignored issues
–
show
|
|||||
109 | * Register providers for cleaning. |
||||
110 | * |
||||
111 | * @param array providers |
||||
0 ignored issues
–
show
The type
Hhxsv5\LaravelS\Illuminate\providers was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
112 | */ |
||||
0 ignored issues
–
show
|
|||||
113 | protected function registerCleanProviders(array $providers = []) |
||||
114 | { |
||||
115 | $this->providers = $providers; |
||||
116 | } |
||||
117 | |||||
118 | /** |
||||
119 | * Clean Providers. |
||||
120 | */ |
||||
0 ignored issues
–
show
|
|||||
121 | public function cleanProviders() |
||||
122 | { |
||||
123 | $loadedProviders = $this->reflectionApp->loadedProviders(); |
||||
124 | |||||
125 | foreach ($this->providers as $provider) { |
||||
126 | if (class_exists($provider)) { |
||||
127 | if ($this->config['is_lumen']) { |
||||
128 | unset($loadedProviders[get_class(new $provider($this->currentApp))]); |
||||
129 | } |
||||
130 | |||||
131 | switch ($this->reflectionApp->registerMethodParameterCount()) { |
||||
132 | case 1: |
||||
0 ignored issues
–
show
|
|||||
133 | $this->currentApp->register($provider); |
||||
134 | break; |
||||
135 | case 2: |
||||
0 ignored issues
–
show
|
|||||
136 | $this->currentApp->register($provider, true); |
||||
137 | break; |
||||
138 | case 3: |
||||
0 ignored issues
–
show
|
|||||
139 | $this->currentApp->register($provider, [], true); |
||||
140 | break; |
||||
141 | default: |
||||
0 ignored issues
–
show
|
|||||
142 | throw new \RuntimeException('The number of parameters of the register method is unknown.'); |
||||
143 | } |
||||
144 | } |
||||
145 | } |
||||
146 | |||||
147 | if ($this->config['is_lumen']) { |
||||
148 | $this->reflectionApp->setLoadedProviders($loadedProviders); |
||||
149 | } |
||||
150 | } |
||||
151 | |||||
152 | /** |
||||
0 ignored issues
–
show
|
|||||
153 | * Register white list of controllers for cleaning. |
||||
154 | * |
||||
155 | * @param array providers |
||||
0 ignored issues
–
show
|
|||||
156 | */ |
||||
0 ignored issues
–
show
|
|||||
157 | protected function registerCleanControllerWhiteList(array $controllers = []) |
||||
158 | { |
||||
159 | $controllers = array_unique($controllers); |
||||
160 | $this->whiteListControllers = array_combine($controllers, $controllers); |
||||
161 | } |
||||
162 | |||||
163 | /** |
||||
164 | * Clean controllers. |
||||
165 | */ |
||||
0 ignored issues
–
show
|
|||||
166 | public function cleanControllers() |
||||
167 | { |
||||
168 | if ($this->config['is_lumen']) { |
||||
169 | return; |
||||
170 | } |
||||
171 | |||||
172 | if (empty($this->config['destroy_controllers']['enable'])) { |
||||
173 | return; |
||||
174 | } |
||||
175 | |||||
176 | /**@var \Illuminate\Routing\Route $route */ |
||||
0 ignored issues
–
show
|
|||||
177 | $route = $this->currentApp['router']->current(); |
||||
178 | if (!$route) { |
||||
0 ignored issues
–
show
|
|||||
179 | return; |
||||
180 | } |
||||
181 | |||||
182 | if (isset($route->controller)) { // For Laravel 5.4+ |
||||
183 | if (empty($this->whiteListControllers) || !isset($this->whiteListControllers[get_class($route->controller)])) { |
||||
184 | unset($route->controller); |
||||
185 | } |
||||
186 | } else { |
||||
187 | $reflection = new \ReflectionClass(get_class($route)); |
||||
188 | if ($reflection->hasProperty('controller')) { // Laravel 5.3 |
||||
189 | $controller = $reflection->getProperty('controller'); |
||||
190 | $controller->setAccessible(true); |
||||
191 | if (empty($this->whiteListControllers) || (($instance = $controller->getValue($route)) && !isset($this->whiteListControllers[get_class($instance)]))) { |
||||
192 | $controller->setValue($route, null); |
||||
193 | } |
||||
194 | } |
||||
195 | } |
||||
196 | } |
||||
197 | } |
||||
198 |