RealEntity   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 39.08 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 34
loc 87
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createDefinition() 0 6 1
A createConstants() 0 21 2
B createStaticFields() 26 26 1
A createFields() 8 8 2

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
//[PHPCOMPRESSOR(remove,start)]
3
/**
4
 * Created by Vitaly Iegorov <[email protected]>.
5
 * on 22.03.16 at 17:50
6
 */
7
namespace samsoncms\api\generator;
8
9
use samsoncms\api\generator\metadata\RealMetadata;
10
use samsoncms\api\Record;
11
12
/**
13
 * Real database instances class generator.
14
 *
15
 * @package samsoncms\api\generator
16
 */
17
class RealEntity extends Generic
18
{
19
    /**
20
     * Class definition generation part.
21
     *
22
     * @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata
23
     */
24
    protected function createDefinition($metadata)
25
    {
26
        $this->generator
27
            ->multiComment(array('"' . $metadata->entity . '" database entity class'))
28
            ->defClass($this->className, '\\' . \samsonframework\orm\Record::class);
29
    }
30
31
    /**
32
     * Class constants generation part.
33
     *
34
     * @param RealMetadata $metadata Entity metadata
35
     */
36
    protected function createConstants($metadata)
37
    {
38
        $this->generator
39
            ->commentVar('string', 'Entity full class name, use ::class instead')
40
            ->defClassConst('ENTITY', $metadata->entityClassName)
41
            ->commentVar('string', 'Entity manager full class name')
42
            ->defClassConst('MANAGER', $metadata->entityClassName . 'Query')
43
            // FIXME: Only related to cms api tables
44
            ->commentVar('string', 'Primary field name')
45
            ->defClassConst('F_PRIMARY', $metadata->primaryField)
46
            ->commentVar('string', 'Deletion field name')
47
            ->defClassConst('F_DELETION', 'Active')
48
        ;
49
50
        // Create all entity fields constants storing each additional field metadata
51
        foreach ($metadata->fields as $fieldID => $fieldName) {
52
            $this->generator
53
                ->commentVar('string', $fieldName . ' entity field name')
54
                ->defClassConst('F_' . $fieldName, $fieldName);
55
        }
56
    }
57
58
    /**
59
     * Class static fields generation part.
60
     *
61
     * @param RealMetadata $metadata Entity metadata
62
     */
63 View Code Duplication
    protected function createStaticFields($metadata)
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...
64
    {
65
        $this->generator
66
            ->commentVar('array', '@deprecated Old ActiveRecord data')
67
            ->defClassVar('$_sql_select', 'public static ', $metadata->arSelect)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...ericMetadata::$arSelect has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
68
            ->commentVar('array', '@deprecated Old ActiveRecord data')
69
            ->defClassVar('$_attributes', 'public static ', $metadata->arAttributes)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...Metadata::$arAttributes has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
70
            ->commentVar('array', '@deprecated Old ActiveRecord data')
71
            ->defClassVar('$_types', 'public static ', $metadata->arTypes)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...nericMetadata::$arTypes has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
72
            ->commentVar('array', '@deprecated Old ActiveRecord data')
73
            ->defClassVar('$_table_attributes', 'public static ', $metadata->arTableAttributes)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...ata::$arTableAttributes has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
74
            ->commentVar('array', '@deprecated Old ActiveRecord data')
75
            ->defClassVar('$_map', 'public static ', $metadata->arMap)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...GenericMetadata::$arMap has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
76
            ->commentVar('array', '@deprecated Old ActiveRecord data')
77
            ->defClassVar('$_sql_from', 'public static ', $metadata->arFrom)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...enericMetadata::$arFrom has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
78
            ->commentVar('array', '@deprecated Old ActiveRecord data')
79
            ->defClassVar('$_own_group', 'public static ', $metadata->arGroup)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...nericMetadata::$arGroup has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
80
            ->commentVar('array', '@deprecated Old ActiveRecord data')
81
            ->defClassVar('$_relation_alias', 'public static ', $metadata->arRelationAlias)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...adata::$arRelationAlias has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
82
            ->commentVar('array', '@deprecated Old ActiveRecord data')
83
            ->defClassVar('$_relation_type', 'public static ', $metadata->arRelationType)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...tadata::$arRelationType has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
84
            ->commentVar('array', '@deprecated Old ActiveRecord data')
85
            ->defClassVar('$_relations', 'public static ', $metadata->arRelations)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...cMetadata::$arRelations has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
86
            ->commentVar('array', '@deprecated Old ActiveRecord data')
87
            ->defClassVar('$fieldIDs', 'public static ', $metadata->fields);
88
    }
89
90
    /**
91
     * Class fields generation part.
92
     *
93
     * @param RealMetadata $metadata Entity metadata
94
     */
95 View Code Duplication
    protected function createFields($metadata)
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...
96
    {
97
        foreach ($metadata->fields as $fieldID => $fieldName) {
98
            $this->generator
99
                ->commentVar($metadata->types[$fieldID], $fieldName . ' entity field')
100
                ->defClassVar('$' . $fieldName, 'public');
101
        }
102
    }
103
}
104
//[PHPCOMPRESSOR(remove,end)]
105