Completed
Push — develop ( 8d2506...6ea8df )
by Abdelrahman
01:57
created

MigrateMakeCommand::getMigrationPath()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Console\Commands;
6
7
use Illuminate\Database\Console\Migrations\MigrateMakeCommand as BaseMigrateMakeCommand;
8
9
class MigrateMakeCommand extends BaseMigrateMakeCommand
10
{
11
    /**
12
     * The console command signature.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'make:migration {name : The name of the migration.}
17
        {--module= : The name of the module.}
18
        {--create= : The table to be created.}
19
        {--table= : The table to migrate.}
20
        {--path= : The location where the migration file should be created.}';
21
22
    /**
23
     * Get migration path (either specified by '--path' option or module location).
24
     *
25
     * @return string
26
     */
27
    protected function getMigrationPath()
28
    {
29
        if (! is_null($targetPath = $this->input->getOption('path'))) {
30
            return $this->laravel->basePath().'/'.$targetPath;
31
        }
32
33
        if (! is_null($module = $this->input->getOption('module')) && $this->laravel->files->exists($modulePath = $this->laravel->path().DIRECTORY_SEPARATOR.$module)) {
0 ignored issues
show
Bug introduced by
Accessing files on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 168 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...
34
            return $modulePath.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations';
35
        }
36
37
        return $this->laravel->databasePath().DIRECTORY_SEPARATOR.'migrations';
0 ignored issues
show
Bug introduced by
The method databasePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean basePath()?

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...
38
    }
39
}
40