DataAttributeBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 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