| Conditions | 20 |
| Paths | 79 |
| Total Lines | 92 |
| 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 |
||
| 28 | protected function processIsbn() |
||
| 29 | { |
||
| 30 | $isbn = $this->getParam('isbn') ?? ''; |
||
|
|
|||
| 31 | if (empty($isbn)) { |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | |||
| 35 | // ISBN-13 à partir de 2007 |
||
| 36 | $year = $this->findBookYear(); |
||
| 37 | if ($year !== null && $year < 2007 && 10 === strlen($this->stripIsbn($isbn))) { |
||
| 38 | // juste mise en forme ISBN-10 pour 'isbn' |
||
| 39 | try { |
||
| 40 | $isbnMachine = new IsbnFacade($isbn); |
||
| 41 | $isbnMachine->validate(); |
||
| 42 | $isbn10pretty = $isbnMachine->format('ISBN-10'); |
||
| 43 | if ($isbn10pretty !== $isbn) { |
||
| 44 | $this->setParam('isbn', $isbn10pretty); |
||
| 45 | $this->addSummaryLog('ISBN10'); |
||
| 46 | // $this->notCosmetic = true; |
||
| 47 | } |
||
| 48 | } catch (Throwable $e) { |
||
| 49 | // ISBN not validated |
||
| 50 | $this->setParam( |
||
| 51 | 'isbn invalide', |
||
| 52 | sprintf('%s %s', $isbn, $e->getMessage() ?? '') |
||
| 53 | ); |
||
| 54 | $this->addSummaryLog(sprintf('ISBN invalide: %s', $e->getMessage())); |
||
| 55 | $this->notCosmetic = true; |
||
| 56 | } |
||
| 57 | |||
| 58 | return; |
||
| 59 | } |
||
| 60 | |||
| 61 | try { |
||
| 62 | $isbnMachine = new IsbnFacade($isbn); |
||
| 63 | $isbnMachine->validate(); |
||
| 64 | $isbn13 = $isbnMachine->format('ISBN-13'); |
||
| 65 | } catch (Throwable $e) { |
||
| 66 | // ISBN not validated |
||
| 67 | // TODO : bot ISBN invalide (queue, message PD...) |
||
| 68 | $this->setParam( |
||
| 69 | 'isbn invalide', |
||
| 70 | sprintf('%s %s', $isbn, $e->getMessage() ?? '') |
||
| 71 | ); |
||
| 72 | $this->addSummaryLog(sprintf('ISBN invalide: %s', $e->getMessage())); |
||
| 73 | $this->notCosmetic = true; |
||
| 74 | |||
| 75 | // TODO log file ISBNinvalide |
||
| 76 | return; |
||
| 77 | } |
||
| 78 | |||
| 79 | // Si $isbn13 et 'isbn2' correspond à ISBN-13 => suppression |
||
| 80 | if (isset($isbn13) |
||
| 81 | && $this->hasParamValue('isbn2') |
||
| 82 | && $this->stripIsbn($this->getParam('isbn2')) === $this->stripIsbn($isbn13) |
||
| 83 | ) { |
||
| 84 | $this->unsetParam('isbn2'); |
||
| 85 | } |
||
| 86 | |||
| 87 | // ISBN-10 ? |
||
| 88 | $stripIsbn = $this->stripIsbn($isbn); |
||
| 89 | if (10 === mb_strlen($stripIsbn)) { |
||
| 90 | // ajout des tirets |
||
| 91 | $isbn10pretty = $isbn; |
||
| 92 | |||
| 93 | try { |
||
| 94 | $isbn10pretty = $isbnMachine->format('ISBN-10'); |
||
| 95 | } catch (Throwable $e) { |
||
| 96 | unset($e); |
||
| 97 | } |
||
| 98 | |||
| 99 | // archivage ISBN-10 dans 'isbn2' |
||
| 100 | if (!$this->getParam('isbn2')) { |
||
| 101 | $this->setParam('isbn2', $isbn10pretty); |
||
| 102 | } |
||
| 103 | // sinon dans 'isbn3' |
||
| 104 | if ($this->hasParamValue('isbn2') |
||
| 105 | && $this->stripIsbn($this->getParam('isbn2')) !== $stripIsbn |
||
| 106 | && empty($this->getParam('isbn3')) |
||
| 107 | ) { |
||
| 108 | $this->setParam('isbn3', $isbn10pretty); |
||
| 109 | } |
||
| 110 | // delete 'isbn10' (en attendant modification modèle) |
||
| 111 | if ($this->hasParamValue('isbn10') && $this->stripIsbn($this->getParam('isbn10')) === $stripIsbn) { |
||
| 112 | $this->unsetParam('isbn10'); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | // ISBN correction |
||
| 117 | if ($isbn13 !== $isbn) { |
||
| 118 | $this->setParam('isbn', $isbn13); |
||
| 119 | $this->addSummaryLog('ISBN'); |
||
| 120 | // $this->notCosmetic = true; |
||
| 124 |