LocalizationServiceProvider::registerHelpers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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