ZiprecruiterProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 99
ccs 35
cts 35
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createJobObject() 0 23 1
A getDefaultResponseFields() 0 18 1
A getListingsPath() 0 4 1
1
<?php namespace JobApis\Jobs\Client\Providers;
2
3
use JobApis\Jobs\Client\Job;
4
5
class ZiprecruiterProvider extends AbstractProvider
6
{
7
    /**
8
     * Map of setter methods to query parameters
9
     *
10
     * @var array
11
     */
12
    protected $queryMap = [
13
        'setApiKey' => 'api_key',
14
        'setSearch' => 'search',
15
        'setLocation' => 'location',
16
        'setRadiusMiles' => 'radius_miles',
17
        'setPage' => 'page',
18
        'setJobsPerPage' => 'jobs_per_page',
19
        'setDaysAgo' => 'days_ago',
20
        'setKeyword' => 'search',
21
        'setCount' => 'jobs_per_page',
22
    ];
23
24
    /**
25
     * Current api query parameters
26
     *
27
     * @var array
28
     */
29
    protected $queryParams = [
30
        'api_key' => null,
31
        'search' => null,
32
        'location' => null,
33
        'radius_miles' => null,
34
        'page' => null,
35
        'jobs_per_page' => null,
36
        'days_ago' => null,
37
    ];
38
39
    /**
40
     * Returns the standardized job object
41
     *
42
     * @param array $payload
43
     *
44
     * @return \JobApis\Jobs\Client\Job
45
     */
46 4
    public function createJobObject($payload)
47
    {
48 4
        $job = new Job([
49 4
            'title' => $payload['name'],
50 4
            'name' => $payload['name'],
51 4
            'description' => $payload['snippet'],
52 4
            'url' => $payload['url'],
53 4
            'sourceId' => $payload['id'],
54 4
            'location' => $payload['location'],
55 4
        ]);
56
57 4
        $job->setCompany($payload['hiring_company']['name'])
58 4
            ->setCompanyUrl($payload['hiring_company']['url'])
59 4
            ->setDatePostedAsString($payload['posted_time'])
60 4
            ->setCity($payload['city'])
61 4
            ->setState($payload['state']);
62
63 4
        $job->job_age = $payload['job_age'];
0 ignored issues
show
Bug introduced by
The property job_age does not seem to exist in JobApis\Jobs\Client\Job.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
64 4
        $job->posted_time_friendly = $payload['posted_time_friendly'];
0 ignored issues
show
Bug introduced by
The property posted_time_friendly does not seem to exist in JobApis\Jobs\Client\Job.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
65 4
        $job->has_non_zr_url = $payload['has_non_zr_url'];
0 ignored issues
show
Bug introduced by
The property has_non_zr_url does not seem to exist in JobApis\Jobs\Client\Job.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
66
67 4
        return $job;
68
    }
69
70
    /**
71
     * Job response object default keys that should be set
72
     *
73
     * @return  array
74
     */
75 4
    public function getDefaultResponseFields()
76
    {
77
        return [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('source', '...ry', 'hiring_company'); (string[]) is incompatible with the return type declared by the abstract method JobApis\Jobs\Client\Prov...etDefaultResponseFields of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
78 4
            'source',
79 4
            'id',
80 4
            'name',
81 4
            'snippet',
82 4
            'category',
83 4
            'posted_time',
84 4
            'posted_time_friendly',
85 4
            'url',
86 4
            'location',
87 4
            'city',
88 4
            'state',
89 4
            'country',
90 4
            'hiring_company',
91 4
        ];
92
    }
93
94
    /**
95
     * Get listings path
96
     *
97
     * @return  string
98
     */
99 4
    public function getListingsPath()
100
    {
101 4
        return 'jobs';
102
    }
103
}
104