ValidToonFormat::message()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Squareetlabs\LaravelToon\Rules;
6
7
use Illuminate\Contracts\Validation\Rule;
8
use Squareetlabs\LaravelToon\Services\ToonService;
9
10
class ValidToonFormat implements Rule
0 ignored issues
show
Deprecated Code introduced by
The interface Illuminate\Contracts\Validation\Rule has been deprecated: see ValidationRule ( Ignorable by Annotation )

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

10
class ValidToonFormat implements /** @scrutinizer ignore-deprecated */ Rule

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
11
{
12
    public function __construct(
13
        private readonly ToonService $toon = new ToonService(),
14
    ) {}
15
16
    public function passes($attribute, $value): bool
17
    {
18
        try {
19
            $this->toon->decode((string)$value);
20
21
            return true;
22
        } catch (\Exception) {
23
            return false;
24
        }
25
    }
26
27
    public function message(): string
28
    {
29
        return 'El valor no es un formato TOON válido.';
30
    }
31
}
32
33