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

NotTelegramImage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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