Passed
Push — develop ( 6dcea6...5ae9a6 )
by Septianata
16:24
created

NotTelegramImage::passes()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5.2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6111
cc 5
nc 4
nop 2
crap 5.2
1
<?php
2
3
namespace App\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class NotTelegramImage implements Rule
8
{
9
    /**
10
     * Create a new instance class.
11
     *
12
     * @param  bool  $mustBeString
13
     * @param  bool  $canBeNull
14
     * @return void
15
     */
16 2
    public function __construct(
17
        protected bool $mustBeString = true,
18
        protected bool $canBeNull = false
19
    ) {
20
        //
21 2
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26 2
    public function passes($attribute, $value)
27
    {
28 2
        if (is_null($value) && $this->canBeNull) {
29
            return true;
30
        }
31
32
        return
33 2
            ($this->mustBeString ? is_string($value) : true) &&
34 2
            $value !== '%%%_IMAGE_%%%';
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function message()
41
    {
42
        return trans('validation.not_telegram_image');
43
    }
44
}
45