CategoryModel::getTermOrederField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Jidaikobo\Kontiki\Models;
4
5
use Illuminate\Database\Connection;
6
use Illuminate\Database\Query\Builder;
7
8
class CategoryModel extends BaseModel
9
{
10
    use Traits\CRUDTrait;
11
    use Traits\MetaDataTrait;
0 ignored issues
show
introduced by
The trait Jidaikobo\Kontiki\Models\Traits\MetaDataTrait requires some properties which are not provided by Jidaikobo\Kontiki\Models\CategoryModel: $meta_key, $meta_value
Loading history...
12
    use Traits\IndexTrait;
13
14
    protected string $table = 'terms';
15
16
    protected function defineFieldDefinitions(array $params = []): void
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

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

16
    protected function defineFieldDefinitions(/** @scrutinizer ignore-unused */ array $params = []): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        $id = 1;
19
        $fields = [
0 ignored issues
show
Unused Code introduced by
The assignment to $fields is dead and can be removed.
Loading history...
20
            'id' => $this->getIdField(),
21
            'name' => $this->getNameField(),
22
            'slug' => $this->getSlugField($id),
23
            'parent_id' => $this->getParentIdField($id),
24
            'term_order' => $this->getTermOrederField(),
25
        ];
26
27
        // $MetaData = $this->getMetaDataFieldDefinitions($params);
28
        // $this->fieldDefinitions = array_merge($fields, $MetaData);
29
    }
30
31
    private function getNameField(): array
32
    {
33
        return $this->getField(
34
            __('name'),
35
            [
36
                'rules' => ['required'],
37
                'display_in_list' => true
38
            ]
39
        );
40
    }
41
42
    private function getSlugField(?int $id): array
43
    {
44
        $slug_exp = __('slug_exp', 'The "slug" is used as the URL. It can contain alphanumeric characters and hyphens.');
45
46
        return $this->getField(
47
            __('slug'),
48
            [
49
                'description' => $slug_exp,
50
                'rules' => [
51
                    'required',
52
                    'slug',
53
                    ['lengthMin', 3],
54
                    ['unique', $this->table, 'slug', $id]
55
                ],
56
            ]
57
        );
58
    }
59
60
    private function getParentIdField($id): array
61
    {
62
        $type = false ? 'hidden' : 'select';
63
        return $this->getField(
64
            __('parent'),
65
            [
66
                'type' => $type,
67
                'options' => [],
68
                'default' => '',
69
                'rules' => [
70
                    'required',
71
                    'slug',
72
                    ['lengthMin', 3],
73
                    ['unique', $this->table, 'slug', $id]
74
                ],
75
            ]
76
        );
77
    }
78
79
    private function getTermOrederField(): array
80
    {
81
        return $this->getField(
82
            __('order'),
83
            [
84
                'display_in_list' => true
85
            ]
86
        );
87
    }
88
}
89