Passed
Pull Request — master (#680)
by Garion
03:19
created

ReadOneAreaResolver::resolve()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 4
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DNADesign\Elemental\GraphQL;
4
5
use DNADesign\Elemental\Models\ElementalArea;
6
use Exception;
7
use GraphQL\Type\Definition\ResolveInfo;
8
use InvalidArgumentException;
9
use SilverStripe\GraphQL\OperationResolver;
10
11
class ReadOneAreaResolver implements OperationResolver
12
{
13
    public function resolve($object, array $args, $context, ResolveInfo $info)
14
    {
15
        $area = ElementalArea::get()->byID($args['ID']);
16
17
        if (!$area) {
0 ignored issues
show
introduced by
$area is of type SilverStripe\ORM\DataObject, thus it always evaluated to true.
Loading history...
18
            throw new InvalidArgumentException('Could not find elemental area matching ID ' . $args['ID']);
19
        }
20
21
        if (!$area->canView($context['currentUser'])) {
22
            throw new Exception('Current user cannot view element areas');
23
        }
24
25
        return $area;
26
    }
27
}
28