Test Setup Failed
Push — master ( 665277...008233 )
by Php Easy Api
03:42
created

files()   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
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\Support\Filesystem;
6
use Resta\Logger\LoggerHandler;
7
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...
8
use Resta\Exception\ExceptionManager;
9
use Resta\Support\HigherOrderTapProxy;
10
use Resta\Response\ResponseOutManager;
11
use Resta\Contracts\ContainerContracts;
12
use Resta\EventDispatcher\EventManager;
13
use Resta\Contracts\ExceptionContracts;
14
use Resta\Contracts\StaticPathContracts;
15
use Resta\Contracts\ApplicationContracts;
16
use Resta\Foundation\ApplicationProvider;
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\Contracts\ApplicationHelpersContracts;
21
use Resta\Foundation\PathManager\StaticPathList;
22
23
if (!function_exists('app')) {
24
25
    /**
26
     * @return ApplicationContracts|ApplicationHelpersContracts
27
     */
28
    function app()
29
    {
30
        return appInstance();
0 ignored issues
show
Bug Best Practice introduced by
The expression return appInstance() returns the type Resta\Foundation\ApplicationProvider which is incompatible with the documented return type Resta\Contracts\Applicat...icationHelpersContracts.
Loading history...
31
    }
32
}
33
34
if (!function_exists('appInstance')) {
35
36
    /**
37
     * @return ApplicationProvider
38
     */
39
    function appInstance()
40
    {
41
        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...
42
    }
43
}
44
45
if (!function_exists('applicationKey')) {
46
47
    /**
48
     * @return string
49
     */
50
    function applicationKey()
51
    {
52
        if(property_exists($kernel=app()->kernel(),'applicationKey')){
0 ignored issues
show
Bug introduced by
The method kernel() does not exist on Resta\Contracts\ApplicationHelpersContracts. ( Ignorable by Annotation )

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

52
        if(property_exists($kernel=app()->/** @scrutinizer ignore-call */ kernel(),'applicationKey')){

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
            return $kernel->applicationKey;
54
        }
55
        return null;
56
57
    }
58
}
59
60
if (!function_exists('auth')) {
61
    /**
62
     * @return AuthenticateContract
63
     */
64
    function auth()
65
    {
66
        return app()->resolve(AuthenticateProvider::class);
0 ignored issues
show
Bug introduced by
The method resolve() does not exist on Resta\Contracts\ApplicationHelpersContracts. ( Ignorable by Annotation )

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

66
        return app()->/** @scrutinizer ignore-call */ resolve(AuthenticateProvider::class);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
    }
68
}
69
70
if (!function_exists('bind')) {
71
72
    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...
73
    {
74
        return (object)app()['serviceContainer'];
75
    }
76
}
77
78
if (!function_exists('bundleName')) {
79
80
    /**
81
     * @return null|string
82
     */
83
    function bundleName()
84
    {
85
        if(defined('endpoint')){
86
87
            return endpoint.''.StaticPathList::$controllerBundleName;
88
        }
89
        return null;
90
    }
91
}
92
93
if (!function_exists('config')) {
94
95
    /**
96
     * @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...
97
     * @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...
98
     * @return mixed|null
99
     */
100
    function config($config=null,$default=null)
101
    {
102
        $configResult = app()->config($config);
0 ignored issues
show
Bug introduced by
The method config() does not exist on Resta\Contracts\ApplicationHelpersContracts. ( Ignorable by Annotation )

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

102
        $configResult = app()->/** @scrutinizer ignore-call */ config($config);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
104
        if($configResult === null && $default!==null){
0 ignored issues
show
introduced by
The condition $default !== null is always false.
Loading history...
105
            return $default;
106
        }
107
108
        return $configResult;
109
    }
110
}
111
112
if (!function_exists('container')) {
113
114
    /**
115
     * @param $class
116
     * @param $bind array
117
     * @return mixed
118
     */
119
    function container($class,$bind=array())
120
    {
121
        return app()->singleton()->appClass->container(appInstance(),$class,$bind);
0 ignored issues
show
Bug introduced by
The method singleton() does not exist on Resta\Contracts\ApplicationHelpersContracts. ( Ignorable by Annotation )

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

121
        return app()->/** @scrutinizer ignore-call */ singleton()->appClass->container(appInstance(),$class,$bind);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
122
    }
123
}
124
125
if (!function_exists('core')) {
126
127
    /**
128
     * @return mixed
129
     */
130
    function core()
131
    {
132
        return app()->singleton();
133
    }
134
}
135
136
if (!function_exists('dd')) {
137
    function dd()
138
    {
139
        $args = func_get_args();
140
        call_user_func_array('dump', $args);
141
        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...
142
    }
143
}
144
145
if (!function_exists('files')) {
146
147
    /**
148
     * @return Filesystem
149
     */
150
    function files() : Filesystem
151
    {
152
        return app()->resolve(Filesystem::class);
153
    }
154
}
155
156
if (!function_exists('environment')) {
157
    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...
158
    {
159
        return app()->environment(func_get_args());
0 ignored issues
show
Bug introduced by
The method environment() does not exist on Resta\Contracts\ApplicationHelpersContracts. ( Ignorable by Annotation )

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

159
        return app()->/** @scrutinizer ignore-call */ environment(func_get_args());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
160
    }
161
}
162
163
if (!function_exists('event')) {
164
165
    /**
166
     * @return EventManager
167
     */
168
    function event()
169
    {
170
        return app()->singleton()->bindings['eventDispatcher'];
171
    }
172
}
173
174
if (!function_exists('exception')) {
175
176
    /**
177
     * @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...
178
     * @param array $params
179
     * @return ExceptionContracts
180
     */
181
    function exception($name=null,$params=array())
182
    {
183
        $exceptionManager=ExceptionManager::class;
184
        return app()->resolve($exceptionManager,['name'=>$name,'params'=>$params]);
185
    }
186
}
187
188
if (!function_exists('faker')) {
189
190
    /**
191
     * @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...
192
     * @return Generator
193
     */
194
    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...
195
    {
196
        if($locale===null){
0 ignored issues
show
introduced by
The condition $locale === null is always true.
Loading history...
197
            $faker=Factory::create();
198
        }
199
        else{
200
            $faker=Factory::create($locale);
201
        }
202
203
        return $faker;
204
    }
205
}
206
207
if (!function_exists('fingerPrint')) {
208
209
    function fingerPrint()
210
    {
211
        return md5(sha1(implode("|",[
212
            request()->getClientIp(),$_SERVER['HTTP_USER_AGENT'],applicationKey()
213
        ])));
214
    }
215
}
216
217
if (!function_exists('fullUrl')) {
218
219
    function fullUrl()
220
    {
221
        return request()->getUri();
222
    }
223
}
224
225
if (!function_exists('get')) {
226
227
    /**
228
     * @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...
229
     * @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...
230
     * @return null
231
     */
232
    function get($param=null,$default=null)
233
    {
234
        //symfony request query object
235
        $get=core()->get;
236
237
        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...
238
    }
239
}
240
241
if (!function_exists('headers')) {
242
243
    /**
244
     * @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...
245
     * @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...
246
     * @return array
247
     */
248
    function headers($param=null,$default=null)
249
    {
250
        $list=[];
251
252
        //We only get the objects in the list name to match the header objects
253
        //that come with the request path to the objects sent by the client
254
        foreach (request()->headers->all() as $key=>$value) {
255
            $list[$key]=$value;
256
        }
257
258
        //return header list
259
        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...
260
    }
261
}
262
263
if (!function_exists('httpMethod')) {
264
265
    /**
266
     * @return string
267
     */
268
    function httpMethod()
269
    {
270
        return strtolower(core()->httpMethod);
271
    }
272
}
273
274
if (!function_exists('logger')) {
275
276
    /**
277
     * @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...
278
     * @return LoggerHandler
279
     */
280
    function logger($file=null)
281
    {
282
        return app()->resolve(LoggerHandler::class,['file'=>$file]);
283
    }
284
}
285
286
if (!function_exists('request')) {
287
288
    /**
289
     * @return RequestService|Request
290
     */
291
    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...
292
    {
293
        return core()->request;
294
    }
295
}
296
297
if (!function_exists('response')) {
298
299
    /**
300
     * @return ResponseOutManager
301
     */
302
    function response()
303
    {
304
        $object=debug_backtrace()[1]['object'];
305
        return new ResponseOutManager($object);
306
    }
307
}
308
309
if (!function_exists('resolve')) {
310
311
    /**
312
     * @param $class
313
     * @param array $bind
314
     * @return mixed|null
315
     *
316
     * @throws \DI\DependencyException
317
     * @throws \DI\NotFoundException
318
     */
319
    function resolve($class,$bind=array())
320
    {
321
        return app()->resolve($class,$bind);
322
    }
323
}
324
325
if (!function_exists('route')) {
326
327
    /**
328
     * @param $key
329
     * @return mixed
330
     */
331
    function route($key=null)
332
    {
333
        return array_map(function($route){
334
            return strtolower($route);
335
        },app()->singleton()->appClass->route($key));
336
    }
337
}
338
339
if (!function_exists('path')) {
340
341
    /**
342
     * @return StaticPathContracts
343
     */
344
    function path()
345
    {
346
        return app()->path();
347
    }
348
}
349
350
if (!function_exists('post')) {
351
352
    /**
353
     * @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...
354
     * @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...
355
     * @return mixed
356
     */
357
    function post($param=null,$default=null)
358
    {
359
        //symfony request query object
360
        $post=core()->post;
361
362
        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...
363
    }
364
}
365
366
if (!function_exists('tap')) {
367
368
    /**
369
     * @param $value
370
     * @param $callback
371
     * @return mixed
372
     */
373
    function tap($value, $callback)
374
    {
375
        if (!is_callable($callback)) {
376
            return new HigherOrderTapProxy($value);
377
        }
378
379
        $callback($value);
380
        return $value;
381
    }
382
}
383
384
if (!function_exists('trans')) {
385
386
    /**
387
     * @param $lang
388
     * @param array $select
389
     * @return mixed
390
     */
391
    function trans($lang,$select=array())
392
    {
393
        return app()->singleton()->appClass->translator($lang,$select);
394
    }
395
}