Errors::hasError()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Yaro\Jarboe\Table\Fields\Traits;
4
5
use Illuminate\Support\ViewErrorBag;
6
7
trait Errors
8
{
9
    public function hasError(ViewErrorBag $errors, $locale = null): bool
10
    {
11
        if ($locale) {
12
            return $errors->has(sprintf('%s.%s', $this->name(), $locale));
13
        }
14
15
        if ($this->belongsToArray()) {
16
            return $errors->has($this->getDotPatternName());
17
        }
18
19
        return $errors->has($this->name());
20
    }
21
22
    public function getErrors(ViewErrorBag $errors, $locale = null): array
23
    {
24
        if ($locale) {
25
            return $errors->get(sprintf('%s.%s', $this->name(), $locale));
26
        }
27
28
        if ($this->belongsToArray()) {
29
            return $errors->get($this->getDotPatternName());
30
        }
31
32
        return $errors->get($this->name());
33
    }
34
35
    abstract public function name(string $name = null);
36
    abstract public function belongsToArray(): bool;
37
    abstract public function getDotPatternName(): string;
38
}
39