Completed
Push — master ( 50e245...46828e )
by CodexShaper
07:06
created

wpb_today()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * The all functions.
4
 *
5
 * @link       https://github.com/maab16
6
 * @since      1.0.0
7
 *
8
 * @package    WPB
9
 */
10
11
use Codexshaper_Pwa\Application;
0 ignored issues
show
Bug introduced by
The type Codexshaper_Pwa\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...
12
use Illuminate\Container\Container;
13
use Illuminate\Support\Str;
14
use Illuminate\Support\Carbon;
15
use Illuminate\Support\HtmlString;
16
use Illuminate\Contracts\Bus\Dispatcher;
17
use Illuminate\Contracts\Auth\Access\Gate;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Gate. 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...
18
use Illuminate\Contracts\Support\Responsable;
19
use Illuminate\Contracts\Routing\UrlGenerator;
20
// use Illuminate\Foundation\Bus\PendingDispatch;
21
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Response. 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...
22
use Illuminate\Contracts\Debug\ExceptionHandler;
23
use Illuminate\Contracts\Routing\ResponseFactory;
24
use Illuminate\Contracts\Auth\Factory as AuthFactory;
25
use Illuminate\Contracts\View\Factory as ViewFactory;
26
use Illuminate\Http\Exceptions\HttpResponseException;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HttpResponseException. 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...
27
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
28
use Symfony\Component\Debug\Exception\FatalThrowableError;
29
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
30
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
31
use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
32
33
if ( ! function_exists( 'wpb_csrf_token' ) ) {
34
	/**
35
	 * Generate wp nonce.
36
	 *
37
	 * @param string|null $action   This is the nonce action name.
38
	 *
39
	 * @return null|string
40
	 */
41
	function wpb_csrf_token( $action = 'wpb_nonce' ) {
42
		return wp_create_nonce( $action );
0 ignored issues
show
Bug introduced by
The function wp_create_nonce was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

42
		return /** @scrutinizer ignore-call */ wp_create_nonce( $action );
Loading history...
43
	}
44
}
45
46
if ( ! function_exists( 'wpb_config' ) ) {
47
	/**
48
	 * Get / set the specified configuration value.
49
	 *
50
	 * If an array is passed as the key, we will assume you want to set an array of values.
51
	 *
52
	 * @param array|string|null $key This is the key for config array.
53
	 * @param mixed             $default This is the default config value.
54
	 *
55
	 * @return mixed|\Illuminate\Config\Repository
56
	 */
57
	function wpb_config( $key = null, $default = null ) {
58
		if ( is_null( $key ) ) {
59
			return app( 'config' );
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

59
			return /** @scrutinizer ignore-call */ app( 'config' );
Loading history...
60
		}
61
62
		if ( is_array( $key ) ) {
63
			return app( 'config' )->set( $key );
64
		}
65
66
		return app( 'config' )->get( $key, $default );
67
	}
68
}
69
70
if ( ! function_exists( 'wpb_view' ) ) {
71
	/**
72
	 * Render blade view.
73
	 *
74
	 * @param string $view   This is the filename.
75
	 * @param array  $data   This is the view data.
76
	 * @param array  $merge_data   This is the merge data for view.
77
	 *
78
	 * @throws \Exception This will throw an exception if view class doesn't exists.
79
	 * @return null|string
80
	 */
81
	function wpb_view( $view, $data = array(), $merge_data = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $merge_data is not used and could be removed. ( Ignorable by Annotation )

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

81
	function wpb_view( $view, $data = array(), /** @scrutinizer ignore-unused */ $merge_data = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

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

81
	function wpb_view( $view, /** @scrutinizer ignore-unused */ $data = array(), $merge_data = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
		if ( ! class_exists( \CodexShaper\Blade\View::class ) ) {
83
			throw new \Exception( 'View not resolved. Please install View' );
84
		}
85
86
		return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() );
87
	}
88
}
89
90
if (! function_exists('wpb_abort')) {
91
    /**
92
     * Throw an HttpException with the given data.
93
     *
94
     * @param  \Symfony\Component\HttpFoundation\Response|int     $code
95
     * @param  string  $message
96
     * @param  array   $headers
97
     * @return void
98
     *
99
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
100
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
101
     */
102
    function wpb_abort($code, $message = '', array $headers = [])
103
    {
104
        if ($code instanceof Response) {
105
            throw new HttpResponseException($code);
106
        } elseif ($code instanceof Responsable) {
0 ignored issues
show
introduced by
$code is never a sub-type of Illuminate\Contracts\Support\Responsable.
Loading history...
107
            throw new HttpResponseException($code->toResponse(request()));
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

107
            throw new HttpResponseException($code->toResponse(/** @scrutinizer ignore-call */ request()));
Loading history...
108
        }
109
110
        wpb_app()->abort($code, $message, $headers);
111
    }
112
}
113
114
if (! function_exists('wpb_abort_if')) {
115
    /**
116
     * Throw an HttpException with the given data if the given condition is true.
117
     *
118
     * @param  bool    $boolean
119
     * @param  int     $code
120
     * @param  string  $message
121
     * @param  array   $headers
122
     * @return void
123
     *
124
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
125
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
126
     */
127
    function wpb_abort_if($boolean, $code, $message = '', array $headers = [])
128
    {
129
        if ($boolean) {
130
            wpb_abort($code, $message, $headers);
131
        }
132
    }
133
}
134
135
if (! function_exists('wpb_abort_unless')) {
136
    /**
137
     * Throw an HttpException with the given data unless the given condition is true.
138
     *
139
     * @param  bool    $boolean
140
     * @param  int     $code
141
     * @param  string  $message
142
     * @param  array   $headers
143
     * @return void
144
     *
145
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
146
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
147
     */
148
    function wpb_abort_unless($boolean, $code, $message = '', array $headers = [])
149
    {
150
        if (! $boolean) {
151
            wpb_abort($code, $message, $headers);
152
        }
153
    }
154
}
155
156
if (! function_exists('wpb_action')) {
157
    /**
158
     * Generate the URL to a controller action.
159
     *
160
     * @param  string  $name
161
     * @param  mixed   $parameters
162
     * @param  bool    $absolute
163
     * @return string
164
     */
165
    function wpb_action($name, $parameters = [], $absolute = true)
166
    {
167
        return wpb_app('url')->action($name, $parameters, $absolute);
168
    }
169
}
170
171
if (! function_exists('wpb_app')) {
172
    /**
173
     * Get the available container instance.
174
     *
175
     * @param  string  $abstract
176
     * @param  array   $parameters
177
     * @return mixed|\Illuminate\Foundation\Application
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\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...
178
     */
179
    function wpb_app($abstract = null, array $parameters = [])
180
    {
181
    	global $wpb_app;
182
183
        if (is_null($abstract)) {
184
            return $wpb_app;
185
        }
186
187
        return $wpb_app->make($abstract, $parameters);
188
    }
189
}
190
191
if (! function_exists('wpb_app_path')) {
192
    /**
193
     * Get the path to the application folder.
194
     *
195
     * @param  string  $path
196
     * @return string
197
     */
198
    function wpb_app_path($path = '')
199
    {
200
        return wpb_app('path').($path ? DIRECTORY_SEPARATOR.$path : $path);
201
    }
202
}
203
204
if (! function_exists('wpb_asset')) {
205
    /**
206
     * Generate an asset path for the application.
207
     *
208
     * @param  string  $path
209
     * @param  bool    $secure
210
     * @return string
211
     */
212
    function wpb_asset($path, $secure = null)
213
    {
214
        return wpb_app('url')->asset($path, $secure);
215
    }
216
}
217
218
if (! function_exists('wpb_auth')) {
219
    /**
220
     * Get the available auth instance.
221
     *
222
     * @param  string|null  $guard
223
     * @return \Illuminate\Contracts\Auth\Factory|\Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard
224
     */
225
    function wpb_auth($guard = null)
226
    {
227
        if (is_null($guard)) {
228
            return wpb_app(AuthFactory::class);
229
        }
230
231
        return wpb_app(AuthFactory::class)->guard($guard);
232
    }
233
}
234
235
if (! function_exists('wpb_back')) {
236
    /**
237
     * Create a new redirect response to the previous location.
238
     *
239
     * @param  int    $status
240
     * @param  array  $headers
241
     * @param  mixed  $fallback
242
     * @return \Illuminate\Http\RedirectResponse
243
     */
244
    function wpb_back($status = 302, $headers = [], $fallback = false)
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...
245
    {
246
        return wpb_app('redirect')->back($status, $headers, $fallback);
247
    }
248
}
249
250
if (! function_exists('wpb_base_path')) {
251
    /**
252
     * Get the path to the base of the install.
253
     *
254
     * @param  string  $path
255
     * @return string
256
     */
257
    function wpb_base_path($path = '')
258
    {
259
        return wpb_app()->basePath().($path ? DIRECTORY_SEPARATOR.$path : $path);
260
    }
261
}
262
263
if (! function_exists('wpb_bcrypt')) {
264
    /**
265
     * Hash the given value against the bcrypt algorithm.
266
     *
267
     * @param  string  $value
268
     * @param  array  $options
269
     * @return string
270
     */
271
    function wpb_bcrypt($value, $options = [])
272
    {
273
        return wpb_app('hash')->driver('bcrypt')->make($value, $options);
274
    }
275
}
276
277
if (! function_exists('wpb_broadcast')) {
278
    /**
279
     * Begin broadcasting an event.
280
     *
281
     * @param  mixed|null  $event
282
     * @return \Illuminate\Broadcasting\PendingBroadcast
0 ignored issues
show
Bug introduced by
The type Illuminate\Broadcasting\PendingBroadcast 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...
283
     */
284
    function wpb_broadcast($event = null)
285
    {
286
        return wpb_app(BroadcastFactory::class)->event($event);
287
    }
288
}
289
290
if (! function_exists('wpb_cache')) {
291
    /**
292
     * Get / set the specified cache value.
293
     *
294
     * If an array is passed, we'll assume you want to put to the cache.
295
     *
296
     * @param  dynamic  key|key,default|data,expiration|null
0 ignored issues
show
Bug introduced by
The type key 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...
297
     * @return mixed|\Illuminate\Cache\CacheManager
0 ignored issues
show
Bug introduced by
The type Illuminate\Cache\CacheManager 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...
298
     *
299
     * @throws \Exception
300
     */
301
    function wpb_cache()
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...
302
    {
303
        $arguments = func_get_args();
304
305
        if (empty($arguments)) {
306
            return wpb_app('cache');
307
        }
308
309
        if (is_string($arguments[0])) {
310
            return wpb_app('cache')->get($arguments[0], $arguments[1] ?? null);
311
        }
312
313
        if (! is_array($arguments[0])) {
314
            throw new Exception(
315
                'When setting a value in the cache, you must pass an array of key / value pairs.'
316
            );
317
        }
318
319
        if (! isset($arguments[1])) {
320
            throw new Exception(
321
                'You must specify an expiration time when setting a value in the cache.'
322
            );
323
        }
324
325
        return wpb_app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1]);
326
    }
