| Conditions | 8 |
| Paths | 85 |
| Total Lines | 83 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 19 | public function parse(WriterInterface $writer) |
||
| 20 | { |
||
| 21 | $uri = 'http://php.net/archive/archive.xml'; |
||
| 22 | $client = new Client(); |
||
| 23 | $content = $client->get($uri)->getBody(); |
||
| 24 | |||
| 25 | $contents = new \ArrayObject(); |
||
|
|
|||
| 26 | $now = new \DateTimeImmutable(); |
||
| 27 | $then = $now->sub(new \DateInterval('P1Y')); |
||
| 28 | |||
| 29 | $dom = new \DOMDocument('1.0', 'UTF-8'); |
||
| 30 | $dom->loadXML($content, LIBXML_NOBLANKS ^ LIBXML_XINCLUDE); |
||
| 31 | $dom->documentURI = $uri; |
||
| 32 | |||
| 33 | $xpath = new \DOMXPath($dom); |
||
| 34 | $nodes = $xpath->query('//xi:include[@href]', $dom->parentNode); |
||
| 35 | |||
| 36 | foreach ($nodes as $item) { |
||
| 37 | /** @var \DOMNode $item */ |
||
| 38 | $href = $item->attributes->getNamedItem('href'); |
||
| 39 | if (! preg_match('/\/([\d\-]{10})/', $href->textContent, $result)) { |
||
| 40 | continue; |
||
| 41 | } |
||
| 42 | |||
| 43 | $date = new \DateTime($result[1]); |
||
| 44 | |||
| 45 | if (! $date instanceof \DateTime) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($then > $date) { |
||
| 50 | $item->parentNode->removeChild($item); |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | $dom->xinclude(); |
||
| 56 | $dom->normalizeDocument(); |
||
| 57 | |||
| 58 | $xpath->registerNamespace('default', 'http://php.net/ns/news'); |
||
| 59 | $xpath->registerNamespace('f', 'http://www.w3.org/2005/Atom'); |
||
| 60 | |||
| 61 | $items = $xpath->query('//f:category[@term="cfp"]'); |
||
| 62 | |||
| 63 | foreach ($items as $node) { |
||
| 64 | try { |
||
| 65 | /** @var \DOMNode $node */ |
||
| 66 | $node = $node->parentNode; |
||
| 67 | $item = $xpath->query('default:finalTeaserDate', $node)->item(0); |
||
| 68 | $cfpDate = new \DateTime($item->textContent); |
||
| 69 | |||
| 70 | if ($now > $cfpDate) { |
||
| 71 | continue; |
||
| 72 | } |
||
| 73 | |||
| 74 | $item = $xpath->query('published', $node)->item(0); |
||
| 75 | $cfpStart = new \DateTime($item->textContent); |
||
| 76 | var_Dump($cfpStart); |
||
| 77 | |||
| 78 | $info = new Cfp(); |
||
| 79 | |||
| 80 | $nameNodes = $xpath->query('f:title', $node); |
||
| 81 | $info->conferenceName = $nameNodes->item(0)->textContent; |
||
| 82 | |||
| 83 | $descNode = $xpath->query('f:content', $node)->item(0); |
||
| 84 | $info->description = $dom->saveXML($descNode); |
||
| 85 | |||
| 86 | $info->dateEnd = $cfpDate; |
||
| 87 | $info->dateStart = $cfpStart; |
||
| 88 | $info->tags = ['PHP']; |
||
| 89 | |||
| 90 | $cfpImageNode = $xpath->query('default:newsImage', $node)->item(0); |
||
| 91 | $info->uri = $cfpImageNode->attributes->getNamedItem('link')->textContent; |
||
| 92 | $info->conferenceUri = $cfpImageNode->attributes->getNamedItem('link')->textContent; |
||
| 93 | $info->iconUri = 'http://php.net/images/news/' . $cfpImageNode->textContent; |
||
| 94 | |||
| 95 | var_Dump($info->toArray()); |
||
| 96 | // $writer->write($info, 'php.net'); |
||
| 97 | } catch (\Exception $e) { |
||
| 98 | echo $e->getMessage() . "\n"; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 |
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.