Errors   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 12
cp 0
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasError() 0 11 3
A getErrors() 0 11 3
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