| Conditions | 10 |
| Paths | 22 |
| Total Lines | 49 |
| Code Lines | 25 |
| 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 |
||
| 89 | private function convertGBurl2OuvrageCitation(string $url): string |
||
| 90 | { |
||
| 91 | if (!GoogleLivresTemplate::isGoogleBookURL($url)) { |
||
| 92 | throw new \DomainException('Pas de URL Google Books'); |
||
| 93 | } |
||
| 94 | |||
| 95 | $gooDat = GoogleLivresTemplate::parseGoogleBookQuery($url); |
||
| 96 | if (empty($gooDat['id'])) { |
||
| 97 | throw new \DomainException('Pas de ID Google Books'); |
||
| 98 | } |
||
| 99 | |||
| 100 | $ouvrage = $this->generateOuvrageFromGoogleData($gooDat['id']); |
||
| 101 | $cleanUrl = GoogleLivresTemplate::simplifyGoogleUrl($url); |
||
| 102 | $ouvrage->unsetParam('présentation en ligne'); |
||
| 103 | $ouvrage->setParam('lire en ligne', $cleanUrl); |
||
| 104 | $ouvrage->userSeparator = ' |'; |
||
| 105 | |||
| 106 | // Si titre absent |
||
| 107 | if (empty($ouvrage->getParam('titre'))) { |
||
| 108 | throw new \DomainException("Ouvrage sans titre (data Google?)"); |
||
| 109 | } |
||
| 110 | |||
| 111 | // Google page => 'passage' |
||
| 112 | if (!empty($gooDat['pg'])) { |
||
| 113 | if (preg_match('#(?:PA|PT)([0-9]+)$#', $gooDat['pg'], $matches)) { |
||
| 114 | // Exclusion de page=1, page=2 (vue par défaut sur Google Book) |
||
| 115 | if (intval($matches[1]) >= 3) { |
||
| 116 | $page = $matches[1]; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | // conversion chiffres Romain pour PR |
||
| 120 | if (preg_match('#PR([0-9]+)$#', $gooDat['pg'], $matches)) { |
||
| 121 | // Exclusion de page=1, page=2 (vue par défaut sur Google Book) |
||
| 122 | if (intval($matches[1]) >= 3) { |
||
| 123 | $page = NumberUtil::arab2roman(intval($matches[1])); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | if (isset($page)) { |
||
| 128 | $ouvrage->setParam('passage', $page); |
||
| 129 | // ajout commentaire '<!-- utile? -->' ? |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | $optimizer = new OuvrageOptimize($ouvrage); |
||
| 134 | $optimizer->doTasks(); |
||
| 135 | $ouvrage2 = $optimizer->getOuvrage(); |
||
| 136 | |||
| 137 | return $ouvrage2->serialize(); |
||
| 138 | } |
||
| 198 |