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) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
parent::__construct($generator, $metadata); |
29
|
|
|
|
30
|
|
|
$replaced = preg_replace('/Table$/i', '', $this->metadata->entity); |
31
|
|
|
$this->className = $replaced . 'TableCollection'; |
32
|
|
|
$this->parentClass = $replaced . 'TableQuery'; |
33
|
|
|
$this->entityClass = '\samsoncms\api\generated\\' . $replaced . 'TableEntity'; |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Class constructor generation part. |
38
|
|
|
* |
39
|
|
|
* @param \samsoncms\api\generator\metadata\VirtualMetadata $metadata Entity metadata |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
protected function createConstructor($metadata) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$class = "\n\t" . '/**'; |
44
|
|
|
$class .= "\n\t" . ' * @param ViewInterface $renderer Renderer'; |
45
|
|
|
$class .= "\n\t" . ' * @param int $parentID Parent entity identifier'; |
46
|
|
|
$class .= "\n\t" . ' * @param QueryInterface $query Database query instance'; |
47
|
|
|
$class .= "\n\t" . ' * @param string $locale Localization identifier'; |
48
|
|
|
$class .= "\n\t" . ' */'; |
49
|
|
|
$class .= "\n\t" . 'public function __construct(ViewInterface $renderer, $parentID, QueryInterface $query = null, $locale = null)'; |
50
|
|
|
$class .= "\n\t" . '{'; |
51
|
|
|
$class .= "\n\t\t" . '$this->renderer = $renderer;'; |
52
|
|
|
|
53
|
|
|
$class .= "\n\t\t" . 'parent::__construct($parentID, isset($query) ? $query : new dbQuery(), $locale);'; |
54
|
|
|
$class .= "\n\t" . '}'; |
55
|
|
|
|
56
|
|
|
$this->generator->text($class); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
//[PHPCOMPRESSOR(remove,end)] |
61
|
|
|
|
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.