Issues (27)

src/FastapiServiceProvider.php (3 issues)

1
<?php
2
3
namespace Larafast\Fastapi;
4
5
use Illuminate\Database\Migrations\MigrationCreator;
6
use Illuminate\Support\ServiceProvider;
7
use Larafast\Fastapi\Console\Commands\ControllerMakeCommand;
8
use Larafast\Fastapi\Console\Commands\FactoryMakeCommand;
9
use Larafast\Fastapi\Console\Commands\Fastapi;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Larafast\Fastapi\Fastapi. 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...
10
use Larafast\Fastapi\Console\Commands\MigrateMakeCommand;
11
use Larafast\Fastapi\Console\Commands\ModelMakeCommand;
12
use Larafast\Fastapi\Console\Commands\RequestMakeCommand;
13
use Larafast\Fastapi\Console\Commands\ResourceMakeCommand;
14
15
class FastapiServiceProvider extends ServiceProvider
16
{
17
18
    protected $commands = [
19
        ControllerMakeCommand::class,
20
        FactoryMakeCommand::class,
21
        Fastapi::class,
22
        MigrateMakeCommand::class,
23
        ModelMakeCommand::class,
24
        RequestMakeCommand::class,
25
        ResourceMakeCommand::class,
26
    ];
27
28
    /**
29
     * Bootstrap the application services.
30
     */
31
    public function boot()
32
    {
33
34
        $this->publishes([
35
            __DIR__ . '/../config/config.php' => config_path('fastApi.php'),
36
        ], 'fastApi');
37
38
39
        // $this->publishes([
40
        //     __DIR__ . '/../resources/stubs' => resource_path('stubs')
41
        // ], 'fastApi');
42
43
44
        $this->app->when(MigrationCreator::class)
45
            ->needs('$customStubPath')
46
            ->give(function ($app) {
0 ignored issues
show
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

46
            ->give(function (/** @scrutinizer ignore-unused */ $app) {

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

Loading history...
47
                return base_path('vendor/larafast/fastapi/resources/stubs');
48
            });
49
50
        $this->commands($this->commands);
51
    }
52
53
    /**
54
     * Register the application services.
55
     */
56
    public function register()
57
    {
58
        // Automatically apply the package configuration
59
        $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'fastApi');
60
61
        // Register the main class to use with the facade
62
        $this->app->singleton('fastApi', function () {
63
            return new Fastapi;
0 ignored issues
show
The call to Larafast\Fastapi\Console...\Fastapi::__construct() has too few arguments starting with files. ( Ignorable by Annotation )

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

63
            return /** @scrutinizer ignore-call */ new Fastapi;

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
64
        });
65
    }
66
}
67