ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace sixlive\Laravel\JsonSchemaAssertions;
4
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Support\ServiceProvider as Provider;
7
use Illuminate\Testing\TestResponse;
8
use sixlive\JsonSchemaAssertions\SchemaAssertion;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, sixlive\Laravel\JsonSche...ertions\SchemaAssertion.

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
10
class ServiceProvider extends Provider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15 5
    public function boot()
16
    {
17 5
        if ($this->app->runningInConsole()) {
18 5
            $this->publishes([
19 5
                __DIR__.'/../config/config.php' => config_path('json-schema-assertions.php'),
20 5
            ], 'config');
21
        }
22
23
        TestResponse::macro('assertJsonSchema', function ($schema) {
24 5
            $basePath = Config::get('json-schema-assertions.schema_base_path');
25
26 5
            (new SchemaAssertion($basePath))
27 5
              ->schema($schema)
28 5
              ->assert($this->content());
0 ignored issues
show
Bug introduced by
The method content() does not seem to exist on object<sixlive\Laravel\J...rtions\ServiceProvider>.

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...
29
30 4
            return $this;
31 5
        });
32 5
    }
33
34
    /**
35
     * Register the application services.
36
     */
37 5
    public function register()
38
    {
39 5
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'json-schema-assertions');
40 5
    }
41
}
42