Completed
Push — master ( 6b0d9f...50bca0 )
by Ben
05:27 queued 03:23
created

ServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @author Ben Rowe <[email protected]>
5
 * @license    http://www.opensource.org/licenses/mit-license.html MIT License
6
 */
7
8
namespace Benrowe\Laravel\Config;
9
10
use Illuminate\Support\ServiceProvider;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Benrowe\Laravel\Config\ServiceProvider.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
12
/**
13
 * Service Provider for Config
14
 *
15
 * @package Benrowe\Laravel\Config;
16
 */
17
class ServiceProvider extends ServiceProvider
18
{
19
    protected $defer = false;
20
21
    /**
22
     * Boot the configuration component
23
     *
24
     * @return nil
0 ignored issues
show
Documentation introduced by
Should the return type not be nil|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
25
     */
26
    public function boot()
27
    {
28
        # publish necessary files
29
        $this->publishes([
30
            __DIR__ . '/../config/config.php' => config_path('config.php'),
31
        ], 'config');
32
33
        $this->publishes([
34
            __DIR__.'/../migrations/' => database_path('migrations'),
35
        ], 'migrations');
36
    }
37
38
    /**
39
     * Register an instance of the component
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        $this->app->singleton('config', function () {
46
            return new Config();
47
        });
48
    }
49
50
    /**
51
     * Define the services this provider will build & provide
52
     *
53
     * @return array
54
     */
55
    public function provides()
56
    {
57
        return [
58
            'Benrowe\Laravel\Config\Config',
59
            'config'
60
        ];
61
    }
62
63
    /**
64
     * Get the configuration destination path
65
     *
66
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
67
     */
68
    protected function getConfigPath()
69
    {
70
        return ;
71
    }
72
}
73