HasResourceKeyTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getResourceKey() 0 11 2
1
<?php
2
3
namespace Apiato\Core\Traits;
4
5
use Illuminate\Support\Pluralizer;
6
use ReflectionClass;
7
8
/**
9
 * Class HasResourceKeyTrait
10
 *
11
 * @author  Johannes Schobel <[email protected]>
12
 */
13
trait HasResourceKeyTrait
14
{
15
16
    /**
17
     * Returns the type for JSON API Serializer. Can be overwritten with the protected $resourceKey in respective model class
18
     *
19
     * @return string
20
     */
21
    public function getResourceKey()
22
    {
23
        if (isset($this->resourceKey)) {
24
            $resourceKey = $this->resourceKey;
0 ignored issues
show
Bug introduced by Johannes Schobel
The property resourceKey does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
        } else {
26
            $reflect = new ReflectionClass($this);
27
            $resourceKey = strtolower(Pluralizer::plural($reflect->getShortName()));
28
        }
29
30
        return $resourceKey;
31
    }
32
}
33