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 query class generator. |
15
|
|
|
* |
16
|
|
|
* @package samsoncms\api\generator |
17
|
|
|
*/ |
18
|
|
|
class TableVirtualQuery extends VirtualQuery |
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 . 'TableQuery'; |
32
|
|
|
$this->parentClass = '\\' . \samsoncms\api\query\EntityTable::class; |
33
|
|
|
$this->entityClass = '\samsoncms\api\generated\\' . $replaced . 'TableEntity'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Class uses generation part. |
38
|
|
|
* |
39
|
|
|
* @param \samsoncms\api\generator\metadata\VirtualMetadata $metadata Entity metadata |
40
|
|
|
*/ |
41
|
|
|
protected function createUses($metadata) |
42
|
|
|
{ |
43
|
|
|
$this->generator |
44
|
|
|
->newLine('use samsonframework\orm\QueryInterface;') |
45
|
|
|
->newLine('use samson\activerecord\dbQuery;') |
46
|
|
|
->newLine('use samsonframework\orm\ArgumentInterface;') |
47
|
|
|
->newLine(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Class constructor generation part. |
52
|
|
|
* |
53
|
|
|
* @param \samsoncms\api\generator\metadata\VirtualMetadata $metadata Entity metadata |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
protected function createConstructor($metadata) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$class = "\n\t" . '/**'; |
58
|
|
|
$class .= "\n\t" . ' * @param int $parentID Parent entity identifier'; |
59
|
|
|
$class .= "\n\t" . ' * @param QueryInterface $query Database query instance'; |
60
|
|
|
$class .= "\n\t" . ' * @param string $locale Localization identifier'; |
61
|
|
|
$class .= "\n\t" . ' */'; |
62
|
|
|
$class .= "\n\t" . 'public function __construct($parentID, QueryInterface $query = null, $locale = null)'; |
63
|
|
|
$class .= "\n\t" . '{'; |
64
|
|
|
$class .= "\n\t\t" . 'parent::__construct($parentID, isset($query) ? $query : new dbQuery(), $locale);'; |
65
|
|
|
$class .= "\n\t" . '}'; |
66
|
|
|
|
67
|
|
|
$this->generator->text($class); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
//[PHPCOMPRESSOR(remove,end)] |
71
|
|
|
|
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.