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

Gallery::createDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
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 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 "' . $metadata->entityRealName . '" gallery',
41
            ))
42
            ->defClass($metadata->entity . 'Gallery', '\\'.\samsoncms\api\Gallery::class)
43
            ->newLine('use \\'.\samsoncms\api\Renderable::class.';')
44
        ->newLine();
45
    }
46
47
    /**
48
     * Class constructor generation part.
49
     *
50
     * @param Metadata $metadata Entity metadata
51
     */
52
    protected function createConstructor(Metadata $metadata)
53
    {
54
        $class = "\n\t" . '/**';
55
        $class .= "\n\t" . ' * @param ViewInterface $renderer Rendering instance';
56
        $class .= "\n\t" . ' * @param ' . $metadata->parent->entity . ' $entity Parent entity';
57
        $class .= "\n\t" . ' * @param QueryInterface $query Database query instance';
58
        $class .= "\n\t" . ' */';
59
        $class .= "\n\t" . 'public function __construct(ViewInterface $renderer, ' . $entityType . ' $entity, QueryInterface $query = null)';
0 ignored issues
show
Bug introduced by
The variable $entityType does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
60
        $class .= "\n\t" . '{';
61
        $class .= "\n\t\t" . '$this->renderer = $renderer;';
62
        $class .= "\n\t\t" . 'parent::__construct(isset($query) ? $query : new dbQuery(), $entity->id, ' . $fieldID . ');';
0 ignored issues
show
Bug introduced by
The variable $fieldID does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
63
        $class .= "\n\t" . '}' . "\n";
64
65
        $this->generator->text($class);
66
    }
67
}
68
//[PHPCOMPRESSOR(remove,end)]
69