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

Api   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 8
c 4
b 0
f 2
lcom 1
cbo 3
dl 0
loc 58
ccs 24
cts 24
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
B search() 0 22 6
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