NullifyOwningAssociation   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 3 1
A hydrate() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiSkeletons\Doctrine\GraphQL\Hydrator\Strategy;
6
7
use GraphQL\Error\Error;
8
use Laminas\Hydrator\Strategy\StrategyInterface;
9
10
/**
11
 * Nullify an association.
12
 *
13
 * In a many to many relationship from a known starting point it is possible
14
 * to backwards-query the owning relationship to gather data the user should
15
 * not be privileged to.
16
 *
17
 * For instance in a User <> Role relationship a user may have many roles.  But
18
 * a role may have many users.  So in a query where a user is fetched then their
19
 * roles are fetched you could then reverse the query to fetch all users with the
20
 * same role
21
 *
22
 * This query would return all user names with the same roles as the user who
23
 * created the artist.
24
 * { artist { user { role { user { name } } } } }
25
 *
26
 * This hydrator strategy is used to prevent the reverse lookup by nullifying
27
 * the response when queried from the owning side of a many to many relationship
28
 *
29
 * Ideally the developer will add the owning relation to a filter so the
30
 * field is not queryable at all.  This strategy exists as a patch for generating
31
 * a configuration skeleton.
32
 */
33
class NullifyOwningAssociation extends AbstractCollectionStrategy implements
34
    StrategyInterface
35
{
36
    public function extract(mixed $value, object|null $object = null): mixed
37
    {
38
        throw new Error('Query is barred by Nullify Owning Association');
39
    }
40
41
    /**
42
     * @param mixed[]|null $data
43
     *
44
     * @codeCoverageIgnore
45
     */
46
    public function hydrate(mixed $value, array|null $data): void
47
    {
48
    }
49
}
50