327
}
328
329
if (! function_exists('wpb_config_path')) {
330
    /**
331
     * Get the configuration path.
332
     *
333
     * @param  string  $path
334
     * @return string
335
     */
336
    function wpb_config_path($path = '')
337
    {
338
        return wpb_app()->make('path.config').($path ? DIRECTORY_SEPARATOR.$path : $path);
339
    }
340
}
341
342
if (! function_exists('wpb_cookie')) {
343
    /**
344
     * Create a new cookie instance.
345
     *
346
     * @param  string  $name
347
     * @param  string  $value
348
     * @param  int  $minutes
349
     * @param  string  $path
350
     * @param  string  $domain
351
     * @param  bool  $secure
352
     * @param  bool  $httpOnly
353
     * @param  bool  $raw
354
     * @param  string|null  $sameSite
355
     * @return \Illuminate\Cookie\CookieJar|\Symfony\Component\HttpFoundation\Cookie
0 ignored issues
show
Bug introduced by
The type Illuminate\Cookie\CookieJar 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...
356
     */
357
    function wpb_cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true, $raw = false, $sameSite = null)
358
    {
359
        $cookie = wpb_app(CookieFactory::class);
360
361
        if (is_null($name)) {
362
            return $cookie;
363
        }
364
365
        return $cookie->make($name, $value, $minutes, $path, $domain, $secure, $httpOnly, $raw, $sameSite);
366
    }
