Passed
Pull Request — master (#4)
by Adam
02:15
created

FoundationServiceProvider::initializeRequest()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 18
rs 9.9666
c 0
b 0
f 0
cc 3
nc 4
nop 2
1
<?php
2
3
namespace Endeavors\Components\Routing;
4
5
use Illuminate\Routing\Redirector;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\URL;
9
10
class FoundationServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Register the service provider.
14
     *
15
     * @return void
16
     */
17
    public function register()
18
    {
19
        $this->registerRequestSignatureValidation();
20
    }
21
22
    /**
23
     * Register the signature macros on the request.
24
     * @todo is URL::getRequest the same as $this
25
     * @return void
26
     */
27
    public function registerRequestSignatureValidation()
28
    {
29
        Request::macro('hasValidSignature', function() {
30
            return URL::hasValidSignature($this ?? URL::getRequest());
31
        });
32
33
        Request::macro('hasInvalidSignature', function() {
34
            return !URL::hasValidSignature($this ?? URL::getRequest());
35
        });
36
37
        Request::macro('hasValidParameterSignature', function(array $parameters = []) {
38
            return URL::hasValidParameterSignature($this ?? URL::getRequest(), $parameters);
39
        });
40
41
        Request::macro('hasInvalidParameterSignature', function(array $parameters = []) {
42
            return !URL::hasValidParameterSignature($this ?? URL::getRequest(), $parameters);
43
        });
44
    }
45
}
46