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

TableVirtualCollection   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 2
lcom 1
cbo 3
dl 8
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A createConstructor() 0 17 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 PhpStorm.
5
 * User: nazarenko
6
 * Date: 29.03.2016
7
 * Time: 11:11
8
 */
9
namespace samsoncms\api\generator;
10
11
use samsonphp\generator\Generator;
12
13
/**
14
 * Table collection class generator.
15
 *
16
 * @package samsoncms\api\generator
17
 */
18
class TableVirtualCollection extends VirtualCollection
19
{
20
    /**
21
     * Query constructor.
22
     *
23
     * @param Generator $generator
24
     * @param           $metadata
25
     */
26 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...
27
    {
28
        parent::__construct($generator, $metadata);
29
30
        $this->className = rtrim($this->metadata->entity, 'Table') . 'TableCollection';
31
        $this->parentClass = rtrim($this->metadata->entity, 'Table') . 'TableQuery';
32
        $this->entityClass = '\samsoncms\api\generated\\' . rtrim($this->metadata->entity, 'Table') . 'TableEntity';
0 ignored issues
show
Bug introduced by
The property entityClass does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
    }
34
35
    /**
36
     * Class constructor generation part.
37
     *
38
     * @param \samsoncms\api\generator\metadata\Virtual $metadata Entity metadata
39
     */
40
    protected function createConstructor($metadata)
41
    {
42
        $class = "\n\t" . '/**';
43
        $class .= "\n\t" . ' * @param ViewInterface $renderer Renderer';
44
        $class .= "\n\t" . ' * @param int $parentID Parent entity identifier';
45
        $class .= "\n\t" . ' * @param QueryInterface $query Database query instance';
46
        $class .= "\n\t" . ' * @param string $locale Localization identifier';
47
        $class .= "\n\t" . ' */';
48
        $class .= "\n\t" . 'public function __construct(ViewInterface $renderer, $parentID, QueryInterface $query = null, $locale = null)';
49
        $class .= "\n\t" . '{';
50
        $class .= "\n\t\t" . '$this->renderer = $renderer;';
51
52
        $class .= "\n\t\t" . 'parent::__construct($parentID, isset($query) ? $query : new dbQuery(), $locale);';
53
        $class .= "\n\t" . '}';
54
55
        $this->generator->text($class);
56
    }
57
}
58
59
//[PHPCOMPRESSOR(remove,end)]
60