1
1
<?php
2
2
/**
3
- * MARCspec is the specification of a reference, encoded as string, to a set of data
3
+ * MARCspec is the specification of a reference, encoded as string, to a set of data
4
4
* from within a MARC record.
5
- *
5
+ *
6
6
* @author Carsten Klee <[email protected] >
7
7
* @package CK\MARCspec
8
- * @copyright For the full copyright and license information, please view the LICENSE
8
+ * @copyright For the full copyright and license information, please view the LICENSE
9
9
* file that was distributed with this source code.
10
10
*/
11
11
namespace CK \MARCspec ;
12
12
13
13
use CK \MARCspec \Exception \InvalidMARCspecException ;
14
+
14
15
/**
15
16
* A MARCspec comparison string class
16
17
*/
@@ -19,28 +20,25 @@ class ComparisonString implements ComparisonStringInterface, \JsonSerializable,
19
20
20
21
/**
21
22
* @var string The escaped comparison string
22
- */
23
+ */
23
24
private $ raw ;
24
25
25
26
/**
26
27
*
27
28
* {@inheritdoc}
28
- *
29
- * @throws \InvalidArgumentException if argument is not a string or
29
+ *
30
+ * @throws \InvalidArgumentException if argument is not a string or
30
31
* comparison string is not properly escaped
31
32
*/
32
33
public function __construct ($ raw )
33
34
{
34
35
35
- if (!is_string ($ raw ))
36
- {
36
+ if (!is_string ($ raw )) {
37
37
throw new \InvalidArgumentException ('Argument must be of type string. Got '
38
- .gettype ($ raw ).'. '
39
- );
38
+ .gettype ($ raw ).'. ' );
40
39
}
41
40
42
- if (false !== strpos ($ raw ,' ' ))
43
- {
41
+ if (false !== strpos ($ raw , ' ' )) {
44
42
throw new InvalidMARCspecException (
45
43
InvalidMARCspecException::CS .
46
44
InvalidMARCspecException::SPACE ,
@@ -49,8 +47,7 @@ public function __construct($raw)
49
47
}
50
48
51
49
/** char of list ${}!=~?|\s must be escaped if not at index 0*/
52
- if (!preg_match ('/^(.(?:[^${}!=~?| ]|(?<= \\\\)[${}!=~?|])*)$/ ' ,$ raw ))
53
- {
50
+ if (!preg_match ('/^(.(?:[^${}!=~?| ]|(?<= \\\\)[${}!=~?|])*)$/ ' , $ raw )) {
54
51
throw new InvalidMARCspecException (
55
52
InvalidMARCspecException::CS .
56
53
InvalidMARCspecException::ESCAPE ,
@@ -66,7 +63,7 @@ public function __construct($raw)
66
63
*/
67
64
public function getComparable ()
68
65
{
69
- $ comparable = str_replace ('\s ' ,' ' ,$ this ->raw );
66
+ $ comparable = str_replace ('\s ' , ' ' , $ this ->raw );
70
67
return stripcslashes ($ comparable );
71
68
}
72
69
@@ -84,11 +81,10 @@ public function getRaw()
84
81
public static function escape ($ arg )
85
82
{
86
83
$ specialChars = ['{ ' ,'} ' ,'! ' ,'= ' ,'~ ' ,'? ' ];
87
- for ($ i = 0 ; $ i < count ($ specialChars );$ i ++)
88
- {
89
- $ arg = str_replace ($ specialChars [$ i ],'\\' .$ specialChars [$ i ],$ arg );
84
+ for ($ i = 0 ; $ i < count ($ specialChars ); $ i ++) {
85
+ $ arg = str_replace ($ specialChars [$ i ], '\\' .$ specialChars [$ i ], $ arg );
90
86
}
91
- return $ arg = str_replace (' ' ,'\s ' ,$ arg );
87
+ return $ arg = str_replace (' ' , '\s ' , $ arg );
92
88
}
93
89
94
90
/**
@@ -109,58 +105,61 @@ public function jsonSerialize()
109
105
110
106
/**
111
107
* Access object like an associative array
112
- *
108
+ *
113
109
* @api
114
- *
110
+ *
115
111
* @param string $offset Key raw|comparable
116
- */
112
+ */
117
113
public function offsetExists ($ offset )
118
114
{
119
- switch ($ offset )
120
- {
121
- case 'raw ' :
122
- case ' comparable ' : return true ;
115
+ switch ($ offset ) {
116
+ case ' raw ' :
117
+ case 'comparable ' :
118
+ return true ;
123
119
break ;
124
- default : return false ;
120
+ default :
121
+ return false ;
125
122
}
126
123
}
127
124
128
125
/**
129
126
* Access object like an associative array
130
- *
127
+ *
131
128
* @api
132
- *
129
+ *
133
130
* @param string $offset Key operator|leftSubTerm|rightSubTerm
134
- */
131
+ */
135
132
public function offsetGet ($ offset )
136
133
{
137
- switch ($ offset )
138
- {
139
- case ' raw ' : return $ this ->getRaw ();
134
+ switch ($ offset ) {
135
+ case ' raw ' :
136
+ return $ this ->getRaw ();
140
137
break ;
141
- case 'comparable ' : return $ this ->getComparable ();
138
+ case 'comparable ' :
139
+ return $ this ->getComparable ();
142
140
break ;
143
- default : throw new \UnexpectedValueException ("Offset $ offset does not exist. " );
141
+ default :
142
+ throw new \UnexpectedValueException ("Offset $ offset does not exist. " );
144
143
}
145
144
}
146
145
147
146
/**
148
147
* Access object like an associative array
149
- *
148
+ *
150
149
* @api
151
- *
150
+ *
152
151
* @param string $offset
153
- */
154
- public function offsetSet ($ offset ,$ value )
152
+ */
153
+ public function offsetSet ($ offset , $ value )
155
154
{
156
155
throw new \UnexpectedValueException ("Offset $ offset cannot be set. " );
157
156
}
158
157
159
158
/**
160
159
* Access object like an associative array
161
- *
160
+ *
162
161
* @param string $offset
163
- */
162
+ */
164
163
public function offsetUnset ($ offset )
165
164
{
166
165
throw new \BadMethodCallException ("Offset $ offset can not be unset. " );
0 commit comments