Completed
Push — master ( f57c42...65aeb1 )
by Choraimy
11s queued 10s
created

GeoRoutesServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaraCrafts\GeoRoutes;
4
5
use Illuminate\Routing\Route;
6
use Illuminate\Support\ServiceProvider;
7
use LaraCrafts\GeoRoutes\Http\Middleware\GeoRoutesMiddleware;
8
9
class GeoRoutesServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any package services.
13
     *
14
     * @return void
15
     */
16 15
    public function boot()
17
    {
18 15
        $this->mergeConfigFrom(__DIR__ . '/../config/geo-routes.php', 'geo-routes');
19 15
        $this->publishes([__DIR__ . '/../config/geo-routes.php' => config_path('geo-routes.php')], 'config');
20
21 15
        if (version_compare($this->app->version(), '5.5.0', '>=')) {
22
            $this->registerMacros();
23
        }
24 15
    }
25
26
    /**
27
     * Register any package services.
28
     *
29
     * @return void
30
     */
31 15
    public function register()
32
    {
33 15
        $router = $this->app->make('router');
34
35 15
        if (method_exists($router, 'aliasMiddleware')) {
36
            $router->aliasMiddleware('geo', GeoRoutesMiddleware::class);
37
        } else {
38 15
            $router->middleware('geo', GeoRoutesMiddleware::class);
39
        }
40 15
    }
41
42
    /**
43
     * Register the route macros.
44
     *
45
     * @return void
46
     */
47
    protected function registerMacros()
48
    {
49
        Route::macro('allowFrom', function (string ...$countries) {
50
            return new GeoRoute($this, $countries, 'allow');
0 ignored issues
show
Bug introduced by
$this of type LaraCrafts\GeoRoutes\GeoRoutesServiceProvider is incompatible with the type Illuminate\Routing\Route expected by parameter $route of LaraCrafts\GeoRoutes\GeoRoute::__construct(). ( Ignorable by Annotation )

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

50
            return new GeoRoute(/** @scrutinizer ignore-type */ $this, $countries, 'allow');
Loading history...
51
        });
52
53
        Route::macro('denyFrom', function (string ...$countries) {
54
            return new GeoRoute($this, $countries, 'deny');
0 ignored issues
show
Bug introduced by
$this of type LaraCrafts\GeoRoutes\GeoRoutesServiceProvider is incompatible with the type Illuminate\Routing\Route expected by parameter $route of LaraCrafts\GeoRoutes\GeoRoute::__construct(). ( Ignorable by Annotation )

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

54
            return new GeoRoute(/** @scrutinizer ignore-type */ $this, $countries, 'deny');
Loading history...
55
        });
56
57
        Route::macro('from', function (string ...$countries) {
58
            return new GeoRoute($this, $countries, 'allow');
0 ignored issues
show
Bug introduced by
$this of type LaraCrafts\GeoRoutes\GeoRoutesServiceProvider is incompatible with the type Illuminate\Routing\Route expected by parameter $route of LaraCrafts\GeoRoutes\GeoRoute::__construct(). ( Ignorable by Annotation )

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

58
            return new GeoRoute(/** @scrutinizer ignore-type */ $this, $countries, 'allow');
Loading history...
59
        });
60
    }
61
}
62