GenderizeResponse::returnWithCollection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Pixelpeter\Genderize\Models;
4
5
use Illuminate\Support\Collection;
6
7
class GenderizeResponse extends BaseModel
8
{
9
    protected $meta;
10
    protected $result;
11
12
    public function __construct($response)
13
    {
14
        $this->result = $this->setResult($response);
15
        $this->meta = $this->setMeta($response);
16
    }
17
18
    protected function setMeta($data)
19
    {
20
        return new Meta($data);
21
    }
22
23
    protected function setResult($response)
24
    {
25
        if (is_array($response->body)) {
26
            return $this->returnWithCollection($response);
27
        }
28
29
        return new Name($response->body);
30
    }
31
32
    protected function returnWithCollection($response)
33
    {
34
        $collection = new Collection();
35
36
        foreach ($response->body as $row) {
37
            $collection->push(new Name($row));
38
        }
39
40
        return $collection;
41
    }
42
}
43