Api   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
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 65
ccs 20
cts 20
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 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
    /**
13
     * @var string
14
     */
15
    private $affiliateId;
16
17
    /**
18
     * @var \Careerjet_API
19
     */
20
    private $api;
21
22
    /**
23
     * @var string
24
     */
25
    private $country;
26
27
    /**
28
     * @var string
29
     */
30
    private $language;
31
32 1
    public function __construct(
33
        string $affiliateId,
34
        string $country,
35
        string $language = null,
36
        \Careerjet_API $api = null
37
    ) {
38 1
        $this->affiliateId = $affiliateId;
39 1
        $this->country = $country;
40 1
        $this->language = $language;
41
42 1
        $this->api = !empty($api) ? $api : new \Careerjet_API(Locale::byCountryAndLanguage($country, $language));
43 1
    }
44
45
    /**
46
     * @param array $filters
47
     *
48
     * @return JobCollection
49
     * @throws Exception\CareerjetException
50
     */
51 1
    public function search(array $filters = []) : JobCollection
52
    {
53 1
        $collection = new JobCollection;
54 1
        $search = ['affid' => $this->affiliateId];
55 1
        if (isset($filters['keywords'])) { // empty allowed
56 1
            $search['keywords'] = $filters['keywords'];
57
        }
58 1
        if (isset($filters['location'])) { // empty allowed
59 1
            $search['location'] = $filters['location'];
60
        }
61 1
        if (isset($filters['limit'])) { // max 99
62 1
            $search['pagesize'] = $filters['limit'];
63
        }
64 1
        $search['page'] = isset($filters['offset']) ? $filters['offset'] : 1; // starts on 1
65
66 1
        $result = $this->api->search($search);
67 1
        foreach ($result->jobs as $job) {
68 1
            $collection->add(JobBuilder::fromApi($job, $this->country));
69
        }
70
71 1
        return $collection;
72
    }
73
}
74