| Conditions | 29 |
| Paths | 13440 |
| Total Lines | 106 |
| Code Lines | 60 |
| Lines | 12 |
| Ratio | 11.32 % |
| 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 |
||
| 64 | public function transform(JobInterface $job, $options = []) |
||
| 65 | { |
||
| 66 | $applyUrl = $this->getApplyUrlHelper(); |
||
| 67 | |||
| 68 | /* @var \Jobs\Entity\Job $job */ |
||
| 69 | $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><job></job>'); |
||
| 70 | |||
| 71 | /* |
||
| 72 | * FOR TESTING |
||
| 73 | */ |
||
| 74 | $xml->addChild('test', 'true'); |
||
| 75 | |||
| 76 | |||
| 77 | $xml->addChild('action', isset($options['action']) ? $options['action'] : 'post'); |
||
| 78 | |||
| 79 | if (isset($options['externalId'])) { |
||
| 80 | $xml->addChild('jobid', $options['externalId']); |
||
| 81 | } |
||
| 82 | |||
| 83 | $xml->addChild('title', $job->getTitle()); |
||
| 84 | $xml->addChild('company', $job->getOrganization()->getOrganizationName()->getName()); |
||
| 85 | $xml->addChild('companyurl', $job->getOrganization()->getContact()->getWebsite() ?: 'http://cross-solution.de'); |
||
| 86 | if ($image = $job->getOrganization()->getImage()) { |
||
|
|
|||
| 87 | $xml->addChild('logourl', $job->getOrganization()->getImage()->getUri()); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($companyDesc = $job->getOrganization()->getDescription()) { |
||
| 91 | $xml->addChild('aboutcompany', $companyDesc); |
||
| 92 | } |
||
| 93 | |||
| 94 | $xml->addChild('vendorid', $job->getId()); |
||
| 95 | |||
| 96 | $atsMode = $job->getAtsMode(); |
||
| 97 | if ($atsMode->isDisabled()) { |
||
| 98 | $xml->addChild('howtoapply', 'postalisch'); |
||
| 99 | } else if ($atsMode->isEmail()) { |
||
| 100 | $xml->addChild('howtoapply', $atsMode->getEmail()); |
||
| 101 | } else if ($atsMode->isUri()) { |
||
| 102 | $xml->addChild('howtoapply', $atsMode->getUri()); |
||
| 103 | } else if (is_callable($applyUrl)) { |
||
| 104 | $xml->addChild('howtoapply', $applyUrl($job, ['linkOnly' => true, 'absolute' => true])); |
||
| 105 | } else { |
||
| 106 | $xml->addChild('howtoapply', 'postalisch'); |
||
| 107 | } |
||
| 108 | |||
| 109 | |||
| 110 | |||
| 111 | $locations = $job->getLocations(); |
||
| 112 | if ($locations->count()) { |
||
| 113 | $loc = $xml->addChild('locations'); |
||
| 114 | |||
| 115 | foreach ($locations as $location) { |
||
| 116 | $l = $loc->addChild('location', $location->getCity()); |
||
| 117 | $coords = $location->getCoordinates(); |
||
| 118 | if (CoordinatesInterface::TYPE_POINT == $coords->getType()) { |
||
| 119 | $c = $coords->getCoordinates(); |
||
| 120 | $l->addAttribute('lon', $c[0]); |
||
| 121 | $l->addAttribute('lat', $c[1]); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | foreach (['topspot', 'featured', 'remote', 'relocation', 'visasponsorship', 'sysadmin'] as $boolOpt) { |
||
| 127 | if (isset($options[$boolOpt])) { |
||
| 128 | $xml->addChild($boolOpt, $options[$boolOpt] ? 'true' : 'false'); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | foreach (['length', 'coupon', 'pixel'] as $strOpt) { |
||
| 133 | if (isset($options[$strOpt])) { |
||
| 134 | $xml->addChild($strOpt, $options[$strOpt]); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | $xml->addChild('description', $job->getTemplateValues()->getDescription() ?: '<p>Porta magna lectus architect evangelist. Monad dolores unibody gubergren combinator VC. NoSQL viral pre-IPO disruptive in event-driven vel :). Exploit monkey patch gubergren functional agile. Consetetur justo architect async crowdfunding eos usability! Kasd massa dolores tincidunt web-scale vesting schedule diam :). Et stet in agile.</p>'); |
||
| 139 | |||
| 140 | if ($requirements = $job->getTemplateValues()->getRequirements()) { |
||
| 141 | $xml->addChild('requirements', $requirements); |
||
| 142 | } |
||
| 143 | |||
| 144 | $tags = $xml->addChild('tags'); |
||
| 145 | if (isset($options['keywords']) && is_array($options['keyword'])) { |
||
| 146 | foreach ($options['keywords'] as $keyword) { |
||
| 147 | $tags->addChild('tag', $keyword); |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | $tags->addChild('tag', 'none'); |
||
| 151 | } |
||
| 152 | |||
| 153 | View Code Duplication | if (isset($options['advertisingregions']) && is_array($options['advertisingregions'])) { |
|
| 154 | $regions = $xml->addChild('advertisingregioncodes'); |
||
| 155 | foreach ($options['advertisingregions'] as $adreg) { |
||
| 156 | $regions->addChild('regioncode', $adreg); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | View Code Duplication | if (isset($options['advertisingcountries']) && is_array($options['advertisingcountries'])) { |
|
| 161 | $countries = $xml->addChild('advertisingcountrycodes'); |
||
| 162 | foreach ($options['advertisingcountries'] as $adcountry) { |
||
| 163 | $countries->addChild('regioncode', $adcountry); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | |||
| 168 | return $xml->asXml(); |
||
| 169 | } |
||
| 170 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.