jobapis /
jobs-muse
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php namespace JobApis\Jobs\Client\Providers; |
||
| 2 | |||
| 3 | use JobApis\Jobs\Client\Job; |
||
| 4 | |||
| 5 | class MuseProvider extends AbstractProvider |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Returns the standardized job object |
||
| 9 | * |
||
| 10 | * @param array $payload Raw job payload from the API |
||
| 11 | * |
||
| 12 | * @return \JobApis\Jobs\Client\Job |
||
| 13 | */ |
||
| 14 | 4 | public function createJobObject($payload = []) |
|
| 15 | { |
||
| 16 | 4 | $job = new Job([ |
|
| 17 | 4 | 'title' => $payload['name'], |
|
| 18 | 4 | 'name' => $payload['name'], |
|
| 19 | 4 | 'description' => $payload['contents'], |
|
| 20 | 4 | 'url' => $payload['refs']['landing_page'], |
|
| 21 | 4 | 'sourceId' => $payload['id'], |
|
| 22 | 4 | ]); |
|
| 23 | |||
| 24 | // categories array |
||
| 25 | 4 | $this->setCategories($job, $payload['categories']); |
|
| 26 | |||
| 27 | // company array |
||
| 28 | 4 | $this->setCompany($job, $payload['company']); |
|
| 29 | |||
| 30 | // levels array |
||
| 31 | 4 | $this->setLevels($job, $payload['levels']); |
|
| 32 | |||
| 33 | // locations array |
||
| 34 | 4 | $this->setLocation($job, $payload['locations']); |
|
| 35 | |||
| 36 | 4 | return $job; |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Job response object default keys that should be set |
||
| 41 | * |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | 4 | public function getDefaultResponseFields() |
|
| 45 | { |
||
| 46 | return [ |
||
|
0 ignored issues
–
show
|
|||
| 47 | 4 | 'levels', // array |
|
| 48 | 4 | 'locations', // array |
|
| 49 | 4 | 'tags', // array |
|
| 50 | 4 | 'categories', // array |
|
| 51 | 4 | 'publication_date', |
|
| 52 | 4 | 'short_name', |
|
| 53 | 4 | 'refs', // array |
|
| 54 | 4 | 'contents', |
|
| 55 | 4 | 'type', |
|
| 56 | 4 | 'model_type', |
|
| 57 | 4 | 'company', // array |
|
| 58 | 4 | 'id', |
|
| 59 | 4 | 'name', |
|
| 60 | 4 | ]; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get listings path |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | 4 | public function getListingsPath() |
|
| 69 | { |
||
| 70 | 4 | return 'results'; |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Sets the categories on the job using the categories array |
||
| 75 | * |
||
| 76 | * @param Job $job |
||
| 77 | * @param array $categories |
||
| 78 | * |
||
| 79 | * @return MuseProvider |
||
| 80 | */ |
||
| 81 | 4 | protected function setCategories(Job $job, $categories = []) |
|
| 82 | { |
||
| 83 | 4 | $occupationalCats = []; |
|
| 84 | 4 | foreach ($categories as $category) { |
|
| 85 | 4 | $occupationalCats[] = $category['name']; |
|
| 86 | 4 | } |
|
| 87 | 4 | if ($occupationalCats) { |
|
|
0 ignored issues
–
show
The expression
$occupationalCats of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 88 | 4 | $job->setOccupationalCategory(implode(', ', $occupationalCats)); |
|
| 89 | 4 | } |
|
| 90 | 4 | return $this; |
|
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Sets the company on the job using the company array |
||
| 95 | * |
||
| 96 | * @param Job $job |
||
| 97 | * @param array $company |
||
| 98 | * |
||
| 99 | * @return MuseProvider |
||
| 100 | */ |
||
| 101 | 4 | protected function setCompany(Job $job, $company = []) |
|
| 102 | { |
||
| 103 | 4 | if ($company && isset($company['name'])) { |
|
|
0 ignored issues
–
show
The expression
$company of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 104 | 4 | $job->setCompany($company['name']); |
|
| 105 | 4 | } |
|
| 106 | 4 | return $this; |
|
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Sets the experience levels on the job using the levels array |
||
| 111 | * |
||
| 112 | * @param Job $job |
||
| 113 | * @param array $levels |
||
| 114 | * |
||
| 115 | * @return MuseProvider |
||
| 116 | */ |
||
| 117 | 4 | protected function setLevels(Job $job, $levels = []) |
|
| 118 | { |
||
| 119 | 4 | $requirements = []; |
|
| 120 | 4 | foreach ($levels as $level) { |
|
| 121 | 4 | $requirements[] = $level['name']; |
|
| 122 | 4 | } |
|
| 123 | 4 | if ($requirements) { |
|
|
0 ignored issues
–
show
The expression
$requirements of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 124 | 4 | $job->setExperienceRequirements(implode(', ', $requirements)); |
|
| 125 | 4 | } |
|
| 126 | 4 | return $this; |
|
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Sets the location on the job using the first location in the array |
||
| 131 | * |
||
| 132 | * @param Job $job |
||
| 133 | * @param array $locations |
||
| 134 | * |
||
| 135 | * @return MuseProvider |
||
| 136 | */ |
||
| 137 | 4 | protected function setLocation(Job $job, $locations = []) |
|
| 138 | { |
||
| 139 | 4 | if (isset($locations[0]) && isset($locations[0]['name'])) { |
|
| 140 | 4 | $job->setLocation($locations[0]['name']); |
|
| 141 | 4 | } |
|
| 142 | 4 | return $this; |
|
| 143 | } |
||
| 144 | } |
||
| 145 |
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:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.