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

Mapping::setDocumentIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Business\Mapping;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use Illuminate\Database\Eloquent\Model;
5
use Triadev\Leopard\Business\Helper\IsModelSearchable;
6
use Triadev\Leopard\Facade\Leopard;
7
use Triadev\Leopard\Searchable;
8
9
abstract class Mapping
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 Mapping
Loading history...
11
    use IsModelSearchable;
12
    
13
    /** @var Model|Searchable */
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...
14
    protected $model;
0 ignored issues
show
Coding Style introduced by
Protected member variable "model" must contain a leading underscore
Loading history...
15
    
16
    /** @var string */
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...
17
    protected $index;
0 ignored issues
show
Coding Style introduced by
Protected member variable "index" must contain a leading underscore
Loading history...
18
    
19
    /** @var string */
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...
20
    protected $type;
0 ignored issues
show
Coding Style introduced by
Protected member variable "type" must contain a leading underscore
Loading history...
21
    
22
    /**
23
     * Mapping constructor.
24
     *
25
     * @throws \InvalidArgumentException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
26
     */
27 11
    public function __construct()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
29 11
        $modelClass = $this->model();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
30 11
        $this->model = new $modelClass();
31
    
32 11
        $this->isModelSearchable($this->model);
33 10
    }
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...
34
    
35
    /**
36
     * Get mapped eloquent model class
37
     *
38
     * @return string
39
     */
40
    abstract public function model() : string;
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
41
    
42
    /**
43
     * Map
44
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
45
    abstract public function map();
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
46
    
47
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
48
     * @param string $index
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
49
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
50 2
    public function setDocumentIndex(string $index): void
51
    {
52 2
        $this->index = $index;
53 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 setDocumentIndex()
Loading history...
54
    
55
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
56
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
57
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
58 2
    public function setDocumentType(string $type): void
59
    {
60 2
        $this->type = $type;
61 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 setDocumentType()
Loading history...
62
    
63
    /**
64
     * Get es index
65
     *
66
     * @return string
67
     */
68 10
    public function getDocumentIndex() : string
69
    {
70 10
        if ($this->index) {
71 2
            return $this->index;
72
        }
73
        
74 9
        return $this->model->getDocumentIndex() ?: Leopard::getEsDefaultIndex();
1 ignored issue
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Bug Best Practice introduced by
The expression return $this->model->get...rd::getEsDefaultIndex() could return the type Illuminate\Database\Eloquent\Builder which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
75
    }
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 getDocumentIndex()
Loading history...
76
    
77
    /**
78
     * Get es type
79
     *
80
     * @return string
81
     */
82 9
    public function getDocumentType() : string
83
    {
84 9
        return $this->type ?: $this->model->getDocumentType();
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->type ?: $t...odel->getDocumentType() could return the type Illuminate\Database\Eloquent\Builder which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
85
    }
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 getDocumentType()
Loading history...
86
}
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...
87