AffiliateNetworkServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Padosoft\AffiliateNetwork;
4
5
use Illuminate\Support\ServiceProvider;
6
use Padosoft\AffiliateNetwork\Networks\Zanox;
7
use Padosoft\AffiliateNetwork\Networks\ZanoxEx;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Padosoft\AffiliateNetwork\ZanoxEx.

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...
8
9
class AffiliateNetworkServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Indicates if loading of the provider is deferred.
13
     *
14
     * @var bool
15
     */
16
    protected $defer = true;
17
18
    /**
19
     * Bootstrap the application events.
20
     *
21
     * @return void
22
     */
23
    public function boot()
24
    {
25
        $this->publishes([
26
            __DIR__ . '/config/config.php' => config_path('laravel-affiliate-network.php'),
27
        ], 'config');
28
    }
29
30
    /**
31
     * Register the service provider.
32
     *
33
     * @return void
34
     */
35
    public function register()
36
    {
37
38
        $this->app['NetworkManager']=$this->app->share(function ($app) {
0 ignored issues
show
Bug introduced by
The method share() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

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...
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
            return new NetworkManager();
40
        });
41
        $this->app->alias('NetworkManager', NetworkManager::class);
42
    }
43
44
    /**
45
     * Get the services provided by the provider.
46
     *
47
     * @return string[]
48
     */
49
    public function provides()
50
    {
51
        return [
52
            'NetworkManager'
53
        ];
54
    }
55
}
56