Test Setup Failed
Push — master ( 9daa70...cef6c0 )
by Php Easy Api
04:08
created

App::entity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Resta\Support;
4
5
use Lingua\Lingua;
6
use Store\Services\Crypt;
0 ignored issues
show
Bug introduced by
The type Store\Services\Crypt 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Store\Services\Queue;
0 ignored issues
show
Bug introduced by
The type Store\Services\Queue 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Store\Services\Redis as Redis;
0 ignored issues
show
Bug introduced by
The type Store\Services\Redis 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Resta\Cache\CacheManager as Cache;
10
use Store\Services\HttpSession as Session;
0 ignored issues
show
Bug introduced by
The type Store\Services\HttpSession 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Store\Services\DateCollection as Date;
0 ignored issues
show
Bug introduced by
The type Store\Services\DateCollection 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Store\Services\AppCollection as Collection;
0 ignored issues
show
Bug introduced by
The type Store\Services\AppCollection 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Resta\Foundation\PathManager\StaticPathModel;
14
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)
28
    {
29
        //factory runner
30
        if($service=="factory"){
31
            return self::factory();
32
        }
33
        //if $name starts with $needles for repository
34
        if(Str::endsWith($service,'Repository')){
35
            return self::repository($service);
36
        }
37
38
        //if $name starts with $needles for source
39
        if(Str::endsWith($service,'Source')){
40
            return self::source($service,$arg);
41
        }
42
43
        //if $name starts with $needles for model
44
        if(Str::endsWith($service,'Builder')){
45
            return self::Builder(ucfirst($service));
46
        }
47
48
49
        if(method_exists(new self,$service)){
50
            return self::$service($arg);
51
        }
52
53
        exception()->badMethodCall($service.' invalid method or property');
54
55
    }
56
57
    /**
58
     * @return \Resta\Contracts\ApplicationContracts|\Resta\Contracts\ApplicationHelpersContracts|\Resta\Contracts\ContainerContracts
59
     */
60
    private static function app()
61
    {
62
        return 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();
0 ignored issues
show
Bug introduced by
The call to Resta\Cache\CacheManager::__construct() has too few arguments starting with app. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        return /** @scrutinizer ignore-call */ new Cache();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
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)
245
    {
246
        //get Source path
247
        $service=ucfirst($service);
248
        $getCalledClass=str_replace('\\'.class_basename($arg[0]),'',get_class($arg[0]));
249
        $getCalledClass=class_basename($getCalledClass);
250
251
        $service=str_replace($getCalledClass,'',$service);
252
253
        //run service for endpoint
254
        $serviceSource=StaticPathModel::appSourceEndpoint().'\\'.$getCalledClass.'\\'.$service.'\Main';
255
        return app()->resolve($serviceSource);
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
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $param is correct as it would always require null to be passed?
Loading history...
274
     * @return array|null|string
275
     */
276
    public function route($param=null)
277
    {
278
        $kernel=self::getAppInstance()->kernel;
279
280
        $saltRouteParameters=$kernel->routeParameters;
281
282
        if($param===null){
0 ignored issues
show
introduced by
The condition $param === null is always true.
Loading history...
283
            return $saltRouteParameters;
284
        }
285
286
        $saltRouteParameters = (self::app()->get('routeParams')) ?: $saltRouteParameters;
287
288
        return (isset($saltRouteParameters[$param])) ? strtolower($saltRouteParameters[$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
302
        $lang=(new Lingua($languageDir));
303
304
        if(self::app()->has('locale')){
305
            $defaultLocale = self::app()->get('locale');
306
        }
307
        else{
308
            $defaultLocale = config('app.locale');
309
        }
310
311
        if(!file_exists($languageDir.''.DIRECTORY_SEPARATOR.''.$defaultLocale)){
312
            $defaultLocale = config('app.fallback_locale');
313
        }
314
315
        if(count($select)){
316
            return $lang->include(['default'])->locale($defaultLocale)->get($data,$select);
317
        }
318
319
        return $lang->include(['default'])->locale($defaultLocale)->get($data);
320
    }
321
322
}