| Conditions | 7 |
| Paths | 48 |
| Total Lines | 79 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 71 | private function updatePacks(Xdcc $xdcc) |
||
| 72 | { |
||
| 73 | $uri = $xdcc->getServer()->getFullUri().$xdcc->getUrl(); |
||
| 74 | |||
| 75 | $options = []; |
||
| 76 | if ($xdcc->getServer()->getSsl()) { |
||
| 77 | $options['curl.options'] = [ |
||
| 78 | 'CURLOPT_SSL_CIPHER_LIST' => 'ECDHE-ECDSA-AES256-SHA:ECDH-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDH-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDH-ECDSA-AES256-GCM-SHA384:ECDH-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES128-SHA256', |
||
| 79 | 'CURLOPT_SSL_VERIFYPEER' => false, |
||
| 80 | ]; |
||
| 81 | } |
||
| 82 | |||
| 83 | $client = new Client(); |
||
| 84 | $reponse = $client->get($uri, $options); |
||
| 85 | $service = new Service(); |
||
| 86 | $service->elementMap = [ |
||
| 87 | '{}iroffer' => 'Xdaysaysay\CoreBundle\XmlMapping\Iroffer', |
||
| 88 | '{}packlist' => 'Xdaysaysay\CoreBundle\XmlMapping\Packs', |
||
| 89 | '{}pack' => 'Xdaysaysay\CoreBundle\XmlMapping\Pack', |
||
| 90 | '{}network' => 'Xdaysaysay\CoreBundle\XmlMapping\Network', |
||
| 91 | '{}sysinfo' => 'Xdaysaysay\CoreBundle\XmlMapping\Sysinfo', |
||
| 92 | '{}mainqueue' => 'Xdaysaysay\CoreBundle\XmlMapping\Mainqueue', |
||
| 93 | '{}slots' => 'Xdaysaysay\CoreBundle\XmlMapping\Slots', |
||
| 94 | '{}idlequeue' => 'Xdaysaysay\CoreBundle\XmlMapping\Idlequeue', |
||
| 95 | '{}bandwidth' => 'Xdaysaysay\CoreBundle\XmlMapping\Bandwidth', |
||
| 96 | '{}quota' => 'Xdaysaysay\CoreBundle\XmlMapping\Quota', |
||
| 97 | '{}limits' => 'Xdaysaysay\CoreBundle\XmlMapping\Limits', |
||
| 98 | '{}stats' => 'Xdaysaysay\CoreBundle\XmlMapping\Stats', |
||
| 99 | ]; |
||
| 100 | |||
| 101 | /** @var Iroffer $iroffer */ |
||
| 102 | $iroffer = $service->parse($reponse->getBody()->getContents()); |
||
| 103 | |||
| 104 | foreach($xdcc->getXdccnames() as $xdccName) { |
||
| 105 | $xdcc->removeXdccname($xdccName); |
||
| 106 | } |
||
| 107 | foreach($xdcc->getPacks() as $pack) { |
||
| 108 | $xdcc->removePack($pack); |
||
| 109 | } |
||
| 110 | |||
| 111 | $this->getContainer()->get('doctrine')->getManager()->persist($xdcc); |
||
| 112 | $this->getContainer()->get('doctrine')->getManager()->flush(); |
||
| 113 | |||
| 114 | foreach ($iroffer->packlist->packs as $pack) { |
||
| 115 | $addDate = new \DateTime(); |
||
| 116 | $addDate->setTimestamp($pack->adddate); |
||
| 117 | |||
| 118 | $xdccPack = new Pack(); |
||
| 119 | $xdccPack->setId($pack->packnr); |
||
| 120 | $xdccPack->setName($pack->packname); |
||
| 121 | $xdccPack->setSize($pack->packbytes); |
||
| 122 | $xdccPack->setGets($pack->packgets); |
||
| 123 | $xdccPack->setAdddate($addDate); |
||
| 124 | $xdccPack->setMd5sum($pack->md5sum); |
||
| 125 | $xdccPack->setCrc32($pack->crc32); |
||
| 126 | $xdccPack->setXdcc($xdcc); |
||
| 127 | $xdcc->addPack($xdccPack); |
||
| 128 | } |
||
| 129 | |||
| 130 | foreach ($iroffer->sysinfo->networks as $network) { |
||
| 131 | $ircServer = $this->getContainer()->get('doctrine')->getRepository('XdaysaysayCoreBundle:IRCServer')->findOneByHost($network->servername); |
||
| 132 | if($ircServer) { |
||
| 133 | $xdccName = new XdccName(); |
||
| 134 | $xdccName->setXdcc($xdcc); |
||
| 135 | $xdccName->setName($network->currentnick); |
||
| 136 | $xdccName->setIrcServer($ircServer); |
||
| 137 | $xdcc->addXdccname($xdccName); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | $lastUpdate = new \DateTime(); |
||
| 142 | $lastUpdate->setTimestamp($iroffer->sysinfo->stats->lastupdate); |
||
| 143 | $xdcc->setLastupdate($lastUpdate); |
||
| 144 | $xdcc->setTotaluptime($iroffer->sysinfo->stats->totaluptime); |
||
| 145 | $xdcc->setDiskspace($iroffer->sysinfo->quota->diskspace); |
||
| 146 | |||
| 147 | $this->getContainer()->get('doctrine')->getManager()->persist($xdcc); |
||
| 148 | $this->getContainer()->get('doctrine')->getManager()->flush(); |
||
| 149 | } |
||
| 150 | } |