Passed
Pull Request — 2.x (#729)
by Antonio Carlos
06:30
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 map(Router $router)
60
    {
61
        $this->manager
62
            ->getCapsuleList()
63
            ->each(function ($capsule) use ($router) {
64
                $this->registerCapsuleRoutes($router, $capsule);
65
            });
66
    }
67
68
    public function registerViewPaths()
69
    {
70
        $this->app->make('view')->addLocation(config('twill.capsules.path'));
71
    }
72
73
    public function registerManager()
74
    {
75
        $this->app->instance(
76
            'twill.capsules.manager',
77
            $this->manager = new Manager()
78
        );
79
    }
80
81
    public function testCanMakeCapsule()
82
    {
83
        $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

83
        $this->/** @scrutinizer ignore-call */ 
84
               assertExitCodeIsGood(
Loading history...
84
            $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

84
            $this->/** @scrutinizer ignore-call */ 
85
                   artisan('twill:make:capsule', [
Loading history...
85
                'moduleName' => 'Cars',
86
                '--hasBlocks' => true,
87
                '--hasTranslation' => true,
88
                '--hasSlug' => true,
89
                '--hasMedias' => true,
90
                '--hasFiles' => true,
91
                '--hasPosition' => true,
92
                '--hasRevisions' => true,
93
            ])->run()
94
        );
95
96
        $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

96
        $this->/** @scrutinizer ignore-call */ 
97
               assertFileExists(
Loading history...
97
            twill_path('Twill/Capsules/Cars/app/Data/Models/Car.php')
98
        );
99
100
        $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

100
        $this->/** @scrutinizer ignore-call */ 
101
               assertIsObject(
Loading history...
101
            $this->app->make('App\Twill\Capsules\Cars\Data\Models\Car')
102
        );
103
    }
104
}
105