Passed
Push — master ( a6c6d7...adfcc4 )
by Php Easy Api
04:31
created

containerCacheFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Faker\Factory;
4
use Faker\Generator;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Generator. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use Resta\Router\Route;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Route. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Resta\Support\Utils;
7
use Resta\Support\Filesystem;
8
use Resta\Logger\LoggerHandler;
9
use Store\Services\RequestService;
0 ignored issues
show
Bug introduced by
The type Store\Services\RequestService 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...
10
use Resta\Exception\ExceptionManager;
11
use Resta\Support\HigherOrderTapProxy;
12
use Resta\Response\ResponseOutManager;
13
use Resta\EventDispatcher\EventManager;
14
use Resta\Contracts\ExceptionContracts;
15
use Resta\Contracts\StaticPathContracts;
16
use Resta\Contracts\ApplicationContracts;
17
use Resta\Authenticate\AuthenticateContract;
18
use Resta\Authenticate\AuthenticateProvider;
19
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use Resta\Foundation\PathManager\StaticPathList;
21
22
if (!function_exists('app')) {
23
24
    /**
25
     * @return ApplicationContracts
26
     */
27
    function app()
28
    {
29
        return appInstance();
30
    }
31
}
32
33
if (!function_exists('appInstance')) {
34
35
    /**
36
     * @return mixed
37
     */
38
    function appInstance()
39
    {
40
        return \application::getAppInstance();
0 ignored issues
show
Bug introduced by
The type application 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...
41
    }
42
}
43
44
if (!function_exists('applicationKey')) {
45
46
    /**
47
     * @return string
48
     */
49
    function applicationKey()
50
    {
51
        if(property_exists($kernel=app()->kernel(),'applicationKey')){
52
            return $kernel->applicationKey;
53
        }
54
        return null;
55
56
    }
57
}
58
59
if (!function_exists('auth')) {
60
    /**
61
     * @return AuthenticateContract
62
     */
63
    function auth()
64
    {
65
        return app()->resolve(AuthenticateProvider::class);
66
    }
67
}
68
69
if (!function_exists('bind')) {
70
71
    function bind()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
72
    {
73
        return (object)app()['serviceContainer'];
74
    }
75
}
76
77
if (!function_exists('bundleName')) {
78
79
    /**
80
     * @return null|string
81
     */
82
    function bundleName()
83
    {
84
        if(defined('endpoint')){
85
86
            return endpoint.''.StaticPathList::$controllerBundleName;
87
        }
88
        return null;
89
    }
90
}
91
92
if (!function_exists('config')) {
93
94
    /**
95
     * @param null $config
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $config is correct as it would always require null to be passed?
Loading history...
96
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
97
     * @return mixed|null
98
     */
99
    function config($config=null,$default=null)
100
    {
101
        $configResult = app()->config($config);
102
103
        if($configResult === null && $default!==null){
0 ignored issues
show
introduced by
The condition $default !== null is always false.
Loading history...
104
            return $default;
105
        }
106
107
        return $configResult;
108
    }
109
}
110
111
if (!function_exists('container')) {
112
113
    /**
114
     * @param $class
115
     * @param $bind array
116
     * @return mixed
117
     */
118
    function container($class,$bind=array())
119
    {
120
        return app()->singleton()->appClass->container(appInstance(),$class,$bind);
121
    }
122
}
123
124
if (!function_exists('core')) {
125
126
    /**
127
     * @return mixed
128
     */
129
    function core()
130
    {
131
        return app()->singleton();
132
    }
133
}
134
135
if (!function_exists('dd')) {
136
    function dd()
137
    {
138
        $args = func_get_args();
139
        call_user_func_array('dump', $args);
140
        die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
141
    }
142
}
143
144
if (!function_exists('files')) {
145
146
    /**
147
     * @return Filesystem
148
     */
149
    function files() : Filesystem
150
    {
151
        return app()->resolve(Filesystem::class);
152
    }
153
}
154
155
if (!function_exists('environment')) {
156
    function environment()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
157
    {
158
        return app()->environment(func_get_args());
159
    }
160
}
161
162
if (!function_exists('event')) {
163
164
    /**
165
     * @return EventManager
166
     */
167
    function event()
168
    {
169
        return app()->singleton()->bindings['eventDispatcher'];
170
    }
171
}
172
173
if (!function_exists('exception')) {
174
175
    /**
176
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
177
     * @param array $params
178
     * @return ExceptionContracts
179
     */
180
    function exception($name=null,$params=array())
181
    {
182
        $exceptionManager=ExceptionManager::class;
183
        return app()->resolve($exceptionManager,['name'=>$name,'params'=>$params]);
184
    }
185
}
186
187
if (!function_exists('faker')) {
188
189
    /**
190
     * @param null $locale
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $locale is correct as it would always require null to be passed?
Loading history...
191
     * @return Generator
192
     */
193
    function faker($locale=null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
194
    {
195
        if($locale===null){
0 ignored issues
show
introduced by
The condition $locale === null is always true.
Loading history...
196
            $faker=Factory::create();
197
        }
198
        else{
199
            $faker=Factory::create($locale);
200
        }
201
202
        return $faker;
203
    }
204
}
205
206
if (!function_exists('fingerPrint')) {
207
208
    function fingerPrint()
209
    {
210
        return md5(sha1(implode("|",[
211
            request()->getClientIp(),applicationKey()
212
        ])));
213
    }
214
}
215
216
if (!function_exists('fullUrl')) {
217
218
    function fullUrl()
219
    {
220
        return request()->getUri();
221
    }
222
}
223
224
if (!function_exists('get')) {
225
226
    /**
227
     * @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...
228
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
229
     * @return null
230
     */
231
    function get($param=null,$default=null)
232
    {
233
        //symfony request query object
234
        $get=core()->get;
235
236
        return ($param===null) ? $get : (isset($get[$param]) ? $get[$param] : $default);
0 ignored issues
show
introduced by
The condition $param === null is always true.
Loading history...
237
    }
238
}
239
240
if (!function_exists('headers')) {
241
242
    /**
243
     * @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...
244
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
245
     * @return array|string
246
     */
247
    function headers($param=null,$default=null)
248
    {
249
        $list=[];
250
251
        //We only get the objects in the list name to match the header objects
252
        //that come with the request path to the objects sent by the client
253
        foreach (request()->headers->all() as $key=>$value) {
254
            $list[$key]=$value;
255
        }
256
257
        //return header list
258
        return ($param===null) ? $list : (isset($list[$param]) ? $list[$param][0] : $default);
0 ignored issues
show
introduced by
The condition $param === null is always true.
Loading history...
259
    }
260
}
261
262
if (!function_exists('httpMethod')) {
263
264
    /**
265
     * @return string
266
     */
267
    function httpMethod()
268
    {
269
        return strtolower(core()->httpMethod);
270
    }
271
}
272
273
if (!function_exists('logger')) {
274
275
    /**
276
     * @param $file null
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $$file is correct as it would always require null to be passed?
Loading history...
277
     * @return LoggerHandler
278
     */
279
    function logger($file=null)
280
    {
281
        return app()->resolve(LoggerHandler::class,['file'=>$file]);
282
    }
283
}
284
285
if (!function_exists('request')) {
286
287
    /**
288
     * @return RequestService|Request
289
     */
290
    function request()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
291
    {
292
        return core()->request;
293
    }
294
}
295
296
if (!function_exists('response')) {
297
298
    /**
299
     * @return ResponseOutManager
300
     */
301
    function response()
302
    {
303
        $object=debug_backtrace()[1]['object'];
304
        return new ResponseOutManager($object);
305
    }
306
}
307
308
if (!function_exists('resolve')) {
309
310
    /**
311
     * @param $class
312
     * @param array $bind
313
     * @return mixed|null
314
     *
315
     * @throws \DI\DependencyException
316
     * @throws \DI\NotFoundException
317
     */
318
    function resolve($class,$bind=array())
319
    {
320
        return app()->resolve($class,$bind);
321
    }
322
}
323
324
if (!function_exists('policy')) {
325
326
    /**
327
     * @return mixed
328
     */
329
    function policy()
330
    {
331
        $policyPath = implode('/',[
332
            Route::getRouteControllerNamespace(),
333
            'Policy',
334
            Route::getRouteControllerClass().'Policy'
335
        ]);
336
337
        $policyNamespace = Utils::getNamespace($policyPath);
338
339
        if(Utils::isNamespaceExists($policyNamespace)){
340
            return app()->resolve(Utils::getNamespace($policyPath));
341
        }
342
343
        return stdClass::class;
344
345
    }
346
}
347
348
if (!function_exists('route')) {
349
350
    /**
351
     * @param $key
352
     * @return mixed
353
     */
354
    function route($key=null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
355
    {
356
        if(is_null($key)){
357
            return array_map(function($route){
358
                return strtolower($route);
359
            },app()->singleton()->appClass->route($key));
360
        }
361
362
        return app()->singleton()->appClass->route($key);
363
364
    }
365
}
366
367
if (!function_exists('path')) {
368
369
    /**
370
     * @return StaticPathContracts
371
     */
372
    function path()
373
    {
374
        return app()->path();
375
    }
376
}
377
378
if (!function_exists('post')) {
379
380
    /**
381
     * @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...
382
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
383
     * @return mixed
384
     */
385
    function post($param=null,$default=null)
386
    {
387
        //symfony request query object
388
        $post=core()->post;
389
390
        return ($param===null) ? $post : (isset($post[$param]) ? $post[$param] : $default);
0 ignored issues
show
introduced by
The condition $param === null is always true.
Loading history...
391
    }
392
}
393
394
if (!function_exists('tap')) {
395
396
    /**
397
     * @param $value
398
     * @param $callback
399
     * @return mixed
400
     */
401
    function tap($value, $callback)
402
    {
403
        if (!is_callable($callback)) {
404
            return new HigherOrderTapProxy($value);
405
        }
406
407
        $callback($value);
408
        return $value;
409
    }
410
}
411
412
if (!function_exists('trans')) {
413
414
    /**
415
     * @param $lang
416
     * @param array $select
417
     * @return mixed
418
     */
419
    function trans($lang,$select=array())
420
    {
421
        return app()->singleton()->appClass->translator($lang,$select);
422
    }
423
}
424
425
if (!function_exists('serviceJson')) {
426
427
    /**
428
     * @return string
429
     */
430
    function containerCacheFile()
431
    {
432
        $file = app()->path()->kernel().''.DIRECTORY_SEPARATOR.'service.json';
433
434
        if(file_exists($file)){
435
            return $file;
436
        }
437
438
        return null;
439
    }
440
}