367
}
368
369
if (! function_exists('wpb_csrf_field')) {
370
    /**
371
     * Generate a CSRF token form field.
372
     *
373
     * @return \Illuminate\Support\HtmlString
374
     */
375
    function wpb_csrf_field()
376
    {
377
        return new HtmlString('<input type="hidden" name="_token" value="'.csrf_token().'">');
0 ignored issues
show
Bug introduced by
The function csrf_token was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

377
        return new HtmlString('<input type="hidden" name="_token" value="'./** @scrutinizer ignore-call */ csrf_token().'">');
Loading history...
378
    }
379
}
380
381
if (! function_exists('wpb_database_path')) {
382
    /**
383
     * Get the database path.
384
     *
385
     * @param  string  $path
386
     * @return string
387
     */
388
    function wpb_database_path($path = '')
389
    {
390
        return wpb_app()->databasePath($path);
391
    }
392
}
393
394
if (! function_exists('wpb_decrypt')) {
395
    /**
396
     * Decrypt the given value.
397
     *
398
     * @param  string  $value
399
     * @param  bool   $unserialize
400
     * @return mixed
401
     */
402
    function wpb_decrypt($value, $unserialize = true)
403
    {
404
        return wpb_app('encrypter')->decrypt($value, $unserialize);
405
    }
406
}
407
408
if (! function_exists('wpb_dispatch')) {
409
    /**
410
     * Dispatch a job to its appropriate handler.
411
     *
412
     * @param  mixed  $job
413
     * @return \Illuminate\Foundation\Bus\PendingDispatch
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Bus\PendingDispatch 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...
414
     */
415
    function wpb_dispatch($job)
0 ignored issues
show
Unused Code introduced by
The parameter $job is not used and could be removed. ( Ignorable by Annotation )

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

415
    function wpb_dispatch(/** @scrutinizer ignore-unused */ $job)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
416
    {
417
        // return new PendingDispatch($job);
418
    }
419
}
420
421
if (! function_exists('wpb_dispatch_now')) {
422
    /**
423
     * Dispatch a command to its appropriate handler in the current process.
424
     *
425
     * @param  mixed  $job
426
     * @param  mixed  $handler
427
     * @return mixed
428
     */
429
    function wpb_dispatch_now($job, $handler = null)
430
    {
431
        return wpb_app(Dispatcher::class)->dispatchNow($job, $handler);
432
    }
433
}
434
435
if (! function_exists('wpb_elixir')) {
436
    /**
437
     * Get the path to a versioned Elixir file.
438
     *
439
     * @param  string  $file
440
     * @param  string  $buildDirectory
441
     * @return string
442
     *
443
     * @throws \InvalidArgumentException
444
     */
445
    function wpb_elixir($file, $buildDirectory = 'build')
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...
446
    {
447
        static $manifest = [];
448
        static $manifestPath;
449
450
        if (empty($manifest) || $manifestPath !== $buildDirectory) {
451
            $path = wpb_public_path($buildDirectory.'/rev-manifest.json');
452
453
            if (file_exists($path)) {
454
                $manifest = json_decode(file_get_contents($path), true);
455
                $manifestPath = $buildDirectory;
456
            }
457
        }
458
459
        $file = ltrim($file, '/');
460
461
        if (isset($manifest[$file])) {
462
            return '/'.trim($buildDirectory.'/'.$manifest[$file], '/');
463
        }
464
465
        $unversioned = wpb_public_path($file);
466
467
        if (file_exists($unversioned)) {
468
            return '/'.trim($file, '/');
469
        }
470
471
        throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
472
    }
473
}
474
475
if (! function_exists('wpb_encrypt')) {
476
    /**
477
     * Encrypt the given value.
478
     *
479
     * @param  mixed  $value
480
     * @param  bool   $serialize
481
     * @return string
482
     */
483
    function wpb_encrypt($value, $serialize = true)
484
    {
485
        return wpb_app('encrypter')->encrypt($value, $serialize);
486
    }
487
}
488
489
if (! function_exists('wpb_event')) {
490
    /**
491
     * Dispatch an event and call the listeners.
492
     *
493
     * @param  string|object  $event
494
     * @param  mixed  $payload
495
     * @param  bool  $halt
496
     * @return array|null
497
     */
498
    function wpb_event(...$args)
499
    {
500
        return wpb_app('events')->dispatch(...$args);
501
    }
502
}
503
504
if (! function_exists('wpb_factory')) {
505
    /**
506
     * Create a model factory builder for a given class, name, and amount.
507
     *
508
     * @param  dynamic  class|class,name|class,amount|class,name,amount
509
     * @return \Illuminate\Database\Eloquent\FactoryBuilder
510
     */
511
    function wpb_factory()
512
    {
513
        $factory = wpb_app(EloquentFactory::class);
514
515
        $arguments = func_get_args();
516
517
        if (isset($arguments[1]) && is_string($arguments[1])) {
518
            return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ?? null);
519
        } elseif (isset($arguments[1])) {
520
            return $factory->of($arguments[0])->times($arguments[1]);
521
        }
522
523
        return $factory->of($arguments[0]);
524
    }
