LocalizationServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 14 1
A register() 0 11 1
A registerHelpers() 0 6 1
A registerMacros() 0 4 1
1
<?php
2
3
namespace AlexJoffroy\Localization;
4
5
use AlexJoffroy\Localization\Listeners\AppLocaleUpdated;
6
use AlexJoffroy\Localization\Localization;
7
use Illuminate\Foundation\Events\LocaleUpdated;
8
use Illuminate\Support\ServiceProvider;
9
10
class LocalizationServiceProvider extends ServiceProvider
11
{
12 27
    public function boot()
13
    {
14 27
        $this->publishes([
15 27
            __DIR__ . '/../config/localization.php' => config_path('localization.php'),
16 27
        ], 'config');
17
18 27
        $this->publishes([
19 27
            __DIR__ . '/../resources/views' => base_path('resources/views/vendor/localization'),
20 27
        ], 'views');
21
22 27
        $this->loadViewsFrom(__DIR__ . '/../resources/views', 'localization');
23
24 27
        $this->app->events->listen(LocaleUpdated::class, AppLocaleUpdated::class);
0 ignored issues
show
Bug introduced by
Accessing events on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
25 27
    }
26
27 27
    public function register()
28
    {
29 27
        $this->mergeConfigFrom(__DIR__ . '/../config/localization.php', 'localization');
30
31
        $this->app->singleton('localization', function () {
32 27
            return new Localization($this->app);
33 27
        });
34
35 27
        $this->registerHelpers();
36 27
        $this->registerMacros();
37 27
    }
38
39 27
    public function registerHelpers()
40
    {
41 27
        require_once __DIR__ . '/Helpers/l10n.php';
42 27
        require_once __DIR__ . '/Helpers/locale.php';
43 27
        require_once __DIR__ . '/Helpers/locales.php';
44 27
    }
45
46 27
    public function registerMacros()
47
    {
48 27
        require_once __DIR__.'/Macros/locales.php';
49 27
    }
50
}
51