Skip to content

Commit 4178379

Browse files
committed
refactor: Add constants for the three record types
1 parent ea12ddc commit 4178379

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/Marc21.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Scriptotek\Marc;
4+
5+
class Marc21
6+
{
7+
// MARC21 record types
8+
const AUTHORITY = 'Authority';
9+
const BIBLIOGRAPHIC = 'Bibliographic';
10+
const HOLDINGS = 'Holdings';
11+
}

src/Record.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public static function fromString($data)
6060
* Determine if record is a bibliographic, authority or holdings record
6161
*************************************************************************/
6262

63+
/**
64+
* Get the record type based on the value of LDR/6. Returns any of
65+
* the Marc21::BIBLIOGRAPHIC, Marc21::AUTHORITY or Marc21::HOLDINGS
66+
* constants.
67+
*
68+
* @return string
69+
* @throws ErrorException
70+
*/
6371
public function getType()
6472
{
6573
$leader = $this->record->getLeader();
@@ -80,14 +88,14 @@ public function getType()
8088
case 'p': // Mixed materials
8189
case 'r': // Three-dimensional artifact or naturally occurring object
8290
case 't': // Manuscript language material
83-
return 'Bibliographic';
91+
return Marc21::BIBLIOGRAPHIC;
8492
case 'z':
85-
return 'Authority';
93+
return Marc21::AUTHORITY;
8694
case 'u': // Unknown
8795
case 'v': // Multipart item holdings
8896
case 'x': // Single-part item holdings
8997
case 'y': // Serial item holdings
90-
return 'Holdings';
98+
return Marc21::HOLDINGS;
9199
default:
92100
throw new \ErrorException('Unknown record type.');
93101
}

tests/RecordTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Scriptotek\Marc\Marc21;
34
use Scriptotek\Marc\Record;
45

56
class RecordTest extends \PHPUnit_Framework_TestCase
@@ -69,7 +70,7 @@ public function testRecordTypeBiblio()
6970
</record>';
7071

7172
$record = Record::fromString($source);
72-
$this->assertEquals('Bibliographic', $record->type);
73+
$this->assertEquals(Marc21::BIBLIOGRAPHIC, $record->type);
7374
}
7475

7576
public function testRecordTypeAuthority()
@@ -80,6 +81,6 @@ public function testRecordTypeAuthority()
8081
</record>';
8182

8283
$record = Record::fromString($source);
83-
$this->assertEquals('Authority', $record->type);
84+
$this->assertEquals(Marc21::AUTHORITY, $record->type);
8485
}
8586
}

0 commit comments

Comments
 (0)