Passed
Push — master ( ef2b95...fb3c91 )
by Dan Michael O.
02:48
created

NotTrashed   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 3 2
A message() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Rules;
4
5
use App\Item;
6
use Illuminate\Contracts\Validation\Rule;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Validation\Rule was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class NotTrashed implements Rule
9
{
10
    protected $item;
11
12
    /**
13
     * Create a new rule instance.
14
     *
15
     * @param Item $item
16
     */
17
    public function __construct(Item $item = null)
18
    {
19
        $this->item = $item;
20
    }
21
22
    /**
23
     * Determine if the validation rule passes.
24
     *
25
     * @param  string  $attribute
26
     * @param  mixed  $value
27
     * @return bool
28
     */
29
    public function passes($attribute, $value)
30
    {
31
        return is_null($this->item) || !$this->item->trashed();
32
    }
33
34
    /**
35
     * Get the validation error message.
36
     *
37
     * @return string
38
     */
39
    public function message()
40
    {
41
        return sprintf(
42
            'Eksemplaret er slettet. Du kan gjenopprette det på <a href="%s">eksemplarsiden</a> hvis du ønsker det.',
43
            action('ItemsController@show', $this->item->id)
0 ignored issues
show
Bug introduced by
The function action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

43
            /** @scrutinizer ignore-call */ 
44
            action('ItemsController@show', $this->item->id)
Loading history...
44
        );
45
    }
46
}
47