Cancelled
Branch master (8cb5b2)
by Christopher
04:16
created

Make::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 2
rs 9.9
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
2
namespace Triadev\Leopard\Console\Commands\Mapping;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use Illuminate\Console\ConfirmableTrait;
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Support\Composer;
7
use Illuminate\Support\Str;
8
9
class Make extends BaseCommand
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
10
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class Make
Loading history...
11
    use ConfirmableTrait;
12
    
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'triadev:mapping:make {mapping} {--model=}';
0 ignored issues
show
Coding Style introduced by
Protected member variable "signature" must contain a leading underscore
Loading history...
19
    
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Make a new mapping';
0 ignored issues
show
Coding Style introduced by
Protected member variable "description" must contain a leading underscore
Loading history...
26
    
27
    /** @var Filesystem */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
28
    private $filesystem;
0 ignored issues
show
Coding Style introduced by
Private member variable "filesystem" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "filesystem" must be prefixed with an underscore
Loading history...
29
    
30
    /** @var Composer */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
31
    private $composer;
0 ignored issues
show
Coding Style introduced by
Private member variable "composer" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "composer" must be prefixed with an underscore
Loading history...
32
    
33
    /**
34
     * Make constructor.
35
     * @param Filesystem $filesystem
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
36
     * @param Composer $composer
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
37
     */
38 132
    public function __construct(Filesystem $filesystem, Composer $composer)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
39
    {
40 132
        parent::__construct();
41
        
42 132
        $this->filesystem = $filesystem;
43 132
        $this->composer = $composer;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44 132
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
45
    
46
    /**
47
     * Execute the console command.
48
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
49 2
    public function handle()
50
    {
51 2
        $mapping = $this->formatMappingName($this->argument('mapping'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('mapping') can also be of type null and string[]; however, parameter $mapping of Triadev\Leopard\Console\...ke::formatMappingName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

51
        $mapping = $this->formatMappingName(/** @scrutinizer ignore-type */ $this->argument('mapping'));
Loading history...
52
        
53 2
        $model = $this->option('model') ?
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
Expected 1 space after "?"; newline found
Loading history...
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement must be declared on a single line
Loading history...
54 1
            $this->formatModelName($this->option('model')) :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
55 2
            null;
56
        
57 2
        $this->filesystem->put(
58 2
            $this->buildMappingFilePath($mapping),
59 2
            $this->buildMapping(
60 2
                $this->getDefaultStub(),
61 2
                $mapping,
62 2
                $model
63
            )
64
        );
65
        
66 2
        $this->composer->dumpAutoloads();
67 2
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end handle()
Loading history...
68
    
69 2
    private function formatMappingName(string $mapping) : string
0 ignored issues
show
Coding Style introduced by
Private method name "Make::formatMappingName" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
70
    {
71 2
        return trim(Str::studly($mapping));
72
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end formatMappingName()
Loading history...
73
    
74 1
    private function formatModelName(string $model) : string
0 ignored issues
show
Coding Style introduced by
Private method name "Make::formatModelName" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
75
    {
76 1
        return trim($model);
77
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end formatModelName()
Loading history...
78
    
79 2
    private function getDefaultStub() : string
0 ignored issues
show
Coding Style introduced by
Private method name "Make::getDefaultStub" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
80
    {
81 2
        return $this->filesystem->get(__DIR__ . DIRECTORY_SEPARATOR . 'default.stub');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
82
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getDefaultStub()
Loading history...
83
    
84 2
    private function buildMappingFilePath(string $mapping) : string
0 ignored issues
show
Coding Style introduced by
Private method name "Make::buildMappingFilePath" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
85
    {
86 2
        return $this->getMappingPath() . DIRECTORY_SEPARATOR . $mapping . '.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
87
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end buildMappingFilePath()
Loading history...
88
    
89 2
    private function buildMapping(string $stub, string $mapping, ?string $model) : string
0 ignored issues
show
Coding Style introduced by
Private method name "Make::buildMapping" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
90
    {
91 2
        $stub = str_replace('DefaultClass', $mapping, $stub);
92
        
93 2
        if ($model) {
94 1
            $stub = str_replace('DefaultModel', $model, $stub);
95
        }
96
        
97 2
        return $stub;
98
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end buildMapping()
Loading history...
99
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
100