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

GeoRoutesServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 47.62%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 50
ccs 10
cts 21
cp 0.4762
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 2
A boot() 0 7 2
A registerMacros() 0 12 1
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