Conditions | 3 |
Paths | 3 |
Total Lines | 80 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 | // Langue |
||
52 | 'langue' => $this->lang2wiki($this->xpath2string('//mxc:datafield[@tag="101"]/mxc:subfield[@code="a"][1]')), |
||
53 | // c : Langue de l’œuvre originale |
||
54 | 'langue originale' => $this->stripLangFR( |
||
55 | $this->lang2wiki( |
||
56 | $this->xpath2string('//mxc:datafield[@tag="101"]/mxc:subfield[@code="c"][1]') |
||
57 | ) |
||
58 | ), |
||
59 | // g : Langue du titre propre (si différent) |
||
60 | 'langue titre' => $this->stripLangFR( |
||
61 | $this->lang2wiki( |
||
62 | $this->xpath2string('//mxc:datafield[@tag="101"]/mxc:subfield[@code="g"][1]') |
||
63 | ) |
||
64 | ), |
||
65 | /* |
||
66 | * Bloc 200. |
||
67 | * https://www.transition-bibliographique.fr/wp-content/uploads/2019/11/B200-2018.pdf |
||
68 | */ // a : Titre propre |
||
69 | 'titre' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="a"][1]'), |
||
70 | // d : Titre parralèle (autre langue) |
||
71 | 'titre original' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="d"][1]'), |
||
72 | // e : Complément du titre |
||
73 | 'sous-titre' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="e"][1]', ', '), |
||
74 | |||
75 | // Responsabilités : zone 200 trop merdique "Pierre Durand, Paul Dupond" ou "Paul Durand,..." |
||
76 | 'prénom1' => $this->xpath2string('//mxc:datafield[@tag="700"]/mxc:subfield[@code="b"]'), |
||
77 | 'nom1' => $this->xpath2string('//mxc:datafield[@tag="700"]/mxc:subfield[@code="a"]'), |
||
78 | |||
79 | 'prénom2' => $this->xpath2string('//mxc:datafield[@tag="701"]/mxc:subfield[@code="b"]'), |
||
80 | 'nom2' => $this->xpath2string('//mxc:datafield[@tag="701"]/mxc:subfield[@code="a"]'), |
||
81 | |||
82 | // zone 200 |
||
83 | // h : Numéro de partie |
||
84 | // 'volume' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="h"]'), |
||
85 | // i : Titre de partie |
||
86 | // v : numéro de volume |
||
87 | 'volume' => $this->xpath2string('//mxc:datafield[@tag="200"]/mxc:subfield[@code="v"][1]'), |
||
88 | |||
89 | // 410 : collection |
||
90 | 'collection' => $this->xpath2string('//mxc:datafield[@tag="410"]/mxc:subfield[@code="a"][1]'), |
||
91 | |||
92 | // Auteur : voir plutôt 7XX |
||
93 | // https://www.transition-bibliographique.fr/wp-content/uploads/2018/07/B7XX-6-2011.pdf |
||
94 | |||
95 | // multi-zones |
||
96 | 'lieu' => $this->getLocation(), |
||
97 | 'éditeur' => $this->getPublisher(), |
||
98 | 'date' => $this->getPublishDate(), |
||
99 | // 215 |
||
100 | 'pages totales' => $this->convertPages(), |
||
101 | |||
102 | // 'bnf' => $this->convertBnfIdent(), // pertinent si isbn ? |
||
103 | 'isbn2' => $this->xpath2string('//mxc:datafield[@tag="010"]/mxc:subfield[@code="a"][2]'), |
||
104 | 'isbn' => $this->extractISBN(), |
||
105 | |||
106 | // hidden data |
||
107 | 'infos' => [ |
||
108 | 'source' => 'BnF', |
||
109 | 'sourceTag' => $this->sourceTag(), |
||
110 | 'bnfAuteur1' => $this->xpath2string('//mxc:datafield[@tag="700"][1]/mxc:subfield[@code="3"][1]'), |
||
111 | 'ISNIAuteur1' => $this->formatISNI( |
||
112 | $this->xpath2string('//mxc:datafield[@tag="700"][1]/mxc:subfield[@code="o"][1]') |
||
113 | ), |
||
114 | 'yearsAuteur1' => $this->xpath2string('//mxc:datafield[@tag="700"][1]/mxc:subfield[@code="f"][1]'), |
||
115 | ], |
||
291 |