Passed
Push — master ( 1438ee...6641ad )
by Quentin
06:42 queued 12s
created

CapsulesServiceProvider::testCanMakeCapsule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 21
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace A17\Twill;
4
5
use A17\Twill\Services\Capsules\HasCapsules;
6
use A17\Twill\Services\Capsules\Manager;
7
use A17\Twill\Services\Routing\HasRoutes;
8
use Illuminate\Foundation\Support\Providers\RouteServiceProvider;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, A17\Twill\RouteServiceProvider. Consider defining an alias.

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...
9
use Illuminate\Routing\Router;
10
11
class CapsulesServiceProvider extends RouteServiceProvider
12
{
13
    use HasRoutes, HasCapsules;
0 ignored issues
show
Bug introduced by
The trait A17\Twill\Services\Capsules\HasCapsules requires the property $command which is not provided by A17\Twill\CapsulesServiceProvider.
Loading history...
14
15
    protected $manager;
16
17
    protected function mergeTwillConfig()
18
    {
19
        $this->mergeConfigFrom(
20
            __DIR__ . '/../config/capsules.php',
21
            'twill.capsules'
22
        );
23
24
        $this->app
25
            ->make('config')
26
            ->set('twill.capsules.list', $this->getCapsuleList());
27
28
        $this->app->make('config')->set('twill.capsules.loaded', true);
29
    }
30
31
    public function register()
32
    {
33
        $this->registerConfig();
34
    }
35
36
    protected function registerConfig()
37
    {
38
        $this->registerManager();
39
40
        $this->mergeTwillConfig();
41
42
        $this->registerCapsules();
43
44
        $this->registerViewPaths();
45
    }
46
47
    public function registerCapsules()
48
    {
49
        $this->manager->getCapsuleList()->map(function ($capsule) {
50
            $this->registerCapsule($capsule);
51
        });
52
    }
53
54
    protected function registerCapsule($capsule)
55
    {
56
        $this->loadMigrationsFrom($capsule['migrations_dir']);
57
    }
58
59
    public function registerViewPaths()
60
    {
61
        $this->app->make('view')->addLocation(config('twill.capsules.path'));
62
    }
63
64
    public function registerManager()
65
    {
66
        $this->app->instance(
67
            'twill.capsules.manager',
68
            $this->manager = new Manager()
69
        );
70
    }
71
72
    public function testCanMakeCapsule()
73
    {
74
        $this->assertExitCodeIsGood(
0 ignored issues
show
Bug introduced by
The method assertExitCodeIsGood() does not exist on A17\Twill\CapsulesServiceProvider. Since you implemented __call, consider adding a @method annotation. ( 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
               assertExitCodeIsGood(
Loading history...
75
            $this->artisan('twill:make:capsule', [
0 ignored issues
show
Bug introduced by
The method artisan() does not exist on A17\Twill\CapsulesServiceProvider. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

75
            $this->/** @scrutinizer ignore-call */ 
76
                   artisan('twill:make:capsule', [
Loading history...
76
                'moduleName' => 'Cars',
77
                '--hasBlocks' => true,
78
                '--hasTranslation' => true,
79
                '--hasSlug' => true,
80
                '--hasMedias' => true,
81
                '--hasFiles' => true,
82
                '--hasPosition' => true,
83
                '--hasRevisions' => true,
84
            ])->run()
85
        );
86
87
        $this->assertFileExists(
0 ignored issues
show
Bug introduced by
The method assertFileExists() does not exist on A17\Twill\CapsulesServiceProvider. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

87
        $this->/** @scrutinizer ignore-call */ 
88
               assertFileExists(
Loading history...
88
            twill_path('Twill/Capsules/Cars/app/Models/Car.php')
89
        );
90
91
        $this->assertIsObject(
0 ignored issues
show
Bug introduced by
The method assertIsObject() does not exist on A17\Twill\CapsulesServiceProvider. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

91
        $this->/** @scrutinizer ignore-call */ 
92
               assertIsObject(
Loading history...
92
            $this->app->make('App\Twill\Capsules\Cars\Models\Car')
93
        );
94
    }
95
}
96