Completed
Push — master ( da6ff3...4f4aae )
by Vitaly
02:49
created

Collection::createDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
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
/**
10
 * Entity Query class generator.
11
 *
12
 * @package samsoncms\api\generator
13
 */
14
class Collection extends Query
15
{
16
    /**
17
     * Class uses generation part.
18
     *
19
     * @param Metadata $metadata Entity metadata
20
     */
21
    protected function createUses(Metadata $metadata)
22
    {
23
        $this->generator
24
            ->newLine('use samsonframework\core\ViewInterface;')
25
            ->newLine('use samsonframework\orm\QueryInterface;')
26
            ->newLine('use samsonframework\orm\ArgumentInterface;')
27
            ->newLine('use samson\activerecord\dbQuery;')
28
            ->newLine();
29
    }
30
31
    /**
32
     * Class definition generation part.
33
     *
34
     * @param Metadata $metadata Entity metadata
35
     */
36
    protected function createDefinition(Metadata $metadata)
37
    {
38
        $this->generator
39
            ->multiComment(array(
40
                'Class for rendering and querying and fetching "' . $metadata->entityRealName . '" instances from database',
41
                '@method ' . $metadata->entity . ' first();',
42
                '@method ' . $metadata->entity . '[] find();',
43
            ))
44
            ->defClass($metadata->entity . 'Collection', $metadata->entity .'Query')
45
            ->newLine('use \\'.\samsoncms\api\Renderable::class.';')
46
        ->newLine();
47
    }
48
49
    /**
50
     * Class constructor generation part.
51
     *
52
     * @param Metadata $metadata Entity metadata
53
     */
54 View Code Duplication
    protected function createConstructor(Metadata $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...
55
    {
56
        $class = "\n\t".'/**';
57
        $class .= "\n\t".' * @param ViewInterface $renderer Rendering instance';
58
        $class .= "\n\t" . ' * @param QueryInterface $query Database query instance';
59
        $class .= "\n\t".' * @param string $locale Localization identifier';
60
        $class .= "\n\t".' */';
61
        $class .= "\n\t" . 'public function __construct(ViewInterface $renderer, QueryInterface $query = null, $locale = null)';
62
        $class .= "\n\t".'{';
63
        $class .= "\n\t\t" . '$this->renderer = $renderer;';
64
        $class .= "\n\t\t" . 'parent::__construct(isset($query) ? $query : new dbQuery(), $locale);';
65
        $class .= "\n\t".'}';
66
67
        $this->generator->text($class);
68
    }
69
}
70
//[PHPCOMPRESSOR(remove,end)]
71