Completed
Push — master ( 53e43c...41b088 )
by Vitaly
03:02
created

VirtualQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 1
cbo 3
dl 8
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A createStaticFields() 0 21 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
//[PHPCOMPRESSOR(remove,start)]
3
/**
4
 * Created by Vitaly Iegorov <[email protected]>.
5
 * on 22.03.16 at 15:46
6
 */
7
namespace samsoncms\api\generator;
8
9
use samsoncms\api\generator\metadata\Virtual;
10
use samsonphp\generator\Generator;
11
12
/**
13
 * Virtual entity query class generator.
14
 *
15
 * @package samsoncms\api\generator
16
 */
17
class VirtualQuery extends RealQuery
18
{
19
    /**
20
     * Query constructor.
21
     *
22
     * @param Generator $generator
23
     * @param           $metadata
24
     */
25 View Code Duplication
    public function __construct(Generator $generator, $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...
26
    {
27
        parent::__construct($generator, $metadata);
28
29
        $this->className .= 'Query';
30
        $this->parentClass = '\\' . \samsoncms\api\query\Entity::class;
31
        $this->entityClass = '\samsoncms\api\generated\\' . $metadata->entity;
32
    }
33
34
    /**
35
     * Class static fields generation part.
36
     *
37
     * @param Virtual $metadata Entity metadata
38
     */
39
    protected function createStaticFields($metadata)
40
    {
41
        $this->generator
42
            ->commentVar('array', 'Collection of real additional field names')
43
            ->defClassVar('$fieldRealNames', 'public static', $metadata->realNames)
44
            ->commentVar('array', 'Collection of additional field names')
45
            ->defClassVar('$fieldNames', 'public static', $metadata->fieldNames)
46
            // TODO: two above fields should be protected
47
            ->commentVar('array', 'Collection of navigation identifiers')
48
            ->defClassVar('$navigationIDs', 'protected static', array($metadata->entityID))
49
            ->commentVar('string', 'Entity full class name')
50
            ->defClassVar('$identifier', 'protected static', $this->entityClass)
51
            ->commentVar('array', 'Collection of localized additional fields identifiers')
52
            ->defClassVar('$localizedFieldIDs', 'protected static', $metadata->localizedFieldIDs)
53
            ->commentVar('array', 'Collection of NOT localized additional fields identifiers')
54
            ->defClassVar('$notLocalizedFieldIDs', 'protected static', $metadata->notLocalizedFieldIDs)
55
            ->commentVar('array', 'Collection of localized additional fields identifiers')
56
            ->defClassVar('$fieldIDs', 'protected static', $metadata->fields)
57
            ->commentVar('array', 'Collection of additional fields value column names')
58
            ->defClassVar('$fieldValueColumns', 'protected static', $metadata->allFieldValueColumns);
59
    }
60
}
61
//[PHPCOMPRESSOR(remove,end)]
62