Passed
Push — master ( 385f43...170131 )
by Zahir
05:35
created

HelperServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCommands() 0 4 1
A registerResources() 0 10 3
A register() 0 3 1
A registerHelpers() 0 6 3
A isLumen() 0 3 1
A boot() 0 7 1
A packagePath() 0 3 1
1
<?php
2
3
namespace Hayrullah\Helpers;
4
5
use Hayrullah\Helper\Commands;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Support\Str;
8
9
class HelperServiceProvider extends ServiceProvider
10
{
11
    protected $HELPERS_PATH = 'Helpers/';
12
13
    /**
14
     * Register services.
15
     *
16
     * @return void
17
     */
18
    public function register()
19
    {
20
        $this->registerHelpers();
21
    }
22
23
    /**
24
     * Register helpers.
25
     *
26
     * @return void
27
     */
28
    public function registerHelpers()
29
    {
30
        $helpers = glob($this->packagePath('/Helpers/*.php'));
31
        foreach ($helpers as $helper) {
32
            if (file_exists($helper)) {
33
                require_once $helper;
34
            }
35
        }
36
    }
37
38
    /**
39
     * Bootstrap services.
40
     *
41
     * @return void
42
     */
43
    public function boot()
44
    {
45
        // load command files
46
        $this->registerCommands();
47
48
        // load publisher files
49
        $this->registerResources();
50
    }
51
52
53
    /**
54
     * Register commands.
55
     *
56
     * @return void
57
     */
58
    private function registerCommands()
59
    {
60
        $this->commands(Commands\ClearCommand::class);
0 ignored issues
show
Bug introduced by
The method commands() does not exist on Hayrullah\Helpers\HelperServiceProvider. ( Ignorable by Annotation )

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

60
        $this->/** @scrutinizer ignore-call */ 
61
               commands(Commands\ClearCommand::class);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        $this->commands(Commands\CacheCommand::class);
62
    }
63
64
    /**
65
     * Register resources.
66
     *
67
     * @return void
68
     */
69
    public function registerResources()
70
    {
71
        if ($this->isLumen() === false and function_exists('config_path')) {
72
            // function not available and 'publish' not relevant in Lumen
73
74
            $this->publishes(
0 ignored issues
show
Bug introduced by
The method publishes() does not exist on Hayrullah\Helpers\HelperServiceProvider. ( Ignorable by Annotation )

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

74
            $this->/** @scrutinizer ignore-call */ 
75
                   publishes(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
                [
76
                    $this->packagePath($this->HELPERS_PATH) => app_path('Helpers/vendor/hyr-helpers'),
77
                ],
78
                'hyr-helpers'
79
            );
80
        }
81
    }
82
83
    /**
84
     * @param $path
85
     *
86
     * @return string
87
     */
88
    private function packagePath($path)
89
    {
90
        return __DIR__."/$path";
91
    }
92
93
    /**
94
     * Check if package is running under Lumen app.
95
     *
96
     * @return bool
97
     */
98
    protected function isLumen()
99
    {
100
        return Str::contains($this->app->version(), 'Lumen') === true;
101
    }
102
}
103