EntityManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 29.63 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A generateEntity() 0 8 1
A generateField() 12 12 1
A editField() 12 12 1
A deleteField() 0 7 1
A reOrderField() 0 7 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 Hechoenlaravel\JarvisFoundation\Traits;
4
5
/**
6
 * Trait EntityManager
7
 * Use it to Manage Entities and fields in your classes
8
 * @author Jose Luis Fonseca <[email protected]>
9
 * @package Hechoenlaravel\JarvisFoundation\Traits
10
 */
11
trait EntityManager
12
{
13
    use DispatchesCommands;
14
15
    /**
16
     * Generate an entity
17
     * @param array $data
18
     * @return mixed
19
     */
20
    public function generateEntity(array $data = [])
21
    {
22
        return $this->execute('Hechoenlaravel\JarvisFoundation\EntityGenerator\EntityGeneratorCommand',
23
            'Hechoenlaravel\JarvisFoundation\EntityGenerator\Handler\EntityGeneratorHandler', $data, [
24
                'Hechoenlaravel\JarvisFoundation\EntityGenerator\Middleware\EntityGeneratorValidator',
25
                'Hechoenlaravel\JarvisFoundation\EntityGenerator\Middleware\SetPrefixAndTableName'
26
            ]);
27
    }
28
29
    /**
30
     * Generate a field for an entity
31
     * @param array $data
32
     * @return mixed
33
     */
34 View Code Duplication
    public function generateField(array $data = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        return $this->execute('Hechoenlaravel\JarvisFoundation\FieldGenerator\CreateFieldCommand',
37
            'Hechoenlaravel\JarvisFoundation\FieldGenerator\Handler\CreateFieldCommandHandler', $data, [
38
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\FieldGeneratorValidator',
39
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\FieldTypeValidator',
40
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\FieldOrderSetter',
41
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\CreateTheFieldSlug',
42
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\CallPreAssignEventOnField',
43
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\FieldOptionsSerializer',
44
            ]);
45
    }
46
47
    /**
48
     * Edit a field
49
     * @param array $data
50
     * @return mixed
51
     */
52 View Code Duplication
    public function editField(array $data = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        return $this->execute('Hechoenlaravel\JarvisFoundation\FieldGenerator\EditFieldCommand',
55
            'Hechoenlaravel\JarvisFoundation\FieldGenerator\Handler\EditFieldCommandHandler', $data, [
56
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\EditFieldTypeValidator',
57
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\CreateTheFieldSlug',
58
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\SetFieldTypeOnEdit',
59
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\SetCommandDataFromEditFieldModel',
60
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\CallPreAssignEventOnField',
61
                'Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware\FieldOptionsSerializer',
62
            ]);
63
    }
64
65
    /**
66
     * Delete a Field
67
     * @param $id
68
     * @return mixed
69
     */
70
    public function deleteField($id)
71
    {
72
        return $this->execute('Hechoenlaravel\JarvisFoundation\FieldGenerator\DeleteFieldCommand',
73
            'Hechoenlaravel\JarvisFoundation\FieldGenerator\Handler\DeleteFieldCommandHandler', [
74
            'id' => $id
75
        ]);
76
    }
77
78
    /**
79
     * Re order from a field
80
     * @param $id
81
     * @param $order
82
     * @return mixed
83
     */
84
    public function reOrderField($items)
85
    {
86
        return $this->execute('Hechoenlaravel\JarvisFoundation\FieldGenerator\ReOrderFieldCommand',
87
            'Hechoenlaravel\JarvisFoundation\FieldGenerator\Handler\ReOrderFieldCommandHandler', [
88
                'fields' => $items
89
            ]);
90
    }
91
}
92