Issues (2)

src/HashidServiceProvider.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Str;
7
use Laravel\Lumen\Application as LumenApplication;
8
9
class HashidServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register the service provider.
13
     *
14
     * @return void
15
     */
16 24
    public function register()
17
    {
18 24
        $this->setupAssets();
19
20 24
        $this->registerServices();
21 24
        $this->registerCommands();
22 12
    }
23
24
    /**
25
     * Setup package assets.
26
     *
27
     * @return void
28
     */
29 24
    protected function setupAssets()
30
    {
31 24
        if ($this->app instanceof LumenApplication) {
32
            $this->app->configure('hashid'); // @codeCoverageIgnore
0 ignored issues
show
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean configPath()? ( Ignorable by Annotation )

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

32
            $this->app->/** @scrutinizer ignore-call */ 
33
                        configure('hashid'); // @codeCoverageIgnore

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...
33
        }
34
35 24
        $this->mergeConfigFrom($config = __DIR__.'/../config/hashid.php', 'hashid');
36
37 24
        if ($this->app->runningInConsole()) {
38 24
            $this->publishes([$config => base_path('config/hashid.php')], 'hashid');
39
        }
40 12
    }
41
42
    /**
43
     * Register service bindings.
44
     *
45
     * @return void
46
     */
47 24
    protected function registerServices()
48
    {
49 12
        $this->app->singleton('hashid', function ($app) {
50 16
            return new HashidManager($app);
51 24
        });
52 24
        $this->app->alias('hashid', HashidManager::class);
53
54 24
        foreach ($this->getSingletonDrivers() as $class) {
55 24
            $this->app->singleton(
56 24
                $key = $this->getBindingKeyForDriver($class),
57 12
                function () use ($class) {
58 4
                    return new $class;
59 24
                }
60 12
            );
61 24
            $this->app->alias($key, $class);
62
        }
63
64 24
        foreach ($this->getNonSingletonDrivers() as $class) {
65 24
            $this->app->bind($this->getBindingKeyForDriver($class), $class);
66
        }
67 12
    }
68
69
    /**
70
     * Get singleton drivers classes.
71
     *
72
     * @return array
73
     */
74 24
    protected function getSingletonDrivers()
75
    {
76 12
        return [
77 24
            Base64Driver::class,
78 12
            Base64IntegerDriver::class,
79 12
            HexDriver::class,
80 12
            HexIntegerDriver::class,
81 12
        ];
82
    }
83
84
    /**
85
     * Get non-singleton drivers classes.
86
     *
87
     * @return array
88
     */
89 24
    protected function getNonSingletonDrivers()
90
    {
91 12
        return [
92 24
            Base62Driver::class,
93 12
            Base62IntegerDriver::class,
94 12
            HashidsDriver::class,
95 12
            HashidsHexDriver::class,
96 12
            HashidsIntegerDriver::class,
97 12
            HashidsStringDriver::class,
98 12
            OptimusDriver::class,
99 12
        ];
100
    }
101
102
    /**
103
     * Get the binding key for the driver class.
104
     *
105
     * @param  string  $class
106
     * @return string
107
     */
108 24
    protected function getBindingKeyForDriver($class)
109
    {
110 24
        return 'hashid.driver.'.Str::snake(
111 24
            preg_replace('#Driver$#', '', class_basename($class))
112 12
        );
113
    }
114
115
    /**
116
     * Register console commands.
117
     *
118
     * @return void
119
     */
120 24
    protected function registerCommands()
121
    {
122 24
        if ($this->app->runningInConsole()) {
123 24
            $this->commands([
124 24
                Console\AlphabetGenerateCommand::class,
125 12
                Console\OptimusGenerateCommand::class,
126 12
            ]);
127
        }
128 12
    }
129
}
130