TabsTrait::moveDefaultTabToEnd()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 6
rs 10
1
<?php
2
3
namespace Yaro\Jarboe\Table\CrudTraits;
4
5
use Yaro\Jarboe\Table\Fields\AbstractField;
0 ignored issues
show
Bug introduced by
The type Yaro\Jarboe\Table\Fields\AbstractField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
trait TabsTrait
8
{
9
    public function getTabErrorsCount($tabTitle, $errors)
10
    {
11
        $count = 0;
12
        $tabs = $this->getTabs();
13
        $fields = $tabs[$tabTitle];
14
15
        foreach ($fields as $field) {
16
            $count += count($errors->get($field->name()));
17
        }
18
19
        return $count;
20
    }
21
22
    public function getTabs($skipHiddenType = null)
23
    {
24
        $tabs = [];
25
        foreach ($this->getFields() as $field) {
0 ignored issues
show
Bug introduced by
It seems like getFields() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
        foreach ($this->/** @scrutinizer ignore-call */ getFields() as $field) {
Loading history...
26
            if ($skipHiddenType && $field->hidden($skipHiddenType)) {
27
                continue;
28
            }
29
            $tabs[$field->getTab()][] = $field;
30
        }
31
32
        $this->moveDefaultTabToEnd($tabs);
33
34
        return $tabs;
35
    }
36
37
    private function moveDefaultTabToEnd(&$tabs)
38
    {
39
        $defaultTab = AbstractField::DEFAULT_TAB_IDENT;
40
        if (!array_key_exists($defaultTab, $tabs)) {
41
            return;
42
        }
43
44
        $defaultTabFields = $tabs[$defaultTab];
45
        unset($tabs[$defaultTab]);
46
        $tabs[$defaultTab] = $defaultTabFields;
47
    }
48
}
49