Passed
Push — master ( 51b4e4...f97e2a )
by Robbie
06:06
created

ReadOneAreaResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 13 3
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