Passed
Push — master ( c8b7ec...df7add )
by Bruno
08:03
created

Util::scalars()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 37
rs 8.9457
cc 6
nc 3
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Modelarium;
4
5
use Formularium\Formularium;
6
use Illuminate\Support\Str;
7
use Nette\PhpGenerator\PhpNamespace;
8
9
final class Util
10
{
11
    protected const HEADER =
12
'<?php declare(strict_types=1);
13
/**
14
 * This file is automatically generated by Formularium.
15
 */
16
17
 ';
18
19
    public static function scalars(): string
20
    {
21
        $graphql = [
22
'"""
23
This file is auto generated.
24
"""'
25
        ];
26
        $printer = new \Nette\PhpGenerator\PsrPrinter;
27
        $datatypes = Formularium::getDatatypeNames();
28
        foreach ($datatypes as $name) {
29
            $typeName = Str::studly($name);
30
31
            if ($typeName === 'String' ||
32
                $typeName === 'Boolean' ||
33
                $typeName === 'Int' ||
34
                $typeName === 'Float'
35
            ) {
36
                // base types
37
                continue;
38
            }
39
40
            $ns = 'Modelarium\\Types';
41
            $namespace = new PhpNamespace($ns);
42
            $namespace->addClass('Datatype_' . $name)
43
                ->setExtends('FormulariumScalarType');
44
45
            $stub = self::HEADER . $printer->printNamespace($namespace);
0 ignored issues
show
Unused Code introduced by
The assignment to $stub is dead and can be removed.
Loading history...
46
47
            // TODO $filename = __DIR__ . '/../Modelarium/Types/Datatype_' . $name . '.php';
48
            // TODO \Safe\file_put_contents($filename, $stub);
49
50
            $graphql[] = "scalar $typeName @scalar(class: \"" .
51
                str_replace('\\', '\\\\', $ns . '\\Datatype_' . $name) .
52
                "\")";
53
        }
54
        
55
        return implode("\n\n", $graphql);
56
    }
57
58
    /**
59
     * TODO
60
     * @throws
61
     *
62
    public static generateDirectives(string $filename): void
63
    {
64
        \Safe\file_put_contents(
65
            $filename
66
            LaravelProcessor::getDirectivesGraphqlString()
67
        );
68
    } */
69
}
70