Completed
Push — master ( 49dc1a...1f58a4 )
by Yaro
06:59
created

Errors   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 75 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 24
loc 32
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasError() 12 12 3
A getErrors() 12 12 3
name() 0 1 ?
belongsToArray() 0 1 ?
getDotPatternName() 0 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Yaro\Jarboe\Table\Fields\Traits;
4
5
use Illuminate\Support\ViewErrorBag;
6
7
trait Errors
8
{
9 View Code Duplication
    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 View Code Duplication
    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);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
36
    abstract public function belongsToArray(): bool;
37
    abstract public function getDotPatternName(): string;
38
}
39