Completed
Pull Request — master (#10)
by alexfloppy
07:51
created

Schema   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getResourceType() 0 4 1
B getRelationships() 0 24 2
1
<?php
2
3
namespace App\JsonApi\Teams;
4
5
use App\Models\Team;
6
use CloudCreativity\JsonApi\Exceptions\RuntimeException;
7
use CloudCreativity\LaravelJsonApi\Schema\EloquentSchema;
8
9
class Schema extends EloquentSchema
10
{
11
    /**
12
     * @var string
13
     */
14
    const RESOURCE_TYPE = 'teams';
15
16
    /**
17
     * @var array
18
     */
19
    protected $attributes = [
20
        'name',
21
    ];
22
23
    /**
24
     * @return string
25
     */
26
    public function getResourceType()
27
    {
28
        return self::RESOURCE_TYPE;
29
    }
30
31
    /**
32
     * @param object $resource
33
     * @param bool $isPrimary
34
     * @param array $includeRelationships
35
     *
36
     * @return array
37
     */
38
    public function getRelationships($resource, $isPrimary, array $includeRelationships)
39
    {
40
        if (!$resource instanceof Team) {
0 ignored issues
show
Bug introduced by
The class App\Models\Team does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
41
            throw new RuntimeException('Expecting a Team model.');
42
        }
43
44
        return [
45
            'parent'   => [
46
                self::SHOW_SELF    => true,
47
                self::SHOW_RELATED => true,
48
                self::DATA         => $resource->parent,
49
            ],
50
            'children' => [
51
                self::SHOW_SELF    => true,
52
                self::SHOW_RELATED => true,
53
                self::DATA         => $resource->children,
54
            ],
55
            'members'  => [
56
                self::SHOW_SELF    => true,
57
                self::SHOW_RELATED => true,
58
                self::DATA         => $resource->members,
59
            ],
60
        ];
61
    }
62
}
63