Passed
Push — main ( c6d071...1e0b0d )
by Konstantin
02:02
created

QueryBuilder   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 20
c 1
b 0
f 0
dl 0
loc 84
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 3 1
A __construct() 0 3 1
A setIncludeFields() 0 4 1
A setMaxResult() 0 4 1
A setNationalityFilter() 0 4 1
A setGenderFilter() 0 4 1
A setExcludeFields() 0 4 1
A setPage() 0 4 1
A setPasswordFormat() 0 4 1
A setSeed() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kosv\RandomUser\Client;
6
7
use Kosv\RandomUser\Interfaces\QueryBuilderInterface;
8
use Kosv\RandomUser\Url\AbstractBuilder as AbstractUrlBuilder;
9
use Kosv\RandomUser\Url\Builder as UrlBuilder;
10
11
final class QueryBuilder implements QueryBuilderInterface
12
{
13
    private UrlBuilder $url;
14
15
    public function __construct()
16
    {
17
        $this->url = new UrlBuilder();
18
    }
19
20
    public function build(): AbstractUrlBuilder
21
    {
22
        return clone $this->url;
23
    }
24
25
    /**
26
     * @return $this
27
     */
28
    public function setExcludeFields(array $fields)
29
    {
30
        $this->url->setParam('exc', $fields);
31
        return $this;
32
    }
33
34
    /**
35
     * @return $this
36
     */
37
    public function setGenderFilter(string $gender)
38
    {
39
        $this->url->setParam('gender', [$gender]);
40
        return $this;
41
    }
42
43
    /**
44
     * @return $this
45
     */
46
    public function setIncludeFields(array $fields)
47
    {
48
        $this->url->setParam('inc', $fields);
49
        return $this;
50
    }
51
52
    /**
53
     * @return $this
54
     */
55
    public function setNationalityFilter(array $nationalities)
56
    {
57
        $this->url->setParam('nat', $nationalities);
58
        return $this;
59
    }
60
61
    /**
62
     * @return $this
63
     */
64
    public function setMaxResult(int $max)
65
    {
66
        $this->url->setParam('results', [$max]);
67
        return $this;
68
    }
69
70
    /**
71
     * @return $this
72
     */
73
    public function setPage(int $page)
74
    {
75
        $this->url->setParam('page', [$page]);
76
        return $this;
77
    }
78
79
    /**
80
     * @return $this
81
     */
82
    public function setPasswordFormat(array $format)
83
    {
84
        $this->url->setParam('password', $format);
85
        return $this;
86
    }
87
88
    /**
89
     * @return $this
90
     */
91
    public function setSeed(string $name)
92
    {
93
        $this->url->setParam('seed', [$name]);
94
        return $this;
95
    }
96
}
97