| Total Complexity | 41 |
| Total Lines | 305 |
| 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 | * @param $service |
||
| 24 | * @param $arg |
||
| 25 | * @return mixed |
||
| 26 | */ |
||
| 27 | public static function annotationsLoaders($service,$arg) |
||
| 54 | |||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return \Resta\Contracts\ApplicationContracts|\Resta\Contracts\ApplicationHelpersContracts|\Resta\Contracts\ContainerContracts |
||
| 59 | */ |
||
| 60 | private static function app() |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * client manager instance |
||
| 67 | * |
||
| 68 | * @return mixed |
||
| 69 | */ |
||
| 70 | private static function client() |
||
| 71 | {
|
||
| 72 | $clientManager = self::app()->namespace()->version().'\\ClientManager'; |
||
| 73 | return new $clientManager; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param $service |
||
| 78 | * @return mixed |
||
| 79 | */ |
||
| 80 | private static function entity($service) |
||
| 81 | {
|
||
| 82 | //we are making a namespace assignment for the entity. |
||
| 83 | $entity = app()->namespace()->model().'\Entity\EntityMap'; |
||
| 84 | |||
| 85 | //we are getting entity instance. |
||
| 86 | return app()->resolve($entity); |
||
| 87 | } |
||
| 88 | |||
| 89 | private static function factory() |
||
| 90 | {
|
||
| 91 | $factory = app()->namespace()->factory().'\Factory'; |
||
| 92 | return app()->resolve($factory); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param $service |
||
| 97 | * @return mixed |
||
| 98 | */ |
||
| 99 | private static function builder($service) |
||
| 100 | {
|
||
| 101 | //we are making a namespace assignment for the builder. |
||
| 102 | $builder=app()->namespace()->builder().'\BuilderMap'; |
||
| 103 | |||
| 104 | //we are getting builder instance. |
||
| 105 | return app()->resolve($builder); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return Cache |
||
| 110 | */ |
||
| 111 | private static function cache() |
||
| 112 | {
|
||
| 113 | return new Cache(); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @return Collection |
||
| 118 | */ |
||
| 119 | private static function collection() |
||
| 120 | {
|
||
| 121 | return (new Collection()); |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param $instance |
||
| 126 | * @param $class |
||
| 127 | * @param array $bind |
||
| 128 | * @return mixed |
||
| 129 | */ |
||
| 130 | public function container($instance,$class,$bind=array()) |
||
| 131 | {
|
||
| 132 | if(!property_exists($instance->container(),$class)){
|
||
| 133 | throw new \InvalidArgumentException('container object false for ('.$class.') object');
|
||
| 134 | } |
||
| 135 | |||
| 136 | $container=$instance->container()->{$class};
|
||
| 137 | |||
| 138 | if(!is_array($instance->container()->{$class}) AND Utils::isNamespaceExists($container)){
|
||
| 139 | return $instance->resolve($container,$bind); |
||
| 140 | } |
||
| 141 | return $instance->container()->{$class};
|
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @param $object |
||
| 146 | */ |
||
| 147 | public function createAppInstance($object) |
||
| 148 | {
|
||
| 149 | if(!defined('appInstance')){
|
||
| 150 | define('appInstance',(base64_encode(serialize($object))));
|
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param array $arg |
||
| 156 | * @return mixed |
||
| 157 | */ |
||
| 158 | private static function date($arg=array()) |
||
| 159 | {
|
||
| 160 | $locale = (count($arg)=="0") ? config('app.locale','en') : current($arg);
|
||
| 161 | |||
| 162 | return app()->resolve(Date::class)->setLocale($locale); |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return mixed |
||
| 167 | */ |
||
| 168 | private static function crypt() |
||
| 169 | {
|
||
| 170 | return app()->resolve(Crypt::class); |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return mixed |
||
| 175 | */ |
||
| 176 | public static function getAppInstance() |
||
| 177 | {
|
||
| 178 | //we save an instance for the entire application |
||
| 179 | //and add it to the helper file to be accessed from anywhere in the application. |
||
| 180 | if(!isset(self::$instance['appInstance'])){
|
||
| 181 | self::$instance['appInstance']=unserialize(base64_decode(appInstance)); |
||
| 182 | return self::$instance['appInstance']; |
||
| 183 | } |
||
| 184 | return self::$instance['appInstance']; |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @return \stdClass |
||
| 189 | */ |
||
| 190 | public static function kernelBindObject() |
||
| 191 | {
|
||
| 192 | return new \stdClass; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return Session |
||
| 197 | */ |
||
| 198 | private static function session() |
||
| 199 | {
|
||
| 200 | return new Session(); |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @return mixed |
||
| 205 | */ |
||
| 206 | private static function queue() |
||
| 207 | {
|
||
| 208 | if(!isset(self::$instance['queue'])){
|
||
| 209 | |||
| 210 | self::$instance['queue']=(new Queue()); |
||
| 211 | return self::$instance['queue']; |
||
| 212 | |||
| 213 | } |
||
| 214 | return self::$instance['queue']; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @param $service |
||
| 219 | * @param bool $namespace |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | public static function repository($service,$namespace=false) |
||
| 223 | {
|
||
| 224 | //I can get the repository name from the magic method as a salt repository, |
||
| 225 | //after which we will edit it as an adapter namespace. |
||
| 226 | $repositoryName=ucfirst(preg_replace('@Repository@is','',$service));
|
||
| 227 | |||
| 228 | //If we then configure the name of the simple repository to be an adapter |
||
| 229 | //then we will give the user an example of the adapter class in each repository call. |
||
| 230 | $repositoryAdapterName = $repositoryName.'Adapter'; |
||
| 231 | $repositoryNamespace = app()->namespace()->repository().'\\'.$repositoryName.'\\'.$repositoryAdapterName; |
||
| 232 | |||
| 233 | if($namespace) return $repositoryNamespace; |
||
| 234 | |||
| 235 | //and eventually we conclude the adapter class of the repository package as an instance. |
||
| 236 | return app()->resolve($repositoryNamespace)->adapter(); |
||
| 237 | } |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @param $service |
||
| 241 | * @param $arg |
||
| 242 | * @return mixed |
||
| 243 | */ |
||
| 244 | private static function source($service,$arg) |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return mixed |
||
| 260 | */ |
||
| 261 | public static function redis() |
||
| 262 | {
|
||
| 263 | if(!isset(self::$instance['redis'])){
|
||
| 264 | |||
| 265 | self::$instance['redis']=(new Redis())->client(); |
||
| 266 | return self::$instance['redis']; |
||
| 267 | |||
| 268 | } |
||
| 269 | return self::$instance['redis']; |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @param null $param |
||
| 274 | * @return array|null|string |
||
| 275 | */ |
||
| 276 | public function route($param=null) |
||
| 289 | |||
| 290 | |||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @param $data |
||
| 295 | * @param array $select |
||
| 296 | * @return mixed|string |
||
| 297 | */ |
||
| 298 | public function translator($data,$select=array()) |
||
| 299 | {
|
||
| 300 | $languageDir = path()->appLanguage(); |
||
| 301 | |||
| 322 | } |
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