Skip to content

Commit 587dff4

Browse files
committed
refactor: Improve code quality
1 parent f67255d commit 587dff4

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

src/Exceptions/XmlException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace Scriptotek\Marc\Exceptions;
44

5+
use LibXMLError;
6+
57
class XmlException extends \RuntimeException
68
{
7-
public function __construct($errors)
9+
public function __construct(array $errors)
810
{
9-
$details = array_map(function ($error) {
11+
$details = array_map(function (LibXMLError $error) {
1012
return $error->message;
1113
}, $errors);
1214
parent::__construct('Failed loading XML: \n' . implode('\n', $details));

src/Factory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Factory
66
{
7-
protected function _make($className, $args)
7+
protected function genMake($className, $args)
88
{
99
$reflectionClass = new \ReflectionClass($className);
1010
$instance = $reflectionClass->newInstanceArgs($args);
@@ -17,14 +17,14 @@ public function make()
1717
$args = func_get_args();
1818
$className = array_shift($args);
1919

20-
return $this->_make($className, $args);
20+
return $this->genMake($className, $args);
2121
}
2222

2323
public function makeField()
2424
{
2525
$args = func_get_args();
2626
$className = 'Scriptotek\\Marc\\Fields\\' . array_shift($args);
2727

28-
return $this->_make($className, $args);
28+
return $this->genMake($className, $args);
2929
}
3030
}

src/Fields/Title.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public function __toString()
4646
// (for instance when the title is an abbreviation)
4747
$title = rtrim($title, ' /');
4848

49-
// TODO: Handle more subfields like $k, $f and $g ?? Probably should...
50-
5149
return $title;
5250
}
5351
}

src/Importers/XmlImporter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
use Scriptotek\Marc\Collection;
77
use Scriptotek\Marc\Exceptions\XmlException;
88
use Scriptotek\Marc\Factory;
9+
use SimpleXMLElement;
910

1011
class XmlImporter
1112
{
1213
protected $factory;
14+
15+
/* var SimpleXMLElement */
1316
protected $source;
1417

1518
public function __construct($data, $ns = '', $isPrefix = false, $factory = null)
@@ -76,7 +79,7 @@ public function getCollection()
7679
list($prefix, $ns) = $this->getMarcNamespace($records[0]->getNamespaces(true));
7780
$pprefix = empty($prefix) ? '' : "$prefix:";
7881

79-
$records = array_map(function ($record) {
82+
$records = array_map(function (SimpleXMLElement $record) {
8083
$x = $record->asXML();
8184

8285
// Strip away XML declaration.

src/Record.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function getTitle()
180180
*/
181181
public function getSubjects($vocabulary = null, $tag = null)
182182
{
183-
return array_filter(Subject::get($this), function ($field) use ($vocabulary, $tag) {
183+
return array_filter(Subject::get($this), function (Subject $field) use ($vocabulary, $tag) {
184184
$a = is_null($vocabulary) || $vocabulary == $field->vocabulary;
185185
$b = is_null($tag) || $tag == $field->type;
186186

0 commit comments

Comments
 (0)