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