GrammarServiceProvider::provides()   A
last analyzed

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 0
Metric Value
cc 1
eloc 1
c 0
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
namespace Djunehor\Grammar;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\ServiceProvider;
8
9
class GrammarServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     *
14
     * @param Filesystem $filesystem
15
     * @return void
16
     */
17 15
    public function boot(Filesystem $filesystem)
18
    {
19 15
        $publishTag = 'laravel-grammar';
20 15
        if (app() instanceof \Illuminate\Foundation\Application) {
21 15
            $this->publishes([
0 ignored issues
show
Bug introduced by
The method publishes() does not exist on Djunehor\Grammar\GrammarServiceProvider. ( Ignorable by Annotation )

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

21
            $this->/** @scrutinizer ignore-call */ 
22
                   publishes([

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...
22 15
                __DIR__.'/config/laravel-grammar.php' => config_path('laravel-grammar.php'),
23 15
            ], $publishTag);
24
25 15
            $this->publishes([
26 15
                __DIR__.'/database/migrations/2019_11_22_145649_create_words_table.php.stub' => $this->getMigrationFileName($filesystem),
27 15
            ], $publishTag);
28
29 15
            $this->publishes([
30 15
                __DIR__.'/database/seeds/LaravelGrammarSeeder.php.stub' => database_path('seeds/LaravelGrammarSeeder.php'), ],
31 15
                $publishTag);
32 15
            $this->publishes([
33 15
                __DIR__.'/database/seeds/entries.csv.zip' => database_path('seeds/entries.csv.zip'), ],
34 15
                $publishTag);
35
        }
36 15
    }
37
38
    /**
39
     * Register the application services.
40
     *
41
     * @return void
42
     */
43 15
    public function register()
44
    {
45
        $this->app->bind('laravel-grammar', function () {
0 ignored issues
show
Bug introduced by
The method bind() does not exist on Tests\Laravel\App. ( Ignorable by Annotation )

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

45
        $this->app->/** @scrutinizer ignore-call */ 
46
                    bind('laravel-grammar', function () {

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...
46 1
            return new Word();
47 15
        });
48 15
    }
49
50
    /**
51
     * Get the services provided by the provider.
52
     * @return array
53
     */
54 1
    public function provides() : array
55
    {
56 1
        return ['laravel-grammar'];
57
    }
58
59
    /**
60
     * Returns existing migration file if found, else uses the current timestamp.
61
     *
62
     * @param Filesystem $filesystem
63
     * @return string
64
     */
65 15
    protected function getMigrationFileName(Filesystem $filesystem): string
66
    {
67 15
        $timestamp = date('Y_m_d_His');
68
69 15
        return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR)
0 ignored issues
show
Bug introduced by
The method databasePath() does not exist on Tests\Laravel\App. ( Ignorable by Annotation )

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

69
        return Collection::make($this->app->/** @scrutinizer ignore-call */ databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR)

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...
70
            ->flatMap(function ($path) use ($filesystem) {
71 15
                return $filesystem->glob($path.'*_create_laravel_grammar_table.php');
72 15
            })->push($this->app->databasePath()."/migrations/{$timestamp}_create_laravel_grammar_table.php")
73 15
            ->first();
74
    }
75
}
76