Completed
Push — develop ( 4296b7...f9b993 )
by Abdelrahman
02:17 queued 01:13
created

ConsoleTools::publishesViews()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Support\Traits;
6
7
trait ConsoleTools
8
{
9
    /**
10
     * Publish package migrations.
11
     *
12
     * @return void
13
     */
14
    protected function publishesMigrations(string $package): void
15
    {
16
        $namespace = str_replace('laravel-', '', $package);
17
        $namespace = str_replace(['/', '\\', '.', '_'], '-', $namespace);
18
        $basePath = starts_with($package, 'cortex') ? $this->app->path($package)
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Deprecated Code introduced by
The function starts_with() has been deprecated with message: Str::startsWith() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
19
            : $this->app->basePath('vendor/'.$package);
20
21
        if (file_exists($path = $basePath.'/database/migrations')) {
22
            $stubs = $this->app['files']->glob($path.'/*.php.stub');
23
            $existing = $this->app['files']->glob($this->app->databasePath('migrations/'.$package.'/*.php'));
24
25
            $migrations = collect($stubs)->flatMap(function ($migration) use ($existing, $package) {
26
                $sequence = mb_substr(basename($migration), 0, 2);
27
                $match = collect($existing)->first(function ($item, $key) use ($migration, $sequence) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

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

Loading history...
28
                    return mb_strpos($item, str_replace(['.stub', $sequence], '', basename($migration))) !== false;
29
                });
30
31
                return [$migration => $this->app->databasePath('migrations/'.$package.'/'.($match ? basename($match) : date('Y_m_d_His', time() + $sequence).str_replace(['.stub', $sequence], '', basename($migration))))];
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 220 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
32
            })->toArray();
33
34
            $this->publishes($migrations, $namespace.'-migrations');
0 ignored issues
show
Bug introduced by
The method publishes() does not exist on Rinvex\Support\Traits\ConsoleTools. Did you maybe mean publishesMigrations()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
        }
36
    }
37
38
    /**
39
     * Publish package config.
40
     *
41
     * @return void
42
     */
43
    protected function publishesConfig(string $package): void
44
    {
45
        $namespace = str_replace('laravel-', '', $package);
46
        $namespace = str_replace(['/', '\\', '.', '_'], '-', $namespace);
47
        $basePath = starts_with($package, 'cortex') ? $this->app->path($package)
0 ignored issues
show
Deprecated Code introduced by
The function starts_with() has been deprecated with message: Str::startsWith() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
48
            : $this->app->basePath('vendor/'.$package);
49
50
        if (file_exists($path = $basePath.'/config/config.php')) {
51
            $this->publishes([$path => $this->app->configPath(str_replace('-', '.', $namespace).'.php')], $namespace.'-config');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
Bug introduced by
The method publishes() does not exist on Rinvex\Support\Traits\ConsoleTools. Did you maybe mean publishesMigrations()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
52
        }
53
    }
54
55
    /**
56
     * Publish package views.
57
     *
58
     * @return void
59
     */
60
    protected function publishesViews(string $package): void
61
    {
62
        $namespace = str_replace('laravel-', '', $package);
63
        $namespace = str_replace(['/', '\\', '.', '_'], '-', $namespace);
64
        $basePath = starts_with($package, 'cortex') ? $this->app->path($package)
0 ignored issues
show
Deprecated Code introduced by
The function starts_with() has been deprecated with message: Str::startsWith() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
65
            : $this->app->basePath('vendor/'.$package);
66
67
        if (file_exists($path = $basePath.'/resources/views')) {
68
            $this->publishes([$path => $this->app->resourcePath('views/vendor/'.$package)], $namespace.'-views');
0 ignored issues
show
Bug introduced by
The method publishes() does not exist on Rinvex\Support\Traits\ConsoleTools. Did you maybe mean publishesMigrations()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
69
        }
70
    }
71
72
    /**
73
     * Publish package lang.
74
     *
75
     * @return void
76
     */
77
    protected function publishesLang(string $package): void
78
    {
79
        $namespace = str_replace('laravel-', '', $package);
80
        $namespace = str_replace(['/', '\\', '.', '_'], '-', $namespace);
81
        $basePath = starts_with($package, 'cortex') ? $this->app->path($package)
0 ignored issues
show
Deprecated Code introduced by
The function starts_with() has been deprecated with message: Str::startsWith() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
82
            : $this->app->basePath('vendor/'.$package);
83
84
        if (file_exists($path = $basePath.'/resources/lang')) {
85
            $this->publishes([$path => $this->app->resourcePath('lang/vendor/'.$package)], $namespace.'-lang');
0 ignored issues
show
Bug introduced by
The method publishes() does not exist on Rinvex\Support\Traits\ConsoleTools. Did you maybe mean publishesMigrations()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
86
        }
87
    }
88
89
    /**
90
     * Register console commands.
91
     *
92
     * @return void
93
     */
94
    protected function registersCommands(): void
95
    {
96
        // Register artisan commands
97
        foreach ($this->commands as $key => $value) {
0 ignored issues
show
Bug introduced by
The property commands does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
98
            $this->app->singleton($value, $key);
99
        }
100
101
        $this->commands(array_values($this->commands));
0 ignored issues
show
Bug introduced by
The method commands() does not exist on Rinvex\Support\Traits\ConsoleTools. Did you maybe mean registersCommands()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
102
    }
103
}
104