GenderizeResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 35
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setResult() 0 7 2
A setMeta() 0 3 1
A returnWithCollection() 0 9 2
A __construct() 0 4 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
11
    protected $result;
12
13
    public function __construct($response)
14
    {
15
        $this->result = $this->setResult($response);
16
        $this->meta = $this->setMeta($response);
17
    }
18
19
    protected function setMeta($data)
20
    {
21
        return new Meta($data);
22
    }
23
24
    protected function setResult($response)
25
    {
26
        if (is_array($response->body)) {
27
            return $this->returnWithCollection($response);
28
        }
29
30
        return new Name($response->body);
31
    }
32
33
    protected function returnWithCollection($response)
34
    {
35
        $collection = new Collection;
36
37
        foreach ($response->body as $row) {
38
            $collection->push(new Name($row));
39
        }
40
41
        return $collection;
42
    }
43
}
44