Completed
Pull Request — master (#45)
by Jose Manuel
02:24
created

AbstractObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 9 3
has() 0 1 ?
1
<?php
2
3
namespace Softonic\GraphQL\DataObjects;
4
5
use JsonSerializable;
6
use Softonic\GraphQL\DataObjects\Interfaces\DataObject;
7
8
abstract class AbstractObject implements JsonSerializable, DataObject
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $arguments;
14
15 144
    public function __construct(array $arguments = [])
16
    {
17 144
        $this->arguments = $arguments;
18 144
    }
19
20 28
    public function toArray(): array
21
    {
22 28
        $item = [];
23 28
        foreach ($this->arguments as $key => $value) {
24 28
            $item[$key] = $value instanceof JsonSerializable ? $value->toArray() : $value;
0 ignored issues
show
Bug introduced by
The class JsonSerializable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
25
        }
26
27 28
        return $item;
28
    }
29
30
    abstract public function has(string $key): bool;
31
}
32