Conditions | 16 |
Paths | 39 |
Total Lines | 93 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
80 | public function __construct(QuiteSimpleXmlElement $data = null) |
||
81 | { |
||
82 | if (is_null($data)) { |
||
83 | return; |
||
84 | } |
||
85 | |||
86 | $this->id = $data->text('marc:controlfield[@tag="001"]'); // Dokid |
||
87 | |||
88 | $this->bibliographic_record = $data->text('marc:controlfield[@tag="004"]') ?: null; // Objektid |
||
|
|||
89 | |||
90 | $fulltext = array(); |
||
91 | $nonpublic_notes = array(); |
||
92 | $public_notes = array(); |
||
93 | |||
94 | // 008: Extract datestamp only |
||
95 | $f008 = $data->text('marc:controlfield[@tag="008"]'); |
||
96 | $this->created = $this->parseDateTime(substr($f008, 0, 6)); |
||
97 | |||
98 | // 009: Reserved for local use |
||
99 | $this->status = $data->text('marc:controlfield[@tag="009"]'); |
||
100 | |||
101 | foreach ($data->all('marc:datafield') as $node) { |
||
102 | $marcfield = intval($node->attributes()->tag); |
||
103 | switch ($marcfield) { |
||
104 | |||
105 | case 852: |
||
106 | // http://www.loc.gov/marc/holdings/concise/hd852.html |
||
107 | $this->location = $node->text('marc:subfield[@code="a"]'); // NR |
||
108 | $this->sublocation = $node->text('marc:subfield[@code="b"]'); // R (i praksis??) |
||
109 | $this->shelvinglocation = $node->text('marc:subfield[@code="c"]'); // R (i praksis??) |
||
110 | $this->callcode = $node->text('marc:subfield[@code="h"]'); // NR |
||
111 | |||
112 | if (($x = $node->text('marc:subfield[@code="x"]')) !== '') { // R |
||
113 | $nonpublic_notes[] = $x; |
||
114 | } |
||
115 | if (($x = $node->text('marc:subfield[@code="z"]')) !== '') { // R |
||
116 | $public_notes[] = $x; |
||
117 | } |
||
118 | |||
119 | break; |
||
120 | |||
121 | case 856: |
||
122 | $description = $node->text('marc:subfield[@code="3"]'); |
||
123 | if (in_array($description, array('Fulltekst', 'Fulltext'))) { |
||
124 | $fulltext[] = array( |
||
125 | 'url' => $node->text('marc:subfield[@code="u"]'), |
||
126 | 'linktext' => $node->text('marc:subfield[@code="y"]'), |
||
127 | 'comment' => $node->text('marc:subfield[@code="z"]'), |
||
128 | ); |
||
129 | } |
||
130 | break; |
||
131 | |||
132 | case 859: |
||
133 | // 859: Forslag til norsk tillegg til MARC 21 for utlånsstatus |
||
134 | // http://www.bibsys.no/files/out/biblev/utlaanstatus-marc21.pdf |
||
135 | // 859 $f: Use restrictions / Tilgjengelighet |
||
136 | $x = $node->text('marc:subfield[@code="f"]'); |
||
137 | if ($x !== '') { |
||
138 | if (isset(self::$m859_f[$x])) { |
||
139 | $this->use_restrictions = self::$m859_f[$x]; |
||
140 | } |
||
141 | } |
||
142 | |||
143 | $x = $node->text('marc:subfield[@code="h"]'); |
||
144 | if ($x !== '') { |
||
145 | if (isset(self::$m859_h[$x])) { |
||
146 | $this->circulation_status = self::$m859_h[$x]; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | break; |
||
151 | |||
152 | case 866: |
||
153 | // 866: Textual Holdings-General Information |
||
154 | $this->holdings = $node->text('marc:subfield[@code="a"]'); |
||
155 | |||
156 | break; |
||
157 | |||
158 | case 876: |
||
159 | // 866: Item Information - Basic Bibliographic Unit |
||
160 | // $d - Date acquired (R) |
||
161 | $this->acquired = $this->parseDateTime($node->text('marc:subfield[@code="d"]')); |
||
162 | $this->barcode = $node->text('marc:subfield[@code="p"]'); |
||
163 | //$this->status = $node->text('marc:subfield[@code="j"]'); |
||
164 | break; |
||
165 | |||
166 | } |
||
167 | } |
||
168 | |||
169 | $this->fulltext = $fulltext; |
||
170 | $this->nonpublic_notes = $nonpublic_notes; |
||
171 | $this->public_notes = $public_notes; |
||
172 | } |
||
173 | } |
||
174 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.