Conditions | 3 |
Paths | 3 |
Total Lines | 65 |
Code Lines | 28 |
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 |
||
35 | public function process($xml): array |
||
36 | { |
||
37 | if (!$xml instanceof SimpleXMLElement) { |
||
38 | return []; |
||
39 | } |
||
40 | $this->xml = $xml; |
||
41 | |||
42 | // skip multi-records |
||
43 | $nbResults = (int)$xml->xpath('//srw:numberOfRecords[1]')[0] ?? 0; |
||
44 | if (1 !== $nbResults) { |
||
45 | echo "BNF : $nbResults records (skip)\n"; |
||
46 | |||
47 | return []; |
||
48 | } |
||
49 | |||
50 | return [ |
||
51 | // 'bnf' => $this->convertBnfIdent(), // pertinent si isbn ? |
||
52 | 'isbn' => $this->xpath2string('//mxc:datafield[@tag="010"]/mxc:subfield[@code="a"][1]'), |
||
53 | 'isbn2' => $this->xpath2string('//mxc:datafield[@tag="010"]/mxc:subfield[@code="a"][2]'), |
||
54 | |||
55 | // Langue |
||
56 | 'langue' => $this->lang2wiki($this->xpath2string('//mxc:datafield[@tag="101"]/mxc:subfield[@code="a"][1]')), |
||
57 | // c : Langue de l’œuvre originale |
||
58 | 'langue originale' => $this->stripLangFR( |
||
59 | $this->lang2wiki( |
||
60 | $this->xpath2string('//mxc:datafield[@tag="101"]/mxc:subfield[@code="c"][1]') |
||
61 | ) |
||
62 | ), |
||
63 | // g : Langue du titre propre (si différent) |
||
64 | 'langue titre' => $this->stripLangFR( |
||
65 | $this->lang2wiki( |
||
66 | $this->xpath2string('//mxc:datafield[@tag="101"]/mxc:subfield[@code="g"][1]') |
||
67 | ) |
||
68 | ), |
||
69 | /* |
||
70 | * Bloc 200. |
||
71 | * https://www.transition-bibliographique.fr/wp-content/uploads/2019/11/B200-2018.pdf |
||
72 | */ // a : Titre propre |
||
73 | 'titre' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="a"][1]'), |
||
74 | // d : Titre parralèle (autre langue) |
||
75 | 'titre original' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="d"][1]'), |
||
76 | // e : Complément du titre |
||
77 | 'sous-titre' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="e"][1]', ', '), |
||
78 | // f : responsabilité principale "Pierre Durand, Paul Dupond" (XML de dingue pour ça...) |
||
79 | 'auteur1' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="f"]', ', '), |
||
80 | // g : Mention de responsabilité suivante |
||
81 | 'auteur2' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="g"]', ', '), |
||
82 | // h : Numéro de partie |
||
83 | // 'volume' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="h"]'), |
||
84 | // i : Titre de partie |
||
85 | // v : numéro de volume |
||
86 | 'volume' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="v"][1]'), |
||
87 | |||
88 | // 410 : collection |
||
89 | 'collection' => $this->xpath2string('//mxc:datafield[@tag="410"]/mxc:subfield[@code="a"][1]'), |
||
90 | |||
91 | // Auteur : voir plutôt 7XX |
||
92 | // https://www.transition-bibliographique.fr/wp-content/uploads/2018/07/B7XX-6-2011.pdf |
||
93 | |||
94 | // multi-zones |
||
95 | 'lieu' => $this->getLocation(), |
||
96 | 'éditeur' => $this->getPublisher(), |
||
97 | 'date' => $this->getPublishDate(), |
||
98 | // 215 |
||
99 | 'pages totales' => $this->convertPages(), |
||
100 | ]; |
||
229 |