Conditions | 32 |
Paths | 13440 |
Total Lines | 109 |
Code Lines | 63 |
Lines | 12 |
Ratio | 11.01 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
120 | public function transform(JobInterface $job, $options = []) |
||
121 | { |
||
122 | $applyUrl = $this->getApplyUrlHelper(); |
||
123 | $serverUrl = $this->getServerUrlHelper(); |
||
124 | $imageManager = $this->getOrganizationImageManager(); |
||
125 | |||
126 | /* @var \Jobs\Entity\Job $job */ |
||
127 | $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><job></job>'); |
||
128 | |||
129 | /* |
||
130 | * FOR TESTING |
||
131 | */ |
||
132 | $xml->addChild('test', 'true'); |
||
133 | |||
134 | |||
135 | $xml->addChild('action', isset($options['action']) ? $options['action'] : 'post'); |
||
136 | |||
137 | if (isset($options['externalId'])) { |
||
138 | $xml->addChild('jobid', $options['externalId']); |
||
139 | } |
||
140 | |||
141 | $xml->addChild('title', $job->getTitle()); |
||
142 | $xml->addChild('company', $job->getOrganization()->getOrganizationName()->getName()); |
||
143 | $xml->addChild('companyurl', $job->getOrganization()->getContact()->getWebsite() ?: 'http://cross-solution.de'); |
||
144 | if ($image = $job->getOrganization()->getImage() && $serverUrl && $imageManager) { |
||
|
|||
145 | $imageUri = $imageManager->getUri($image); |
||
146 | $xml->addChild('logourl', $serverUrl($imageUri)); |
||
147 | } |
||
148 | |||
149 | if ($companyDesc = $job->getOrganization()->getDescription()) { |
||
150 | $xml->addChild('aboutcompany', $companyDesc); |
||
151 | } |
||
152 | |||
153 | $xml->addChild('vendorid', $job->getId()); |
||
154 | |||
155 | $atsMode = $job->getAtsMode(); |
||
156 | if ($atsMode->isDisabled()) { |
||
157 | $xml->addChild('howtoapply', 'postalisch'); |
||
158 | } else if ($atsMode->isEmail()) { |
||
159 | $xml->addChild('howtoapply', $atsMode->getEmail()); |
||
160 | } else if ($atsMode->isUri()) { |
||
161 | $xml->addChild('howtoapply', $atsMode->getUri()); |
||
162 | } else if (is_callable($applyUrl) && $serverUrl) { |
||
163 | $xml->addChild('howtoapply', $serverUrl($applyUrl($job, ['linkOnly' => true, 'absolute' => true]))); |
||
164 | } else { |
||
165 | $xml->addChild('howtoapply', 'postalisch'); |
||
166 | } |
||
167 | |||
168 | |||
169 | |||
170 | $locations = $job->getLocations(); |
||
171 | if ($locations->count()) { |
||
172 | $loc = $xml->addChild('locations'); |
||
173 | |||
174 | foreach ($locations as $location) { |
||
175 | $l = $loc->addChild('location', $location->getCity()); |
||
176 | $coords = $location->getCoordinates(); |
||
177 | if (CoordinatesInterface::TYPE_POINT == $coords->getType()) { |
||
178 | $c = $coords->getCoordinates(); |
||
179 | $l->addAttribute('lon', $c[0]); |
||
180 | $l->addAttribute('lat', $c[1]); |
||
181 | } |
||
182 | } |
||
183 | } |
||
184 | |||
185 | foreach (['topspot', 'featured', 'remote', 'relocation', 'visasponsorship', 'sysadmin'] as $boolOpt) { |
||
186 | if (isset($options[$boolOpt])) { |
||
187 | $xml->addChild($boolOpt, $options[$boolOpt] ? 'true' : 'false'); |
||
188 | } |
||
189 | } |
||
190 | |||
191 | foreach (['length', 'coupon', 'pixel'] as $strOpt) { |
||
192 | if (isset($options[$strOpt])) { |
||
193 | $xml->addChild($strOpt, $options[$strOpt]); |
||
194 | } |
||
195 | } |
||
196 | |||
197 | $xml->addChild('description', html_entity_decode($job->getTemplateValues()->getDescription()) ?: '<p></p>'); |
||
198 | |||
199 | if ($requirements = $job->getTemplateValues()->getRequirements()) { |
||
200 | $xml->addChild('requirements', $requirements); |
||
201 | } |
||
202 | |||
203 | $tags = $xml->addChild('tags'); |
||
204 | if (isset($options['keywords']) && is_array($options['keyword'])) { |
||
205 | foreach ($options['keywords'] as $keyword) { |
||
206 | $tags->addChild('tag', $keyword); |
||
207 | } |
||
208 | } else { |
||
209 | $tags->addChild('tag', 'none'); |
||
210 | } |
||
211 | |||
212 | View Code Duplication | if (isset($options['advertisingregions']) && is_array($options['advertisingregions'])) { |
|
213 | $regions = $xml->addChild('advertisingregioncodes'); |
||
214 | foreach ($options['advertisingregions'] as $adreg) { |
||
215 | $regions->addChild('regioncode', $adreg); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | View Code Duplication | if (isset($options['advertisingcountries']) && is_array($options['advertisingcountries'])) { |
|
220 | $countries = $xml->addChild('advertisingcountrycodes'); |
||
221 | foreach ($options['advertisingcountries'] as $adcountry) { |
||
222 | $countries->addChild('regioncode', $adcountry); |
||
223 | } |
||
224 | } |
||
225 | |||
226 | |||
227 | return $xml->asXml(); |
||
228 | } |
||
229 | } |