for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Modelarium\Laravel\Directives;
use Modelarium\Laravel\Targets\SeedGenerator;
use Modelarium\Laravel\Targets\Interfaces\SeedDirectiveInterface;
class BelongsToManyDirective implements SeedDirectiveInterface
{
public static function processSeedFieldDirective(
SeedGenerator $generator,
\GraphQL\Type\Definition\FieldDefinition $field,
\GraphQL\Language\AST\Node $directive
): void {
$type1 = $generator->lowerName;
lowerName
Modelarium\BaseGenerator
$type2 = mb_strtolower($generator->getInflector()->singularize($field->name));
if (strcasecmp($type1, $type2) < 0) { // TODO: check this, might not work
$relationship = mb_strtolower($generator->getInflector()->pluralize($field->name));
$generator->extraCode[] = self::makeManyToManySeed($type1, $type2, $relationship);
}
protected static function makeManyToManySeed(string $sourceModel, string $targetModel, string $relationship): string
$sourceModel
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
protected static function makeManyToManySeed(/** @scrutinizer ignore-unused */ string $sourceModel, string $targetModel, string $relationship): string
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
return <<<EOF
try {
\${$targetModel}Items = App\\Models\\$targetModel::all();
\$model->{$relationship}()->attach(
\${$targetModel}Items->random(rand(1, 3))->pluck('id')->toArray()
);
catch (\InvalidArgumentException \$e) {
\${$targetModel}Items->random(1)->pluck('id')->toArray()
EOF;