Passed
Push — master ( 2d2160...e800ea )
by Quetzy
01:06
created

AuditingServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the Laravel Auditing package.
4
 *
5
 * @author     Antério Vieira <[email protected]>
6
 * @author     Quetzy Garcia  <[email protected]>
7
 * @author     Raphael França <[email protected]>
8
 * @copyright  2015-2018
9
 *
10
 * For the full copyright and license information,
11
 * please view the LICENSE.md file that was distributed
12
 * with this source code.
13
 */
14
15
namespace OwenIt\Auditing;
16
17
use Illuminate\Support\ServiceProvider;
18
use OwenIt\Auditing\Console\AuditDriverMakeCommand;
19
use OwenIt\Auditing\Console\AuditTableCommand;
20
use OwenIt\Auditing\Console\InstallCommand;
21
use OwenIt\Auditing\Contracts\Auditor;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, OwenIt\Auditing\Auditor.

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...
22
23
class AuditingServiceProvider extends ServiceProvider
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $defer = true;
29
30
    /**
31
     * Bootstrap the service provider.
32
     *
33
     * @return void
34
     */
35 82
    public function boot()
36
    {
37 82
        $config = realpath(__DIR__.'/../config/audit.php');
38
39 82
        if ($this->app->runningInConsole()) {
40 82
            $this->publishes([
41 82
                $config => base_path('config/audit.php'),
42
            ]);
43
        }
44
45 82
        $this->mergeConfigFrom($config, 'audit');
46 82
    }
47
48
    /**
49
     * Register the service provider.
50
     *
51
     * @return void
52
     */
53 82
    public function register()
54
    {
55 82
        $this->commands([
56 82
            AuditTableCommand::class,
57
            AuditDriverMakeCommand::class,
58
            InstallCommand::class,
59
        ]);
60
61 82
        $this->app->singleton(Auditor::class, function ($app) {
62 40
            return new \OwenIt\Auditing\Auditor($app);
63 82
        });
64 82
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 1
    public function provides()
70
    {
71
        return [
72 1
            Auditor::class,
73
        ];
74
    }
75
}
76