Passed
Push — master ( a41166...4c99b3 )
by Bruno
03:13
created

ModelGenerator::getGenerateFilename()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 1
f 0
ccs 2
cts 2
cp 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Laravel\Targets;
4
5
use Formularium\Datatype;
6
use Formularium\Extradata;
7
use Formularium\ExtradataParameter;
8
use Formularium\Field;
9
use Formularium\Model;
10
use Illuminate\Support\Str;
11
use GraphQL\Type\Definition\ListOfType;
12
use GraphQL\Type\Definition\NonNull;
13
use GraphQL\Type\Definition\ObjectType;
14
use GraphQL\Type\Definition\UnionType;
15
use Modelarium\BaseGenerator;
16
use Modelarium\Datatypes\Datatype_relationship;
17
use Modelarium\Datatypes\RelationshipFactory;
18
use Modelarium\Exception\Exception;
19
use Modelarium\FormulariumUtils;
20
use Modelarium\GeneratedCollection;
21
use Modelarium\GeneratedItem;
22
use Modelarium\Parser;
23
use Modelarium\Types\FormulariumScalarType;
24
use Nette\PhpGenerator\Method;
25
26
class ModelGenerator extends BaseGenerator
27
{
28
    /**
29
     * @var string
30
     */
31
    protected $stubDir = __DIR__ . "/stubs/";
32
33
    /**
34
     * @var string
35
     */
36
    protected static $modelDir = 'app/Models/';
37
38
    /**
39
     * @var ObjectType
40
     */
41
    protected $type = null;
42
43
    /**
44
     * @var \Nette\PhpGenerator\ClassType
45
     */
46
    public $class = null;
47
48
    /**
49
     * fillable attributes
50
     *
51
     * @var array
52
     */
53
    public $fillable = [];
54
55
    /**
56
     * fillable attributes
57
     *
58
     * @var array
59
     */
60
    public $hidden = [];
61
62
    /**
63
     * cast attributes
64
     *
65
     * @var array
66
     */
67
    public $casts = [];
68
69
    /**
70
     *
71
     * @var string
72
     */
73
    public $parentClassName = '\Illuminate\Database\Eloquent\Model';
74
75
    /**
76
     * fields
77
     *
78
     * @var Model
79
     */
80
    public $fModel = null;
81
82
    /**
83
     *
84
     * @var array
85
     */
86
    public $traits = [];
87
88
    /**
89
     * Random generation
90
     *
91
     * @var Method
92
     */
93
    protected $methodRandom = null;
94
95
    /**
96
     * Do we have a 'can' attribute?
97
     *
98
     * @var boolean
99
     */
100
    protected $hasCan = true;
101
102
    /**
103
     * If true, we have timestamps on the migration.
104
     *
105
     * @var boolean
106
     */
107
    public $migrationTimestamps = false;
108
109 10
    public function generate(): GeneratedCollection
110
    {
111 10
        $this->fModel = Model::create($this->studlyName);
112 10
        $x = new GeneratedCollection([
113 10
            new GeneratedItem(
114 10
                GeneratedItem::TYPE_MODEL,
115 10
                $this->generateString(),
116 10
                $this->getGenerateFilename()
117
            ),
118 10
            new GeneratedItem(
119 10
                GeneratedItem::TYPE_MODEL,
120 10
                $this->templateStub('model'),
121 10
                $this->getGenerateFilename(false),
122 10
                true
123
            )
124
        ]);
125 10
        return $x;
126
    }
127
128 10
    protected function processField(
129
        string $typeName,
130
        \GraphQL\Type\Definition\FieldDefinition $field,
131
        \GraphQL\Language\AST\NodeList $directives,
132
        bool $isRequired
133
    ): void {
134 10
        $fieldName = $field->name;
135
136 10
        if ($typeName === 'ID') {
137 10
            return;
138
        }
139
140 10
        $scalarType = $this->parser->getScalarType($typeName);
141
142
        /**
143
         * @var Field $field
144
         */
145 10
        $field = null;
146 10
        if (!$scalarType) {
147
            // probably another model
148 8
            $field = FormulariumUtils::getFieldFromDirectives(
149 8
                $fieldName,
150 8
                $typeName,
151 8
                $directives
152
            );
153 5
        } elseif ($scalarType instanceof FormulariumScalarType) {
154 5
            $field = FormulariumUtils::getFieldFromDirectives(
155 5
                $fieldName,
156 5
                $scalarType->getDatatype()->getName(),
157 5
                $directives
158
            );
159
        } else {
160
            return;
161
        }
162
163 10
        if ($isRequired) {
164 10
            $field->setValidatorOption(
165 10
                Datatype::REQUIRED,
166 10
                'value',
167 10
                true
168
            );
169
        }
170
171 10
        $this->fModel->appendField($field);
172 10
    }
173
174 10
    protected function processFieldDirectives(
175
        \GraphQL\Type\Definition\FieldDefinition $field,
176
        \GraphQL\Language\AST\NodeList $directives
177
    ): void {
178 10
        list($type, $isRequired) = Parser::getUnwrappedType($field->type);
179
180 10
        foreach ($directives as $directive) {
181
            $name = $directive->name->value;
182
            $className = $this->getDirectiveClass($name);
183
            if ($className) {
184
                $methodName = "$className::processModelFieldDirective";
185
                /** @phpstan-ignore-next-line */
186
                $methodName(
187
                    $this,
188
                    $field,
189
                    $directive
190
                );
191
            }
192
        }
193
194 10
        $typeName = $type->name;
195 10
        $this->processField($typeName, $field, $directives, $isRequired);
196 10
    }
197
198 8
    protected function processRelationship(
199
        \GraphQL\Type\Definition\FieldDefinition $field,
200
        \GraphQL\Language\AST\NodeList $directives
201
    ): void {
202 8
        $lowerName = mb_strtolower($this->getInflector()->singularize($field->name));
203 8
        $lowerNamePlural = $this->getInflector()->pluralize($lowerName);
204
205 8
        $targetClass = '\\App\\Models\\' . Str::studly($this->getInflector()->singularize($field->name));
206
207 8
        list($type, $isRequired) = Parser::getUnwrappedType($field->type);
208 8
        $typeName = $type->name;
209
210
        // special types that should be skipped.
211 8
        if ($typeName === 'Can') {
212
            $this->hasCan = true;
213
            return;
214
        }
215
216 8
        $generateRandom = false;
217 8
        $sourceTypeName = $this->lowerName;
218 8
        $targetTypeName = $lowerName;
219 8
        $relationship = null;
220 8
        $isInverse = false;
221
222
        // TODO: convert to separate classes
223 8
        foreach ($directives as $directive) {
224 8
            $name = $directive->name->value;
225 8
            switch ($name) {
226 8
            case 'belongsTo':
227 4
                $generateRandom = true;
228 4
                $relationship = RelationshipFactory::RELATIONSHIP_ONE_TO_MANY;
229 4
                $isInverse = true;
230 4
                $this->class->addMethod($lowerName)
231 4
                    ->setPublic()
232 4
                    ->setReturnType('\\Illuminate\\Database\\Eloquent\\Relations\\BelongsTo')
233 4
                    ->setBody("return \$this->belongsTo($targetClass::class);");
234 4
                break;
235
236 8
            case 'belongsToMany':
237 1
                $generateRandom = true;
238 1
                $relationship = RelationshipFactory::RELATIONSHIP_MANY_TO_MANY;
239 1
                $isInverse = true;
240 1
                $this->class->addMethod($lowerNamePlural)
241 1
                    ->setPublic()
242 1
                    ->setReturnType('\\Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany')
243 1
                    ->setBody("return \$this->belongsToMany($targetClass::class);");
244 1
                break;
245
246 7
            case 'hasOne':
247 3
                $relationship = RelationshipFactory::RELATIONSHIP_ONE_TO_ONE;
248 3
                $isInverse = false;
249 3
                $this->class->addMethod($lowerName)
250 3
                    ->setPublic()
251 3
                    ->setReturnType('\\Illuminate\\Database\\Eloquent\\Relations\\HasOne')
252 3
                    ->setBody("return \$this->hasOne($targetClass::class);");
253 3
                break;
254
255 7
            case 'hasMany':
256 1
                $relationship = RelationshipFactory::RELATIONSHIP_ONE_TO_MANY;
257 1
                $isInverse = false;
258 1
                $target = $this->getInflector()->singularize($targetClass);
259 1
                $this->class->addMethod($lowerNamePlural)
260 1
                    ->setPublic()
261 1
                    ->setReturnType('\\Illuminate\\Database\\Eloquent\\Relations\\HasMany')
262 1
                    ->setBody("return \$this->hasMany($target::class);");
263 1
                break;
264
265 7
            case 'morphOne':
266 7
            case 'morphMany':
267 7
            case 'morphToMany':
268 3
                if ($name === 'morphOne') {
269 1
                    $relationship = RelationshipFactory::MORPH_ONE_TO_ONE;
270
                } else {
271 2
                    $relationship = RelationshipFactory::MORPH_ONE_TO_MANY;
272
                }
273 3
                $isInverse = false;
274
275 3
                $targetType = $this->parser->getType($typeName);
276 3
                if (!$targetType) {
277
                    throw new Exception("Cannot get type {$typeName} as a relationship to {$this->baseName}");
278 3
                } elseif (!($targetType instanceof ObjectType)) {
279
                    throw new Exception("{$typeName} is not a type for a relationship to {$this->baseName}");
280
                }
281 3
                $targetField = null;
282 3
                foreach ($targetType->getFields() as $subField) {
283 3
                    $subDir = Parser::getDirectives($subField->astNode->directives);
284 3
                    if (array_key_exists('morphTo', $subDir) || array_key_exists('morphedByMany', $subDir)) {
285 3
                        $targetField = $subField->name;
286 3
                        break;
287
                    }
288
                }
289 3
                if (!$targetField) {
290
                    throw new Exception("{$targetType} does not have a '@morphTo' or '@morphToMany' field");
291
                }
292
293 3
                $this->class->addMethod($field->name)
294
                    // TODO: return type
295 3
                    ->setPublic()
296 3
                    ->setBody("return \$this->{$name}($typeName::class, '$targetField');");
297 3
                break;
298
    
299 7
            case 'morphTo':
300 2
                $relationship = RelationshipFactory::MORPH_ONE_TO_MANY; // TODO
301 2
                $isInverse = true;
302 2
                $this->class->addMethod($field->name)
303 2
                    ->setReturnType('\\Illuminate\\Database\\Eloquent\\Relations\\MorphTo')
304 2
                    ->setPublic()
305 2
                    ->setBody("return \$this->morphTo();");
306 2
                break;
307
308 5
            case 'morphedByMany':
309 1
                $relationship = RelationshipFactory::MORPH_MANY_TO_MANY; // TODO
310 1
                $isInverse = true;
311 1
                $typeMap = $this->parser->getSchema()->getTypeMap();
312
       
313 1
                foreach ($typeMap as $name => $object) {
314 1
                    if (!($object instanceof ObjectType) || $name === 'Query' || $name === 'Mutation' || $name === 'Subscription') {
315 1
                        continue;
316
                    }
317
318
                    /**
319
                     * @var ObjectType $object
320
                     */
321
322 1
                    if (str_starts_with((string)$name, '__')) {
323
                        // internal type
324 1
                        continue;
325
                    }
326
327 1
                    foreach ($object->getFields() as $subField) {
328 1
                        $subDirectives = Parser::getDirectives($subField->astNode->directives);
329
330 1
                        if (!array_key_exists('morphToMany', $subDirectives)) {
331 1
                            continue;
332
                        }
333
334 1
                        $methodName = $this->getInflector()->pluralize(mb_strtolower((string)$name));
335 1
                        $this->class->addMethod($methodName)
336 1
                                ->setReturnType('\\Illuminate\\Database\\Eloquent\\Relations\\MorphToMany')
337 1
                                ->setPublic()
338 1
                                ->setBody("return \$this->morphedByMany($name::class, '$lowerName');");
339
                    }
340
                }
341 1
                break;
342
343 4
            case 'laravelMediaLibraryData':
344
                $collection = 'images';
345
                $customFields = [];
346
                $studlyFieldName = Str::studly($field->name);
347
348
                // deps
349
                if (!in_array('\\Spatie\\MediaLibrary\\HasMedia', $this->class->getImplements())) {
350
                    $this->class->addImplement('\\Spatie\\MediaLibrary\\HasMedia');
351
                    $this->class->addTrait('\\Spatie\\MediaLibrary\\InteractsWithMedia');
352
                }
353
354
                // args
355
                foreach ($directive->arguments as $arg) {
356
                    /**
357
                     * @var \GraphQL\Language\AST\ArgumentNode $arg
358
                     */
359
360
                    switch ($arg->name->value) {
361
                    case 'collection':
362
                        /** @phpstan-ignore-next-line */
363
                        $collection = $arg->value->value;
0 ignored issues
show
Bug introduced by
Accessing value on the interface GraphQL\Language\AST\ValueNode suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
364
                    break;
365
                    case 'fields':
366
                        /** @phpstan-ignore-next-line */
367
                        foreach ($arg->value->values as $item) {
0 ignored issues
show
Bug introduced by
Accessing values on the interface GraphQL\Language\AST\ValueNode suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
368
                            $customFields[] = $item->value;
369
                        }
370
                    break;
371
                    }
372
                }
373
                $studlyCollection = Str::studly($collection);
374
375
                // registration
376
                if (!$this->class->hasMethod("registerMediaCollections")) {
377
                    $registerMediaCollections = $this->class->addMethod("registerMediaCollections")
378
                        ->setPublic()
379
                        ->setReturnType('void')
380
                        ->addComment("Configures Laravel media-library");
381
                } else {
382
                    $registerMediaCollections = $this->class->getMethod("registerMediaCollections");
383
                }
384
                $registerMediaCollections->addBody("\$this->addMediaCollection(?);\n", [$collection]);
385
386
                // all image models for this collection
387
                $this->class->addMethod("getMedia{$studlyCollection}Collection")
388
                    ->setPublic()
389
                    ->setReturnType('\\Spatie\\MediaLibrary\\MediaCollections\\Models\\Collections\\MediaCollection')
390
                    ->addComment("Returns a collection media from Laravel-MediaLibrary")
391
                    ->setBody("return \$this->getMedia(?);", [$collection]);
392
393
                // custom fields
394
                $this->class->addMethod("getMedia{$studlyCollection}CustomFields")
395
                    ->setPublic()
396
                    ->setReturnType('array')
397
                    ->addComment("Returns custom fields for the media")
398
                    ->setBody("return ?;", [$customFields]);
399
400
                $this->class->addMethod("get{$studlyFieldName}urlAttribute")
401
                    ->setPublic()
402
                    ->setReturnType('string')
403
                    ->addComment("Returns the media attribute (url) for the $collection")
404
                    ->setBody( /** @lang PHP */
405
                        <<< PHP
406
        \$image = \$this->getMedia{$studlyCollection}Collection()->first();
407
        if (\$image) {
408
            return \$image->getUrl();
409
        }
410
        return '';
411
        PHP
412
                    );
413
414
                // all image models for this collection
415
                $this->class->addMethod("get{$studlyFieldName}Attribute")
416
                    ->setPublic()
417
                    ->setReturnType('array')
418
                    ->addComment("Returns media attribute for the $collection media with custom fields")
419
                    ->setBody( /** @lang PHP */
420
                        <<< PHP
421
        \$image = \$this->getMedia{$studlyCollection}Collection()->first();
422
if (\$image) {
423
    \$customFields = [];
424
    foreach (\$this->getMedia{$studlyCollection}CustomFields() as \$c) {
425
        \$customFields[\$c] = \$image->getCustomProperty(\$c);
426
    }
427
    return [
428
        'url' => \$image->getUrl(),
429
        'fields' => json_encode(\$customFields)
430
    ];
431
}
432
return [];
433
PHP
434
                    );
435
                return;
436
            
437
            default:
438 4
                break;
439
            }
440
        }
441 8
        if (!$relationship) {
442
            throw new Exception("Could not find a relationship in {$typeName} for {$field->name} in {$sourceTypeName}");
443
        }
444
445 8
        $relationshipDatatype = "relationship:" . ($isInverse ? "inverse:" : "") .
446 8
            "$relationship:$sourceTypeName:$targetTypeName";
447
448 8
        $this->processField($relationshipDatatype, $field, $directives, $isRequired);
449
450 8
        if ($generateRandom) {
451 5
            if ($relationship == RelationshipFactory::RELATIONSHIP_MANY_TO_MANY || $relationship == RelationshipFactory::MORPH_MANY_TO_MANY) {
452
                // TODO: do we generate it? seed should do it?
453
            } else {
454 4
                $this->methodRandom->addBody(
455 4
                    '$data["' . $lowerName . '_id"] = function () {' . "\n" .
456 4
                '    return factory(' . $targetClass . '::class)->create()->id;'  . "\n" .
457 4
                '};'
458
                );
459
            }
460
        }
461 8
    }
462
463 10
    protected function processDirectives(
464
        \GraphQL\Language\AST\NodeList $directives
465
    ): void {
466 10
        foreach ($directives as $directive) {
467 1
            $name = $directive->name->value;
468 1
            $this->fModel->appendExtradata(FormulariumUtils::directiveToExtradata($directive));
469
470 1
            $className = $this->getDirectiveClass($name);
471 1
            if ($className) {
472 1
                $methodName = "$className::processModelTypeDirective";
473
                /** @phpstan-ignore-next-line */
474 1
                $methodName(
475 1
                    $this,
476
                    $directive
477
                );
478
            }
479
        }
480 10
    }
481
482 10
    public function generateString(): string
483
    {
484 10
        $namespace = new \Nette\PhpGenerator\PhpNamespace('App\\Models');
485 10
        $namespace->addUse('\\Illuminate\\Database\\Eloquent\\Relations\\BelongsTo');
486 10
        $namespace->addUse('\\Illuminate\\Database\\Eloquent\\Relations\\HasOne');
487 10
        $namespace->addUse('\\Illuminate\\Database\\Eloquent\\Relations\\HasMany');
488 10
        $namespace->addUse('\\Illuminate\\Database\\Eloquent\\Relations\\MorphTo');
489 10
        $namespace->addUse('\\Illuminate\\Database\\Eloquent\\Relations\\MorphOne');
490 10
        $namespace->addUse('\\Illuminate\\Database\\Eloquent\\Relations\\MorphToMany');
491 10
        $namespace->addUse('\\Illuminate\\Support\\Facades\\Auth');
492 10
        $namespace->addUse('\\Formularium\\Exception\\NoRandomException');
493 10
        $namespace->addUse('\\Modelarium\\Laravel\\Datatypes\\Datatype_relationship');
494
495 10
        $this->class = $namespace->addClass('Base' . $this->studlyName);
496 10
        $this->class
497 10
            ->addComment("This file was automatically generated by Modelarium.")
498 10
            ->setAbstract();
499
500 10
        $this->methodRandom = new Method('getRandomData');
501 10
        $this->methodRandom->addBody(
502 10
            '$data = static::getFormularium()->getRandom(get_called_class() . \'::getRandomFieldData\');' . "\n"
503
        );
504
505 10
        $this->processGraphql();
506
507
        // this might have changed
508 10
        $this->class->setExtends($this->parentClassName);
509
510 10
        foreach ($this->traits as $trait) {
511 1
            $this->class->addTrait($trait);
512
        }
513
514 10
        $this->class->addProperty('fillable')
515 10
            ->setProtected()
516 10
            ->setValue($this->fillable)
517 10
            ->setComment("The attributes that are mass assignable.\n@var array")
518 10
            ->setInitialized();
519
520 10
        $this->class->addProperty('hidden')
521 10
            ->setProtected()
522 10
            ->setValue($this->hidden)
523 10
            ->setComment("The attributes that should be hidden for arrays.\n@var array")
524 10
            ->setInitialized();
525
526 10
        if (!$this->migrationTimestamps) {
527 9
            $this->class->addProperty('timestamps')
528 9
                ->setPublic()
529 9
                ->setValue(false)
530 9
                ->setComment("Do not set timestamps.\n@var boolean")
531 9
                ->setInitialized();
532
        }
533
534 10
        if ($this->casts) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->casts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
535
            $this->class->addProperty('casts')
536
                ->setProtected()
537
                ->setValue($this->casts)
538
                ->setComment("The attributes that should be cast.\n@var array")
539
                ->setInitialized();
540
        }
541
542 10
        $this->class->addMethod('getFields')
543 10
            ->setPublic()
544 10
            ->setStatic()
545 10
            ->setReturnType('array')
546 10
            ->addComment('@return array')
547 10
            ->addBody(
548 10
                "return ?;\n",
549
                [
550 10
                    $this->fModel->serialize()
551
                ]
552
            );
553
554 10
        $this->class->addMethod('getFormularium')
555 10
            ->setPublic()
556 10
            ->setStatic()
557 10
            ->setReturnType('\Formularium\Model')
558 10
            ->addComment('@return \Formularium\Model')
559 10
            ->addBody(
560
                '$model = \Formularium\Model::fromStruct(static::getFields());' . "\n" .
561 10
                'return $model;',
562
                [
563
                    //$this->studlyName,
564 10
                ]
565
            );
566
        
567 10
        $this->methodRandom
568 10
            ->addComment('@return array')
569 10
            ->setPublic()
570 10
            ->setStatic()
571 10
            ->setReturnType('array')
572 10
            ->addBody('return $data;');
573 10
        $this->class->addMember($this->methodRandom);
574
575 10
        $this->class->addMethod('getRandomFieldData')
576 10
            ->setPublic()
577 10
            ->setStatic()
578 10
            ->addComment("Filters fields and generate random data. Throw NoRandomException for fields you don't want to generate random data, or return a valid value.")
579 10
            ->addBody('
580
$d = $f->getDatatype();
581
if ($d instanceof Datatype_relationship) {
582
    throw new NoRandomException($f->getName());
583
}
584
return $f->getDatatype()->getRandom();')
585 10
            ->addParameter('f')->setType('Formularium\Field');
586
587
        // TODO perhaps we can use PolicyGenerator->policyClasses to auto generate
588 10
        if ($this->hasCan) {
589 10
            $this->class->addMethod('getCanAttribute')
590 10
                ->setPublic()
591 10
                ->setReturnType('array')
592 10
                ->addComment("Returns the policy permissions for actions such as editing or deleting.\n@return \Formularium\Model")
593 10
                ->addBody(
594 10
                    '$policy = new \\App\\Policies\\' . $this->studlyName . 'Policy();' . "\n" .
595 10
                    '$user = Auth::user();' . "\n" .
596 10
                    'return [' . "\n" .
597 10
                    '    //[ "ability" => "create", "value" => $policy->create($user) ]' . "\n" .
598 10
                    '];'
599
                );
600
        }
601
        
602 10
        $printer = new \Nette\PhpGenerator\PsrPrinter;
603 10
        return $this->phpHeader() . $printer->printNamespace($namespace);
604
    }
605
606 10
    protected function processGraphql(): void
607
    {
608 10
        foreach ($this->type->getFields() as $field) {
609 10
            $directives = $field->astNode->directives;
610
            if (
611 10
                ($field->type instanceof ObjectType) ||
612 10
                ($field->type instanceof ListOfType) ||
613 10
                ($field->type instanceof UnionType) ||
614 10
                ($field->type instanceof NonNull && (
615 10
                    ($field->type->getWrappedType() instanceof ObjectType) ||
616 10
                    ($field->type->getWrappedType() instanceof ListOfType) ||
617 10
                    ($field->type->getWrappedType() instanceof UnionType)
618
                ))
619
            ) {
620
                // relationship
621 8
                $this->processRelationship($field, $directives);
622
            } else {
623 10
                $this->processFieldDirectives($field, $directives);
624
            }
625
        }
626
627
        /**
628
         * @var \GraphQL\Language\AST\NodeList|null
629
         */
630 10
        $directives = $this->type->astNode->directives;
631 10
        if ($directives) {
632 10
            $this->processDirectives($directives);
0 ignored issues
show
Bug introduced by
$directives of type GraphQL\Language\AST\DirectiveNode[] is incompatible with the type GraphQL\Language\AST\NodeList expected by parameter $directives of Modelarium\Laravel\Targe...or::processDirectives(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

632
            $this->processDirectives(/** @scrutinizer ignore-type */ $directives);
Loading history...
633
        }
634 10
    }
635
636 10
    public function getGenerateFilename(bool $base = true): string
637
    {
638 10
        return $this->getBasePath(self::$modelDir . '/' . ($base ? 'Base' : '') . $this->studlyName . '.php');
639
    }
640
641
    public static function setModelDir(string $dir): void
642
    {
643
        self::$modelDir = $dir;
644
    }
645
}
646