Passed
Branch master (8cb5b2)
by Christopher
04:33 queued 12s
created

Mapper   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 89.66%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 81
ccs 26
cts 29
cp 0.8966
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMappingFiles() 0 7 1
A run() 0 27 5
A isMappingAlreadyRun() 0 7 2
A __construct() 0 8 1
1
<?php
0 ignored issues
show
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
2
namespace Triadev\Leopard\Business\Mapping;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use Illuminate\Filesystem\Filesystem;
5
use Triadev\Leopard\Contract\Repository\MappingLogRepositoryContract;
6
7
class Mapper
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
8
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class Mapper
Loading history...
9
    /** @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...
10
    private $filesystem;
1 ignored issue
show
Coding Style introduced by
Private member variable "filesystem" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "filesystem" must be prefixed with an underscore
Loading history...
11
    
12
    /** @var MappingLogRepositoryContract */
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...
13
    private $mappingLogRepository;
0 ignored issues
show
Coding Style introduced by
Private member variable "mappingLogRepository" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "mappingLogRepository" must be prefixed with an underscore
Loading history...
14
    
15
    /** @var array */
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...
16
    private $mappingLogs;
0 ignored issues
show
Coding Style introduced by
Private member variable "mappingLogs" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "mappingLogs" must be prefixed with an underscore
Loading history...
17
    
18
    /**
19
     * Mapper constructor.
20
     * @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...
Coding Style introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
21
     * @param MappingLogRepositoryContract $mappingLogRepository
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
22
     */
23 8
    public function __construct(Filesystem $filesystem, MappingLogRepositoryContract $mappingLogRepository)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 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...
24
    {
25 8
        $this->filesystem = $filesystem;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
26 8
        $this->mappingLogRepository = $mappingLogRepository;
27
    
28
        $this->mappingLogs = array_map(function ($log) {
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
29
            return $log['mapping'];
30 8
        }, $this->mappingLogRepository->all());
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
31 8
    }
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...
32
    
33
    /**
34
     * Run mappings
35
     *
36
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
37
     * @param string|null $index
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
38
     * @param string|null $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
39
     *
40
     * @throws \Throwable
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
41
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
42 8
    public function run(string $path, ?string $index = null, ?string $type = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$index" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$index"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$type" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$type"; expected 0 but found 1
Loading history...
43
    {
44 8
        $mappingFiles = $this->getMappingFiles($path);
45
        
46 8
        sort($mappingFiles);
47
        
48 8
        foreach ($mappingFiles as $mappingFile) {
49 8
            if ($this->isMappingAlreadyRun($mappingFile)) {
50
                continue;
51
            }
52
            
53 8
            $this->filesystem->requireOnce($path . DIRECTORY_SEPARATOR . $mappingFile . '.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
54
            
55
            /** @var Mapping $mapping */
0 ignored issues
show
Coding Style introduced by
Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
Loading history...
Coding Style introduced by
Block comments must be started with /*
Loading history...
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...
56 8
            $mapping = new $mappingFile();
57
            
58 8
            if ($index) {
59 1
                $mapping->setDocumentIndex($index);
60
            }
61
            
62 8
            if ($type) {
63 1
                $mapping->setDocumentType($type);
64
            }
65
            
66 8
            $mapping->map();
67
            
68 8
            $this->mappingLogRepository->add($mappingFile);
69
        }
0 ignored issues
show
Coding Style introduced by
End comment for long condition not found; expected "//end foreach"
Loading history...
70 8
    }
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 run()
Loading history...
71
    
72 8
    private function getMappingFiles(string $path): array
0 ignored issues
show
Coding Style introduced by
Private method name "Mapper::getMappingFiles" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
73
    {
74 8
        $files = $this->filesystem->glob($path . DIRECTORY_SEPARATOR . '*.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
75
        
76
        return array_map(function (string $file) {
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
77 8
            return str_replace('.php', '', basename($file));
78 8
        }, $files);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
79
    }
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 getMappingFiles()
Loading history...
80
    
81 8
    private function isMappingAlreadyRun(string $mapping) : bool
0 ignored issues
show
Coding Style introduced by
Private method name "Mapper::isMappingAlreadyRun" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
82
    {
83 8
        if (in_array($mapping, $this->mappingLogs)) {
84
            return true;
85
        }
86
        
87 8
        return false;
88
    }
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 isMappingAlreadyRun()
Loading history...
89
}
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...
90