Completed
Push — master ( 9c48b0...ba7492 )
by Daniel
02:16
created

Api::getLocale()   D

Complexity

Conditions 71
Paths 71

Size

Total Lines 231
Code Lines 221

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 5112

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 231
ccs 0
cts 221
cp 0
rs 4.1818
cc 71
eloc 221
nc 71
nop 2
crap 5112

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Jobles\Careerjet;
4
5
use Jobles\Careerjet\Builder\JobBuilder;
6
use Jobles\Core\API\SearchInterface;
7
use Jobles\Core\Job\JobCollection;
8
9
class Api implements SearchInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $affiliateId;
15
16
    /**
17
     * @var \Careerjet_API
18
     */
19
    private $api;
20
21
    /**
22
     * @var string
23
     */
24
    private $country;
25
26
    /**
27
     * @var string
28
     */
29
    private $language;
30
31 1
    public function __construct($affiliateId, $country, $language = null, \Careerjet_API $api = null)
32
    {
33 1
        $this->affiliateId = $affiliateId;
34 1
        $this->country = $country;
35 1
        $this->language = $language;
36
37 1
        $this->api = !empty($api) ? $api : new \Careerjet_API(Locale::byCountryAndLanguage($country, $language));
38 1
    }
39
40
    /**
41
     * @param array $filters
42
     * @return JobCollection
43
     */
44 1
    public function search(array $filters = [])
45
    {
46 1
        $collection = new JobCollection;
47 1
        $search = ['affid' => $this->affiliateId];
48 1
        if (isset($filters['keywords'])) { // empty allowed
49 1
            $search['keywords'] = $filters['keywords'];
50 1
        }
51 1
        if (isset($filters['location'])) { // empty allowed
52 1
            $search['location'] = $filters['location'];
53 1
        }
54 1
        if (isset($filters['limit'])) { // max 99
55 1
            $search['pagesize'] = $filters['limit'];
56 1
        }
57 1
        $search['page'] = isset($filters['offset']) ? $filters['offset'] : 1; // starts on 1
58
59 1
        $result = $this->api->search($search);
60 1
        foreach ($result->jobs as $job) {
61 1
            $collection->addJob(JobBuilder::fromApi($job, $this->country));
62 1
        }
63
64 1
        return $collection;
65
    }
66
}
67