Passed
Push — master ( 2c1718...50160e )
by Bruno
08:20
created

BaseGenerator::phpHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Modelarium;
4
5
use GraphQL\Type\Definition\Type;
6
use Modelarium\Exception\Exception;
7
use Modelarium\Parser;
8
9
abstract class BaseGenerator implements GeneratorInterface
10
{
11
    use GeneratorNameTrait;
12
13
    /**
14
     * @var string
15
     */
16
    protected $stubDir = null;
17
18
    /**
19
     * @var Parser
20
     */
21
    protected $parser = null;
22
23
    /**
24
     * @var Type
25
     */
26
    protected $type = null;
27
28
    /**
29
     * @param Parser $parser
30
     * @param string $name The target type name.
31
     * @param Type|string $type
32
     */
33
    public function __construct(Parser $parser, string $name, $type = null)
34
    {
35
        $this->parser = $parser;
36
        $this->setName($name);
37
38
        if ($type instanceof Type) {
39
            $this->type = $type;
40
        } elseif (!$type) {
41
            $this->type = $parser->getSchema()->getType($name);
42
        } else {
43
            throw new Exception('Invalid model');
44
        }
45
    }
46
47
    protected function phpHeader(): string
48
    {
49
        $date = date('c');
50
        return <<<EOF
51
<?php declare(strict_types=1);
52
/** 
53
 * This file was automatically generated by Modelarium on $date
54
 */
55
56
EOF;
57
    }
58
}
59