Total Complexity | 47 |
Total Lines | 344 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like App often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use App, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class App |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected static $instance = []; |
||
21 | |||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | protected static $reports = false; |
||
26 | |||
27 | /** |
||
28 | * @param $service |
||
29 | * @param $arg |
||
30 | * @param bool $reports |
||
31 | * @return mixed|string |
||
32 | */ |
||
33 | public static function annotationsLoaders($service,$arg,$reports=false) |
||
62 | |||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return \Resta\Contracts\ApplicationContracts|\Resta\Contracts\ApplicationHelpersContracts|\Resta\Contracts\ContainerContracts |
||
67 | */ |
||
68 | private static function app() |
||
69 | { |
||
70 | return app(); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * client manager instance |
||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | private static function client() |
||
79 | { |
||
80 | $clientManager = self::app()->namespace()->version().'\\ClientManager'; |
||
81 | return new $clientManager; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param $service |
||
86 | * @return mixed |
||
87 | */ |
||
88 | private static function entity($service) |
||
89 | { |
||
90 | //we are making a namespace assignment for the entity. |
||
91 | $entity = app()->namespace()->model().'\Entity\EntityMap'; |
||
92 | |||
93 | //we are getting entity instance. |
||
94 | return app()->resolve($entity); |
||
95 | } |
||
96 | |||
97 | private static function factory() |
||
98 | { |
||
99 | $factory = app()->namespace()->factory().'\Factory'; |
||
100 | return app()->resolve($factory); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @param $service |
||
105 | * @return mixed |
||
106 | */ |
||
107 | private static function builder($service) |
||
108 | { |
||
109 | if(static::$reports){ |
||
110 | self::writeTrace(debug_backtrace(),'builders',$service); |
||
111 | } |
||
112 | |||
113 | //we are making a namespace assignment for the builder. |
||
114 | $builder=app()->namespace()->builder().'\BuilderMap'; |
||
115 | |||
116 | //we are getting builder instance. |
||
117 | return app()->resolve($builder); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @return Cache |
||
122 | */ |
||
123 | private static function cache() |
||
124 | { |
||
125 | return new Cache(); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @return Collection |
||
130 | */ |
||
131 | private static function collection() |
||
132 | { |
||
133 | return (new Collection()); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @param $instance |
||
138 | * @param $class |
||
139 | * @param array $bind |
||
140 | * @return mixed |
||
141 | */ |
||
142 | public function container($instance,$class,$bind=array()) |
||
143 | { |
||
144 | if(!property_exists($instance->container(),$class)){ |
||
145 | throw new \InvalidArgumentException('container object false for ('.$class.') object'); |
||
146 | } |
||
147 | |||
148 | $container=$instance->container()->{$class}; |
||
149 | |||
150 | if(!is_array($instance->container()->{$class}) AND Utils::isNamespaceExists($container)){ |
||
151 | return $instance->resolve($container,$bind); |
||
152 | } |
||
153 | return $instance->container()->{$class}; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param $object |
||
158 | */ |
||
159 | public function createAppInstance($object) |
||
160 | { |
||
161 | if(!defined('appInstance')){ |
||
162 | define('appInstance',(base64_encode(serialize($object)))); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @param array $arg |
||
168 | * @return mixed |
||
169 | */ |
||
170 | private static function date($arg=array()) |
||
171 | { |
||
172 | $locale = (count($arg)=="0") ? config('app.locale','en') : current($arg); |
||
173 | |||
174 | return app()->resolve(Date::class)->setLocale($locale); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * @return mixed |
||
179 | */ |
||
180 | private static function crypt() |
||
181 | { |
||
182 | return app()->resolve(Crypt::class); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @return mixed |
||
187 | */ |
||
188 | public static function getAppInstance() |
||
189 | { |
||
190 | //we save an instance for the entire application |
||
191 | //and add it to the helper file to be accessed from anywhere in the application. |
||
192 | if(!isset(self::$instance['appInstance'])){ |
||
193 | self::$instance['appInstance']=unserialize(base64_decode(appInstance)); |
||
194 | return self::$instance['appInstance']; |
||
195 | } |
||
196 | return self::$instance['appInstance']; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return \stdClass |
||
201 | */ |
||
202 | public static function kernelBindObject() |
||
203 | { |
||
204 | return new \stdClass; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @return Session |
||
209 | */ |
||
210 | private static function session() |
||
211 | { |
||
212 | return new Session(); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * @return mixed |
||
217 | */ |
||
218 | private static function queue() |
||
219 | { |
||
220 | if(!isset(self::$instance['queue'])){ |
||
221 | |||
222 | self::$instance['queue']=(new Queue()); |
||
223 | return self::$instance['queue']; |
||
224 | |||
225 | } |
||
226 | return self::$instance['queue']; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * @param $service |
||
231 | * @param bool $namespace |
||
232 | * @return string |
||
233 | */ |
||
234 | public static function repository($service,$namespace=false) |
||
235 | { |
||
236 | if(static::$reports){ |
||
237 | self::writeTrace(debug_backtrace(),'repositories',$service); |
||
238 | } |
||
239 | |||
240 | //I can get the repository name from the magic method as a salt repository, |
||
241 | //after which we will edit it as an adapter namespace. |
||
242 | $repositoryName=ucfirst(preg_replace('@Repository@is','',$service)); |
||
243 | |||
244 | //If we then configure the name of the simple repository to be an adapter |
||
245 | //then we will give the user an example of the adapter class in each repository call. |
||
246 | $repositoryAdapterName = $repositoryName.'Adapter'; |
||
247 | $repositoryNamespace = app()->namespace()->repository().'\\'.$repositoryName.'\\'.$repositoryAdapterName; |
||
248 | |||
249 | if($namespace) return $repositoryNamespace; |
||
250 | |||
251 | //and eventually we conclude the adapter class of the repository package as an instance. |
||
252 | return app()->resolve($repositoryNamespace)->adapter(); |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * @param $trace |
||
257 | */ |
||
258 | private static function writeTrace($trace,$type,$service) |
||
259 | { |
||
260 | if(self::app()->isLocale()){ |
||
261 | $trace = $trace[2]; |
||
262 | |||
263 | $time = time(); |
||
264 | |||
265 | JsonHandler::$file = path()->kernel().''.DIRECTORY_SEPARATOR.'Reports.json'; |
||
266 | |||
267 | $getJsonFile = JsonHandler::get('annotation.'.$type.'.'.$service.'.file'); |
||
268 | |||
269 | $filenamespace = Utils::getNamespace($trace['file']); |
||
270 | |||
271 | if(!in_array($filenamespace,!is_array($getJsonFile) ? [] : $getJsonFile)){ |
||
272 | JsonHandler::set('annotation.'.$type.'.'.$service.'.file.'.$time,$filenamespace); |
||
273 | JsonHandler::set('annotation.'.$type.'.'.$service.'.line.'.$time,$trace['line']); |
||
274 | } |
||
275 | } |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * @param $service |
||
280 | * @param $arg |
||
281 | * @return mixed |
||
282 | */ |
||
283 | private static function source($service,$arg) |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * @return mixed |
||
299 | */ |
||
300 | public static function redis() |
||
301 | { |
||
302 | if(!isset(self::$instance['redis'])){ |
||
303 | |||
304 | self::$instance['redis']=(new Redis())->client(); |
||
305 | return self::$instance['redis']; |
||
306 | |||
307 | } |
||
308 | return self::$instance['redis']; |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * @param null $param |
||
313 | * @return array|null|string |
||
314 | */ |
||
315 | public function route($param=null) |
||
328 | |||
329 | |||
330 | } |
||
331 | |||
332 | /** |
||
333 | * @param $data |
||
334 | * @param array $select |
||
335 | * @return mixed|string |
||
336 | */ |
||
337 | public function translator($data,$select=array()) |
||
359 | } |
||
360 | |||
361 | } |
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.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths