Gallery::createUses()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 7
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 gallery class generator.
11
 *
12
 * @package samsoncms\api\generator
13
 */
14
class Gallery extends Generic
15
{
16
    /**
17
     * Class uses generation part.
18
     *
19
     * @param \samsoncms\api\generator\metadata\GalleryMetadata $metadata Entity metadata
20
     */
21
    protected function createUses($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 \samsoncms\api\generator\metadata\GalleryMetadata $metadata Entity metadata
35
     */
36
    protected function createDefinition($metadata)
37
    {
38
        $this->generator
39
            ->multiComment(array(
40
                'Class for rendering "' . $metadata->realName . '" gallery',
41
                '@deprecated Use entity *Gallery methods instead'
42
            ))
43
            ->defClass($metadata->entity, '\\'.\samsoncms\api\Gallery::class)
44
            ->newLine('use \\'.\samsoncms\api\Renderable::class.';')
45
        ->newLine();
46
    }
47
48
    /**
49
     * Class constructor generation part.
50
     *
51
     * @param \samsoncms\api\generator\metadata\GalleryMetadata $metadata Entity metadata
52
     */
53
    protected function createConstructor($metadata)
54
    {
55
        $class = "\n\t" . '/**';
56
        $class .= "\n\t" . ' * @param ViewInterface $renderer Rendering instance';
57
        $class .= "\n\t" . ' * @param ' . $metadata->parentClassName . ' $entity Parent entity';
58
        $class .= "\n\t" . ' * @param QueryInterface $query Database query instance';
59
        $class .= "\n\t" . ' */';
60
        $class .= "\n\t" . 'public function __construct(ViewInterface $renderer, ' . $metadata->parentClassName . ' $entity, QueryInterface $query = null)';
61
        $class .= "\n\t" . '{';
62
        $class .= "\n\t\t" . '$this->renderer = $renderer;';
63
        $class .= "\n\t\t" . 'parent::__construct(isset($query) ? $query : new dbQuery(), $entity->id, ' . $metadata->fieldID . ');';
64
        $class .= "\n\t" . '}' . "\n";
65
66
        $this->generator->text($class);
67
    }
68
}
69
//[PHPCOMPRESSOR(remove,end)]
70