Completed
Pull Request — master (#5)
by Arina
01:16
created

DataAttributeBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 14 4
1
<?php
2
3
namespace ArinaSystems\JsonResponse\Builders;
4
5
use Exception;
6
7
class DataAttributeBuilder extends Builder
8
{
9
    /**
10
     * Build a value of the attribute.
11
     *
12
     * @param  mixed   $object
13
     * @return mixed
14
     */
15
    public function build($object)
16
    {
17
        if (!is_object($object)) {
18
            return $object;
19
        }
20
21
        foreach ($this->options->transformers as $type => $transformer) {
22
            if (is_a($object, $type)) {
23
                return (new $transformer($object))->toArray();
24
            }
25
        }
26
27
        throw new Exception("Transformer not found for type " . get_class($object) . ".");
28
    }
29
}
30