Completed
Push — master ( 156e79...007c06 )
by Pascal
02:10
created

Jsonable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 34
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 4 1
A toArray() 0 4 1
A __toString() 0 4 1
A toJson() 0 4 1
1
<?php namespace Atog\Api;
2
3
/**
4
 * Trait Jsonable implements JsonSerializable interface
5
 * @package Atog\Api
6
 */
7
trait Jsonable
8
{
9
    /**
10
     * @return array
11
     */
12
    public function jsonSerialize()
13
    {
14
        return $this->toArray();
15
    }
16
    
17
    /**
18
     * @return array
19
     */
20
    public function toArray()
21
    {
22
        return $this->attributes;
0 ignored issues
show
Bug introduced by
The property attributes 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...
23
    }
24
    
25
    /**
26
     * @return string
27
     */
28
    public function __toString()
29
    {
30
        return $this->toJson();
31
    }
32
    
33
    /**
34
     * @return string
35
     */
36
    public function toJson()
37
    {
38
        return json_encode($this->toArray(), true);
39
    }
40
}
41