LinkCollectionToCollection   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 14
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Api\Helper;
8
use Application\Model\Collection;
9
use Application\Repository\CollectionRepository;
10
use Ecodev\Felix\Api\Field\FieldInterface;
11
use GraphQL\Type\Definition\Type;
12
13
class LinkCollectionToCollection implements FieldInterface
14
{
15 1
    public static function build(): iterable
16
    {
17 1
        yield 'linkCollectionToCollection' => fn () => [
18 1
            'type' => Type::nonNull(_types()->getOutput(Collection::class)),
19 1
            'description' => 'This will link all images from the source collection to the target collection. The returned collection is the target',
20 1
            'args' => [
21 1
                'sourceCollection' => Type::nonNull(_types()->getId(Collection::class)),
22 1
                'targetCollection' => Type::nonNull(_types()->getId(Collection::class)),
23 1
            ],
24 1
            'resolve' => function ($root, array $args): Collection {
25 1
                $sourceCollection = $args['sourceCollection']->getEntity();
26 1
                $targetCollection = $args['targetCollection']->getEntity();
27
28 1
                Helper::throwIfDenied($targetCollection, 'update');
29
30
                /** @var CollectionRepository $collectionRepository */
31 1
                $collectionRepository = _em()->getRepository(Collection::class);
32 1
                $collectionRepository->linkCollectionToCollection($sourceCollection, $targetCollection);
33
34 1
                return $targetCollection;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $targetCollection returns the type Application\Model\AbstractModel which includes types incompatible with the type-hinted return Application\Model\Collection.
Loading history...
35 1
            },
36 1
        ];
37
    }
38
}
39