Passed
Pull Request — master (#116)
by Zing
05:30
created

QueryBuilderServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder;
6
7
use Illuminate\Contracts\Support\DeferrableProvider;
8
use Illuminate\Foundation\Application as Laravel;
9
use Illuminate\Support\ServiceProvider;
10
use Laravel\Lumen\Application as Lumen;
0 ignored issues
show
Bug introduced by
The type Laravel\Lumen\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class QueryBuilderServiceProvider extends ServiceProvider implements DeferrableProvider
13
{
14 41
    public function boot(): void
15
    {
16 41
        if (! $this->app->runningInConsole()) {
17
            return;
18
        }
19
20 41
        if (! $this->app instanceof Laravel) {
21
            return;
22
        }
23
24 41
        $this->publishes([
25 41
            $this->getConfigPath() => config_path('query-builder.php'),
26 41
        ], 'config');
27 41
    }
28
29 41
    public function register(): void
30
    {
31 41
        $this->registerConfig();
32 41
        $this->app->singleton(
33 41
            QueryBuilderFactory::class,
34 41
            function (): QueryBuilderFactory {
35
                return new QueryBuilderFactory(config('query-builder.builders'));
36 41
            }
37
        );
38 41
    }
39
40 41
    protected function getConfigPath(): string
41
    {
42 41
        return __DIR__ . '/../config/query-builder.php';
43
    }
44
45 41
    protected function registerConfig(): void
46
    {
47 41
        if ($this->app instanceof Lumen) {
48
            $this->app->configure('query-builder');
0 ignored issues
show
Bug introduced by
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean configPath()? ( Ignorable by Annotation )

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

48
            $this->app->/** @scrutinizer ignore-call */ 
49
                        configure('query-builder');

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...
49
        }
50
51 41
        $this->mergeConfigFrom($this->getConfigPath(), 'query-builder');
52 41
    }
53
54
    /**
55
     * @return array<class-string<\Zing\QueryBuilder\QueryBuilderFactory>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string<\Zing...r\QueryBuilderFactory>> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string<\Zing\QueryBuilder\QueryBuilderFactory>>.
Loading history...
56
     */
57 1
    public function provides(): array
58
    {
59 1
        return [QueryBuilderFactory::class];
60
    }
61
}
62