525
}
526
527
if (! function_exists('wpb_info')) {
528
    /**
529
     * Write some information to the log.
530
     *
531
     * @param  string  $message
532
     * @param  array   $context
533
     * @return void
534
     */
535
    function wpb_info($message, $context = [])
536
    {
537
        wpb_app('log')->info($message, $context);
538
    }
539
}
540
541
if (! function_exists('wpb_logger')) {
542
    /**
543
     * Log a debug message to the logs.
544
     *
545
     * @param  string  $message
546
     * @param  array  $context
547
     * @return \Illuminate\Log\LogManager|null
0 ignored issues
show
Bug introduced by
The type Illuminate\Log\LogManager 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...
548
     */
549
    function wpb_logger($message = null, array $context = [])
550
    {
551
        if (is_null($message)) {
552
            return wpb_app('log');
553
        }
554
555
        return wpb_app('log')->debug($message, $context);
556
    }
557
}
558
559
if (! function_exists('wpb_logs')) {
560
    /**
561
     * Get a log driver instance.
562
     *
563
     * @param  string  $driver
564
     * @return \Illuminate\Log\LogManager|\Psr\Log\LoggerInterface
565
     */
566
    function wpb_logs($driver = null)
567
    {
568
        return $driver ? wpb_app('log')->driver($driver) : wpb_app('log');
569
    }
570
}
571
572
if (! function_exists('wpb_method_field')) {
573
    /**
574
     * Generate a form field to spoof the HTTP verb used by forms.
575
     *
576
     * @param  string  $method
577
     * @return \Illuminate\Support\HtmlString
578
     */
579
    function wpb_method_field($method)
580
    {
581
        return new HtmlString('<input type="hidden" name="_method" value="'.$method.'">');
582
    }
583
}
584
585
if (! function_exists('wpb_mix')) {
586
    /**
587
     * Get the path to a versioned Mix file.
588
     *
589
     * @param  string  $path
590
     * @param  string  $manifestDirectory
591
     * @return \Illuminate\Support\HtmlString|string
592
     *
593
     * @throws \Exception
594
     */
595
    function wpb_mix($path, $manifestDirectory = '')
596
    {
597
        static $manifests = [];
598
599
        if (! Str::startsWith($path, '/')) {
600
            $path = "/{$path}";
601
        }
602
603
        if ($manifestDirectory && ! Str::startsWith($manifestDirectory, '/')) {
604
            $manifestDirectory = "/{$manifestDirectory}";
605
        }
606
607
        if (file_exists(public_path($manifestDirectory.'/hot'))) {
0 ignored issues
show
Bug introduced by
The function public_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

607
        if (file_exists(/** @scrutinizer ignore-call */ public_path($manifestDirectory.'/hot'))) {
Loading history...
608
            $url = file_get_contents(public_path($manifestDirectory.'/hot'));
609
610
            if (Str::startsWith($url, ['http://', 'https://'])) {
611
                return new HtmlString(Str::after($url, ':').$path);
612
            }
613
614
            return new HtmlString("//localhost:8080{$path}");
615
        }
616
617
        $manifestPath = wpb_public_path($manifestDirectory.'/mix-manifest.json');
618
619
        if (! isset($manifests[$manifestPath])) {
620
            if (! file_exists($manifestPath)) {
621
                throw new Exception('The Mix manifest does not exist.');
622
            }
623
624
            $manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);
625
        }
626
627
        $manifest = $manifests[$manifestPath];
628
629
        if (! isset($manifest[$path])) {
630
            wpb_report(new Exception("Unable to locate Mix file: {$path}."));
631
632
            if (! wpb_app('config')->get('app.debug')) {
633
                return $path;
634
            }
635
        }
636
637
        return new HtmlString($manifestDirectory.$manifest[$path]);
638
    }
639
}
640
641
if (! function_exists('wpb_now')) {
642
    /**
643
     * Create a new Carbon instance for the current time.
644
     *
645
     * @param  \DateTimeZone|string|null $tz
646
     * @return \Illuminate\Support\Carbon
647
     */
648
    function wpb_wpb_now($tz = null)
649
    {
650
        return Carbon::now($tz);
651
    }
652
}
653
654
if (! function_exists('wpb_old')) {
655
    /**
656
     * Retrieve an old input item.
657
     *
658
     * @param  string  $key
659
     * @param  mixed   $default
660
     * @return mixed
661
     */
662
    function wpb_old($key = null, $default = null)
663
    {
664
        return wpb_app('request')->old($key, $default);
665
    }
666
}
667
668
if (! function_exists('wpb_policy')) {
669
    /**
670
     * Get a policy instance for a given class.
671
     *
672
     * @param  object|string  $class
673
     * @return mixed
674
     *
675
     * @throws \InvalidArgumentException
676
     */
677
    function wpb_policy($class)
678
    {
679
        return wpb_app(Gate::class)->getPolicyFor($class);
680
    }
681
}
682
683
if (! function_exists('wpb_public_path')) {
684
    /**
685
     * Get the path to the public folder.
686
     *
687
     * @param  string  $path
688
     * @return string
689
     */
690
    function wpb_public_path($path = '')
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...
691
    {
692
        return wpb_app()->make('path.public').($path ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : $path);
693
    }
694
}
695
696
if (! function_exists('wpb_redirect')) {
697
    /**
698
     * Get an instance of the redirector.
699
     *
700
     * @param  string|null  $to
701
     * @param  int     $status
702
     * @param  array   $headers
703
     * @param  bool    $secure
704
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
705
     */
706
    function wpb_redirect($to = null, $status = 302, $headers = [], $secure = null)
707
    {
708
        if (is_null($to)) {
709
            return wpb_app('redirect');
710
        }
711
712
        return wpb_app('redirect')->to($to, $status, $headers, $secure);
713
    }
714
}
715
716
if (! function_exists('wpb_report')) {
717
    /**
718
     * Report an exception.
719
     *
720
     * @param  \Exception  $exception
721
     * @return void
722
     */
723
    function wpb_report($exception)
724
    {
725
        if ($exception instanceof Throwable &&
726
            ! $exception instanceof Exception) {
0 ignored issues
show
introduced by
$exception is always a sub-type of Exception.
Loading history...
727
            $exception = new FatalThrowableError($exception);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Debug\...ion\FatalThrowableError has been deprecated: since Symfony 4.4 ( Ignorable by Annotation )

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

727
            $exception = /** @scrutinizer ignore-deprecated */ new FatalThrowableError($exception);
Loading history...
728
        }
729
730
        wpb_app(ExceptionHandler::class)->report($exception);
731
    }
732
}
733
734
if (! function_exists('wpb_request')) {
735
    /**
736
     * Get an instance of the current request or an input item from the request.
737
     *
738
     * @param  array|string  $key
739
     * @param  mixed   $default
740
     * @return \Illuminate\Http\Request|string|array
741
     */
742
    function wpb_request($key = null, $default = 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...
743
    {
744
        if (is_null($key)) {
745
            return wpb_app('request');
746
        }
747
748
        if (is_array($key)) {
749
            return wpb_app('request')->only($key);
750
        }
751
752
        $value = wpb_app('request')->__get($key);
753
754
        return is_null($value) ? value($default) : $value;
755
    }
756
}
757
758
if (! function_exists('wpb_rescue')) {
759
    /**
760
     * Catch a potential exception and return a default value.
761
     *
762
     * @param  callable  $callback
763
     * @param  mixed  $rescue
764
     * @return mixed
765
     */
766
    function wpb_rescue(callable $callback, $rescue = null)
767
    {
768
        try {
769
            return $callback();
770
        } catch (Throwable $e) {
771
            wpb_report($e);
772
773
            return value($rescue);
774
        }
775
    }
776
}
777
778
if (! function_exists('wpb_resolve')) {
779
    /**
780
     * Resolve a service from the container.
781
     *
782
     * @param  string  $name
783
     * @return mixed
784
     */
785
    function wpb_resolve($name)
786
    {
787
        return wpb_app($name);
788
    }
789
}
790
791
if (! function_exists('wpb_resource_path')) {
792
    /**
793
     * Get the path to the resources folder.
794
     *
795
     * @param  string  $path
796
     * @return string
797
     */
798
    function wpb_resource_path($path = '')
799
    {
800
        return wpb_app()->resourcePath($path);
801
    }
802
}
803
804
if (! function_exists('wpb_response')) {
805
    /**
806
     * Return a new response from the application.
807
     *
808
     * @param  \Illuminate\View\View|string|array|null  $content
809
     * @param  int     $status
810
     * @param  array   $headers
811
     * @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
812
     */
813
    function wpb_response($content = '', $status = 200, array $headers = [])
814
    {
815
        $factory = wpb_app(ResponseFactory::class);
816
817
        if (func_num_args() === 0) {
818
            return $factory;
819
        }
820
821
        return $factory->make($content, $status, $headers);
822
    }
823
}
824
825
if (! function_exists('wpb_route')) {
826
    /**
827
     * Generate the URL to a named route.
828
     *
829
     * @param  array|string  $name
830
     * @param  mixed  $parameters
831
     * @param  bool  $absolute
832
     * @return string
833
     */
834
    function wpb_route($name, $parameters = [], $absolute = true)
835
    {
836
        return wpb_app('url')->route($name, $parameters, $absolute);
837
    }
838
}
839
840
if (! function_exists('wpb_secure_asset')) {
841
    /**
842
     * Generate an asset path for the application.
843
     *
844
     * @param  string  $path
845
     * @return string
846
     */
847
    function wpb_secure_asset($path)
848
    {
849
        return wpb_asset($path, true);
850
    }
851
}
852
853
if (! function_exists('wpb_secure_url')) {
854
    /**
855
     * Generate a HTTPS url for the application.
856
     *
857
     * @param  string  $path
858
     * @param  mixed   $parameters
859
     * @return string
860
     */
861
    function wpb_secure_url($path, $parameters = [])
862
    {
863
        return wpb_url($path, $parameters, true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return wpb_url($path, $parameters, true) also could return the type Illuminate\Contracts\Routing\UrlGenerator which is incompatible with the documented return type string.
Loading history...
864
    }
865
}
866
867
if (! function_exists('wpb_session')) {
868
    /**
869
     * Get / set the specified session value.
870
     *
871
     * If an array is passed as the key, we will assume you want to set an array of values.
872
     *
873
     * @param  array|string  $key
874
     * @param  mixed  $default
875
     * @return mixed|\Illuminate\Session\Store|\Illuminate\Session\SessionManager
876
     */
877
    function wpb_session($key = null, $default = null)
878
    {
879
        if (is_null($key)) {
880
            return wpb_app('session');
881
        }
882
883
        if (is_array($key)) {
884
            return wpb_app('session')->put($key);
885
        }
886
887
        return wpb_app('session')->get($key, $default);
888
    }
889
}
890
891
if (! function_exists('wpb_storage_path')) {
892
    /**
893
     * Get the path to the storage folder.
894
     *
895
     * @param  string  $path
896
     * @return string
897
     */
898
    function wpb_storage_path($path = '')
899
    {
900
        return wpb_app('path.storage').($path ? DIRECTORY_SEPARATOR.$path : $path);
901
    }
902
}
903
904
if (! function_exists('wpb_today')) {
905
    /**
906
     * Create a new Carbon instance for the current date.
907
     *
908
     * @param  \DateTimeZone|string|null $tz
909
     * @return \Illuminate\Support\Carbon
910
     */
911
    function wpb_today($tz = null)
912
    {
913
        return Carbon::today($tz);
914
    }
915
}
916
917
if (! function_exists('wpb_trans')) {
918
    /**
919
     * Translate the given message.
920
     *
921
     * @param  string  $key
922
     * @param  array   $replace
923
     * @param  string  $locale
924
     * @return \Illuminate\Contracts\Translation\Translator|string|array|null
925
     */
926
    function wpb_trans($key = null, $replace = [], $locale = null)
927
    {
928
        if (is_null($key)) {
929
            return wpb_app('translator');
930
        }
931
932
        return wpb_app('translator')->trans($key, $replace, $locale);
933
    }
934
}
935
936
if (! function_exists('wpb_trans_choice')) {
937
    /**
938
     * Translates the given message based on a count.
939
     *
940
     * @param  string  $key
941
     * @param  int|array|\Countable  $number
942
     * @param  array   $replace
943
     * @param  string  $locale
944
     * @return string
945
     */
946
    function wpb_trans_choice($key, $number, array $replace = [], $locale = null)
947
    {
948
        return wpb_app('translator')->transChoice($key, $number, $replace, $locale);
949
    }
950
}
951
952
if (! function_exists('__')) {
953
    /**
954
     * Translate the given message.
955
     *
956
     * @param  string  $key
957
     * @param  array  $replace
958
     * @param  string  $locale
959
     * @return string|array|null
960
     */
961
    function __($key, $replace = [], $locale = null)
962
    {
963
        return wpb_app('translator')->getFromJson($key, $replace, $locale);
964
    }
965
}
966
967
if (! function_exists('wpb_url')) {
968
    /**
969
     * Generate a url for the application.
970
     *
971
     * @param  string  $path
972
     * @param  mixed   $parameters
973
     * @param  bool    $secure
974
     * @return \Illuminate\Contracts\Routing\UrlGenerator|string
975
     */
976
    function wpb_url($path = null, $parameters = [], $secure = null)
977
    {
978
        if (is_null($path)) {
979
            return wpb_app(UrlGenerator::class);
980
        }
981
982
        return wpb_app(UrlGenerator::class)->to($path, $parameters, $secure);
983
    }
984
}
985
986
if (! function_exists('wpb_validator')) {
987
    /**
988
     * Create a new Validator instance.
989
     *
990
     * @param  array  $data
991
     * @param  array  $rules
992
     * @param  array  $messages
993
     * @param  array  $customAttributes
994
     * @return \Illuminate\Contracts\Validation\Validator
995
     */
996
    function wpb_validator(array $data = [], array $rules = [], array $messages = [], array $customAttributes = [])
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...
997
    {
998
        $factory = wpb_app(ValidationFactory::class);
999
1000
        if (func_num_args() === 0) {
1001
            return $factory;
1002
        }
1003
1004
        return $factory->make($data, $rules, $messages, $customAttributes);
1005
    }
1006
}
1007