Completed
Push — develop ( 814068...b3da70 )
by Abdelrahman
01:14
created

ConsoleTools   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A publishMigrations() 0 23 4
A publishConfig() 0 11 3
A publishViews() 0 11 3
A publishLang() 0 11 3
A registerCommands() 0 9 2
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 publishMigrations(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 = 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 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
It seems like publishes() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
35
        }
36
    }
37
38
    /**
39
     * Publish package config.
40
     *
41
     * @return void
42
     */
43
    protected function publishConfig(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
Bug introduced by
It seems like publishes() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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...
52
        }
53
    }
54
55
    /**
56
     * Publish package views.
57
     *
58
     * @return void
59
     */
60
    protected function publishViews(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
It seems like publishes() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
69
        }
70
    }
71
72
    /**
73
     * Publish package lang.
74
     *
75
     * @return void
76
     */
77
    protected function publishLang(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
It seems like publishes() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
86
        }
87
    }
88
89
    /**
90
     * Register console commands.
91
     *
92
     * @return void
93
     */
94
    protected function registerCommands(): 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 registerCommands()?

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