Completed
Push — master ( a92ee2...268555 )
by Dmitry
04:05
created

JsonSerializableMethods   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 9 2
1
<?php
2
3
namespace PHPKitchen\Platform\Struct\Mixin;
4
5
use JsonSerializable;
6
7
/**
8
 * Represents realization of JSON serialization method for collection.
9
 *
10
 * @property array $elements data storage.
11
 *
12
 * @author Dmitry Kolodko <[email protected]>
13
 * @since 1.0
14
 */
15
trait JsonSerializableMethods {
16
    /**
17
     * Convert the object into something JSON serializable.
18
     *
19
     * @return array
20
     * @since 1.0
21
     */
22
    public function jsonSerialize() {
23
        return array_map(function ($value) {
24
            if ($value instanceof JsonSerializable) {
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
                return $value->jsonSerialize();
26
            }
27
28
            return $value;
29
        }, $this->elements);
30
    }
31
}