Skip to content

Commit fbd718f

Browse files
committed
PSR-2 fixes
1 parent 57cf7a6 commit fbd718f

File tree

12 files changed

+33
-14
lines changed

12 files changed

+33
-14
lines changed

src/Collection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,28 @@ class Collection
1414
public static function fromFile($filename)
1515
{
1616
$importer = new Importer($filename, true);
17+
1718
return $importer->getCollection();
1819
}
1920

2021
public static function fromString($data)
2122
{
2223
$importer = new Importer($data, false);
24+
2325
return $importer->getCollection();
2426
}
2527

2628
public static function fromOaiPmhResponse($data)
2729
{
2830
$importer = new OaiPmhResponse($data);
31+
2932
return $importer->getCollection();
3033
}
3134

3235
public static function fromSruResponse($data)
3336
{
3437
$importer = new SruResponse($data);
38+
3539
return $importer->getCollection();
3640
}
3741

@@ -49,7 +53,7 @@ public function parse($source, $isXml, $ns = '', $isPrefix = true)
4953
}
5054
}
5155

52-
public function __get($key='')
56+
public function __get($key = '')
5357
{
5458
if ($key == 'records') {
5559
// re-instantiaces..
@@ -59,6 +63,7 @@ public function __get($key='')
5963
if (is_null($this->_records)) {
6064
$this->_records = new Records($this->parser);
6165
}
66+
6267
return $this->_records;
6368
}
6469
}

src/Factory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ protected function _make($className, $args)
88
{
99
$reflectionClass = new \ReflectionClass($className);
1010
$instance = $reflectionClass->newInstanceArgs($args);
11+
1112
return $instance;
1213
}
1314

1415
public function make()
1516
{
1617
$args = func_get_args();
1718
$className = array_shift($args);
19+
1820
return $this->_make($className, $args);
1921
}
2022

2123
public function makeField()
2224
{
2325
$args = func_get_args();
2426
$className = 'Scriptotek\\Marc\\Fields\\' . array_shift($args);
27+
2528
return $this->_make($className, $args);
2629
}
2730
}

src/Fields/Isbn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function __toString()
88
{
99
$a = $this->field->getSubfield('a');
1010
if (!$a) {
11-
return null;
11+
return;
1212
}
1313

1414
// TODO: Other subfields?

src/Fields/Subject.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function getVocabulary()
2727
if ($sf2) {
2828
return $sf2->getData();
2929
}
30-
return null;
30+
31+
return;
3132
}
3233

3334
public function __toString()
@@ -38,6 +39,7 @@ public function __toString()
3839
$parts[] = $c->getData();
3940
}
4041
}
41-
return implode(Subject::$glue, $parts);
42+
43+
return implode(self::$glue, $parts);
4244
}
4345
}

src/Fields/Title.php

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

55
class Title extends Field implements FieldInterface
66
{
7-
87
/**
98
* See tests/TitleFieldTest.php for more info.
109
*/
@@ -13,14 +12,14 @@ public function __toString()
1312
// $a is not repeated
1413
$a = $this->field->getSubfield('a');
1514
if (!$a) {
16-
return null;
15+
return;
1716
}
1817
$title = trim($a->getData());
1918

2019
// $b is not repeated
2120
$b = $this->field->getSubfield('b');
2221
if ($b) {
23-
if (!in_array(substr($title, strlen($title) -1), array(':', ';', '=', '.'))) {
22+
if (!in_array(substr($title, strlen($title) - 1), array(':', ';', '=', '.'))) {
2423
// Add colon if no ISBD marker present ("British style")
2524
$title .= ' :';
2625
}

src/Importers/Importer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ public function getCollection()
2121
$isXml = (substr($this->data, 0, 1) == '<');
2222
if ($isXml) {
2323
$importer = new XmlImporter($this->data);
24+
2425
return $importer->getCollection();
2526
} else {
2627
$c = new Collection();
2728
$c->parse($this->data, false);
29+
2830
return $c;
2931
}
3032
}

src/Importers/XmlImporter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function getMarcNamespace($namespaces)
2929
return array($prefix, $ns);
3030
}
3131
}
32+
3233
return array('', '');
3334
}
3435

@@ -54,6 +55,7 @@ public function getRecords()
5455
if (count($marcRecords)) {
5556
return $marcRecords;
5657
}
58+
5759
return array();
5860
}
5961

@@ -64,7 +66,6 @@ public function getCollection()
6466
throw new \ErrorException("Uh oh, didn't find any records");
6567
}
6668

67-
6869
list($prefix, $ns) = $this->getMarcNamespace($records[0]->getNamespaces(true));
6970
$pprefix = empty($prefix) ? '' : "$prefix:";
7071

@@ -93,6 +94,7 @@ public function getCollection()
9394
'</' . $pprefix . 'collection>';
9495

9596
$this->collection->parse($marcCollection, true, $prefix);
97+
9698
return $this->collection;
9799
}
98100
}

src/Record.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ public function __construct(\File_MARC_Record $record, Factory $factory = null)
1616
public static function fromFile($filename)
1717
{
1818
$collection = Collection::fromFile($filename);
19+
1920
return $collection->records->toArray()[0];
2021
}
2122

2223
public static function fromString($data)
2324
{
2425
$collection = Collection::fromString($data);
26+
2527
return $collection->records->toArray()[0];
2628
}
2729

@@ -58,7 +60,7 @@ public function getType()
5860
case 'y': // Serial item holdings
5961
return 'Holdings';
6062
default:
61-
throw new \ErrorException("Unknown record type.");
63+
throw new \ErrorException('Unknown record type.');
6264
}
6365
}
6466

@@ -73,10 +75,11 @@ public function getIsbns()
7375
foreach ($this->record->getFields('020') as $field) {
7476
$fields[] = $this->makeField('Isbn', $field);
7577
}
78+
7679
return $fields;
7780
}
7881

79-
public function getSubjects($vocabulary=null, $type=null)
82+
public function getSubjects($vocabulary = null, $type = null)
8083
{
8184
$fields = array();
8285
$saf = array(
@@ -103,16 +106,19 @@ public function getSubjects($vocabulary=null, $type=null)
103106
$fields[] = $f;
104107
}
105108
}
109+
106110
return array_filter($fields, function ($s) use ($vocabulary, $type) {
107111
$a = is_null($vocabulary) || $vocabulary == $s->vocabulary;
108112
$b = is_null($type) || $type == $s->type;
113+
109114
return $a && $b;
110115
});
111116
}
112117

113118
public function getTitle()
114119
{
115120
$field = $this->record->getField('245');
121+
116122
return $field ? $this->makeField('Title', $field) : null;
117123
}
118124

@@ -128,6 +134,7 @@ protected function makeField($model, \File_MARC_Field $field)
128134
public function get($spec)
129135
{
130136
$reference = new \File_MARC_Reference($spec, $this->record);
137+
131138
return $reference ?: array();
132139
}
133140

src/Records.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function toArray()
2222
$records[] = $this->current();
2323
$this->next();
2424
}
25+
2526
return $records;
2627
}
2728

@@ -44,7 +45,7 @@ public function key()
4445

4546
public function next()
4647
{
47-
$this->position++;
48+
++$this->position;
4849
if ($this->useCache) {
4950
$rec = isset($this->records[$this->position]) ? $this->records[$this->position] : false;
5051
} else {

tests/RecordTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use Scriptotek\Marc\Record;
4-
use Scriptotek\Marc\Collection;
54

65
class RecordTest extends \PHPUnit_Framework_TestCase
76
{

0 commit comments

Comments
 (0)