Completed
Push — dev ( 170d5a...aca493 )
by Tristan
06:11
created

ContainsObjectWithRelationRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 34
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 4 1
A message() 0 3 1
A __construct() 0 3 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
8
class ContainsObjectWithRelationRule implements Rule
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ContainsObjectWithRelationRule
Loading history...
9
{
10
11
    protected $validator;
12
13
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $validator should have a doc-comment as per coding-style.
Loading history...
14
     * Create a new rule instance.
15
     *
16
     * @param  App\Models\Applicant  $applicant
0 ignored issues
show
Bug introduced by
The type App\Services\Validation\Rules\App\Models\Applicant was not found. Did you mean App\Models\Applicant? If so, make sure to prefix the type with \.
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Doc comment for parameter $applicant does not match actual variable name $validator
Loading history...
17
     * @param  string  $relation
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 15 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Superfluous parameter comment
Loading history...
18
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
19
     */
20
    public function __construct($validator)
21
    {
22
        $this->validator = $validator;
23
    }
24
25
    /**
26
     * This check passes if the $value is a collection which contains an object
27
     *  with a relationName relation equal to relationValue
28
     * @param  [type] $attribute [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
29
     * @param  [type] $value     [description]
30
     * @return boolean            [description]
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
31
     */
32
    public function passes($attribute, $value)
33
    {
34
        return $value->contains(function ($object) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
35
            $object->getRelationValue($this->relationName)->is($this->relationValue);
0 ignored issues
show
Bug Best Practice introduced by
The property relationName does not exist on App\Services\Validation\...sObjectWithRelationRule. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property relationValue does not exist on App\Services\Validation\...sObjectWithRelationRule. Did you maybe forget to declare it?
Loading history...
36
        });
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...
37
    }
38
39
    public function message()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function message()
Loading history...
40
    {
41
        return Lang::trans('validation.contains_object_with_relation', ['relation' => $this->relationName]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...> $this->relationName)) also could return the type array which is incompatible with the return type mandated by Illuminate\Contracts\Validation\Rule::message() of string.
Loading history...
Bug Best Practice introduced by
The property relationName does not exist on App\Services\Validation\...sObjectWithRelationRule. Did you maybe forget to declare it?
Loading history...
42
    }
43
}
44