Test Setup Failed
Push — master ( 1c8c73...68a798 )
by Php Easy Api
04:02
created

App::crypt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
     * @param $service
67
     * @return mixed
68
     */
69
    private static function entity($service)
70
    {
71
        //we are making a namespace assignment for the entity.
72
        $entity = app()->namespace()->model().'\Entity\EntityMap';
73
74
        //we are getting entity instance.
75
        return app()->resolve($entity);
76
    }
77
78
    private static function factory()
79
    {
80
        $factory = app()->namespace()->factory().'\Factory';
81
        return app()->resolve($factory);
82
    }
83
84
    /**
85
     * @param $service
86
     * @return mixed
87
     */
88
    private static function builder($service)
89
    {
90
        //we are making a namespace assignment for the builder.
91
        $builder=app()->namespace()->builder().'\BuilderMap';
92
93
        //we are getting builder instance.
94
        return app()->resolve($builder);
95
    }
96
97
    /**
98
     * @return Cache
99
     */
100
    private static function cache()
101
    {
102
        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

102
        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...
103
    }
104
105
    /**
106
     * @return Collection
107
     */
108
    private static function collection()
109
    {
110
        return (new Collection());
111
    }
112
113
    /**
114
     * @param $instance
115
     * @param $class
116
     * @param array $bind
117
     * @return mixed
118
     */
119
    public function container($instance,$class,$bind=array())
120
    {
121
        if(!property_exists($instance->container(),$class)){
122
            throw new \InvalidArgumentException('container object false for ('.$class.') object');
123
        }
124
125
        $container=$instance->container()->{$class};
126
127
        if(!is_array($instance->container()->{$class}) AND Utils::isNamespaceExists($container)){
128
            return $instance->resolve($container,$bind);
129
        }
130
        return $instance->container()->{$class};
131
    }
132
133
    /**
134
     * @param $object
135
     */
136
    public function createAppInstance($object)
137
    {
138
        if(!defined('appInstance')){
139
            define('appInstance',(base64_encode(serialize($object))));
140
        }
141
    }
142
143
    /**
144
     * @param array $arg
145
     * @return mixed
146
     */
147
    private static function date($arg=array())
148
    {
149
        $locale = (count($arg)=="0") ? config('app.locale','en') : current($arg);
150
151
        return app()->resolve(Date::class)->setLocale($locale);
152
    }
153
154
    /**
155
     * @return mixed
156
     */
157
    private static function crypt()
158
    {
159
        return app()->resolve(Crypt::class);
160
    }
161
162
    /**
163
     * @return mixed
164
     */
165
    public static function getAppInstance()
166
    {
167
        //we save an instance for the entire application
168
        //and add it to the helper file to be accessed from anywhere in the application.
169
        if(!isset(self::$instance['appInstance'])){
170
            self::$instance['appInstance']=unserialize(base64_decode(appInstance));
171
            return self::$instance['appInstance'];
172
        }
173
        return self::$instance['appInstance'];
174
    }
175
176
    /**
177
     * @return \stdClass
178
     */
179
    public static function kernelBindObject()
180
    {
181
        return new \stdClass;
182
    }
183
184
    /**
185
     * @return Session
186
     */
187
    private static function session()
188
    {
189
        return new Session();
190
    }
191
192
    /**
193
     * @return mixed
194
     */
195
    private static function queue()
196
    {
197
        if(!isset(self::$instance['queue'])){
198
199
            self::$instance['queue']=(new Queue());
200
            return self::$instance['queue'];
201
202
        }
203
        return self::$instance['queue'];
204
    }
205
206
    /**
207
     * @param $service
208
     * @param bool $namespace
209
     * @return string
210
     */
211
    public static function repository($service,$namespace=false)
212
    {
213
        //I can get the repository name from the magic method as a salt repository,
214
        //after which we will edit it as an adapter namespace.
215
        $repositoryName=ucfirst(preg_replace('@Repository@is','',$service));
216
217
        //If we then configure the name of the simple repository to be an adapter
218
        //then we will give the user an example of the adapter class in each repository call.
219
        $repositoryAdapterName  = $repositoryName.'Adapter';
220
        $repositoryNamespace    = app()->namespace()->repository().'\\'.$repositoryName.'\\'.$repositoryAdapterName;
221
222
        if($namespace) return $repositoryNamespace;
223
224
        //and eventually we conclude the adapter class of the repository package as an instance.
225
        return app()->resolve($repositoryNamespace)->adapter();
226
    }
227
228
    /**
229
     * @param $service
230
     * @param $arg
231
     * @return mixed
232
     */
233
    private static function source($service,$arg)
234
    {
235
        //get Source path
236
        $service=ucfirst($service);
237
        $getCalledClass=str_replace('\\'.class_basename($arg[0]),'',get_class($arg[0]));
238
        $getCalledClass=class_basename($getCalledClass);
239
240
        $service=str_replace($getCalledClass,'',$service);
241
242
        //run service for endpoint
243
        $serviceSource=StaticPathModel::appSourceEndpoint().'\\'.$getCalledClass.'\\'.$service.'\Main';
244
        return app()->resolve($serviceSource);
245
    }
246
247
    /**
248
     * @return mixed
249
     */
250
    public static function redis()
251
    {
252
        if(!isset(self::$instance['redis'])){
253
254
            self::$instance['redis']=(new Redis())->client();
255
            return self::$instance['redis'];
256
257
        }
258
        return self::$instance['redis'];
259
    }
260
261
    /**
262
     * @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...
263
     * @return array|null|string
264
     */
265
    public function route($param=null)
266
    {
267
        $kernel=self::getAppInstance()->kernel;
268
269
        $saltRouteParameters=$kernel->routeParameters;
270
271
        if($param===null){
0 ignored issues
show
introduced by
The condition $param === null is always true.
Loading history...
272
            return $saltRouteParameters;
273
        }
274
275
        $saltRouteParameters = (self::app()->get('routeParams')) ?: $saltRouteParameters;
276
277
        return (isset($saltRouteParameters[$param])) ? strtolower($saltRouteParameters[$param]) : null;
278
279
280
    }
281
282
    /**
283
     * @param $data
284
     * @param array $select
285
     * @return mixed|string
286
     */
287
    public function translator($data,$select=array())
288
    {
289
        $lang=(new Lingua(path()->appLanguage()));
290
291
        $defaultLocale=config('app.locale');
292
293
        if(count($select)){
294
            return $lang->include(['default'])->locale($defaultLocale)->get($data,$select);
295
        }
296
297
        return $lang->include(['default'])->locale($defaultLocale)->get($data);
298
    }
299
300
}