Completed
Branch dev (20d83f)
by Arina
01:20
created

DataAttributeBuilder::build()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 4
nc 4
nop 1
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