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

NotTelegramImage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 7
c 1
b 0
f 0
dl 0
loc 36
ccs 6
cts 9
cp 0.6667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A message() 0 3 1
A passes() 0 9 5
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