Skip to content

Commit 4194fe5

Browse files
committed
Merge pull request #6 from MARCspec/analysis-XV3xOq
Applied fixes from StyleCI
2 parents bd16e74 + 40e13b3 commit 4194fe5

22 files changed

+1404
-1590
lines changed

ComparisonString.php

+35-37
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* from within a MARC record.
55
*
66
* @author Carsten Klee <[email protected]>
7-
* @package CK\MARCspec
87
* @copyright For the full copyright and license information, please view the LICENSE
98
* file that was distributed with this source code.
109
*/
@@ -13,98 +12,97 @@
1312
use CK\MARCspec\Exception\InvalidMARCspecException;
1413

1514
/**
16-
* A MARCspec comparison string class
17-
*/
15+
* A MARCspec comparison string class.
16+
*/
1817
class ComparisonString implements ComparisonStringInterface, \JsonSerializable, \ArrayAccess
1918
{
20-
2119
/**
2220
* @var string The escaped comparison string
2321
*/
2422
private $raw;
2523

2624
/**
27-
*
28-
* {@inheritdoc}
29-
*
30-
* @throws \InvalidArgumentException if argument is not a string or
31-
* comparison string is not properly escaped
32-
*/
25+
* {@inheritdoc}
26+
*
27+
* @throws \InvalidArgumentException if argument is not a string or
28+
* comparison string is not properly escaped
29+
*/
3330
public function __construct($raw)
3431
{
35-
3632
if (!is_string($raw)) {
3733
throw new \InvalidArgumentException('Argument must be of type string. Got '
3834
.gettype($raw).'.');
3935
}
40-
36+
4137
if (false !== strpos($raw, ' ')) {
4238
throw new InvalidMARCspecException(
4339
InvalidMARCspecException::CS.
4440
InvalidMARCspecException::SPACE,
4541
$raw
4642
);
4743
}
48-
49-
/** char of list ${}!=~?|\s must be escaped if not at index 0*/
44+
45+
/* char of list ${}!=~?|\s must be escaped if not at index 0*/
5046
if (!preg_match('/^(.(?:[^${}!=~?| ]|(?<=\\\\)[${}!=~?|])*)$/', $raw)) {
5147
throw new InvalidMARCspecException(
5248
InvalidMARCspecException::CS.
5349
InvalidMARCspecException::ESCAPE,
5450
$raw
5551
);
5652
}
57-
53+
5854
$this->raw = $raw;
5955
}
60-
56+
6157
/**
62-
* {@inheritdoc}
63-
*/
58+
* {@inheritdoc}
59+
*/
6460
public function getComparable()
6561
{
6662
$comparable = str_replace('\s', ' ', $this->raw);
63+
6764
return stripcslashes($comparable);
6865
}
69-
66+
7067
/**
71-
* {@inheritdoc}
72-
*/
68+
* {@inheritdoc}
69+
*/
7370
public function getRaw()
7471
{
7572
return $this->raw;
7673
}
77-
74+
7875
/**
79-
* {@inheritdoc}
80-
*/
76+
* {@inheritdoc}
77+
*/
8178
public static function escape($arg)
8279
{
83-
$specialChars = ['{','}','!','=','~','?'];
80+
$specialChars = ['{', '}', '!', '=', '~', '?'];
8481
for ($i = 0; $i < count($specialChars); $i++) {
8582
$arg = str_replace($specialChars[$i], '\\'.$specialChars[$i], $arg);
8683
}
84+
8785
return $arg = str_replace(' ', '\s', $arg);
8886
}
89-
87+
9088
/**
9189
* {@inheritdoc}
9290
*/
9391
public function __toString()
9492
{
95-
return "\\".$this->raw;
93+
return '\\'.$this->raw;
9694
}
97-
95+
9896
/**
9997
* {@inheritdoc}
10098
*/
10199
public function jsonSerialize()
102100
{
103-
return ['comparisonString'=>$this->raw];
101+
return ['comparisonString' => $this->raw];
104102
}
105-
103+
106104
/**
107-
* Access object like an associative array
105+
* Access object like an associative array.
108106
*
109107
* @api
110108
*
@@ -121,9 +119,9 @@ public function offsetExists($offset)
121119
return false;
122120
}
123121
}
124-
122+
125123
/**
126-
* Access object like an associative array
124+
* Access object like an associative array.
127125
*
128126
* @api
129127
*
@@ -142,9 +140,9 @@ public function offsetGet($offset)
142140
throw new \UnexpectedValueException("Offset $offset does not exist.");
143141
}
144142
}
145-
143+
146144
/**
147-
* Access object like an associative array
145+
* Access object like an associative array.
148146
*
149147
* @api
150148
*
@@ -154,9 +152,9 @@ public function offsetSet($offset, $value)
154152
{
155153
throw new \UnexpectedValueException("Offset $offset cannot be set.");
156154
}
157-
155+
158156
/**
159-
* Access object like an associative array
157+
* Access object like an associative array.
160158
*
161159
* @param string $offset
162160
*/

ComparisonStringInterface.php

+39-42
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,65 @@
44
* from within a MARC record.
55
*
66
* @author Carsten Klee <[email protected]>
7-
* @package CK\MARCspec
87
* @copyright For the full copyright and license information, please view the LICENSE
98
* file that was distributed with this source code.
109
*/
11-
1210
namespace CK\MARCspec;
1311

1412
/**
15-
* MARCspec comparison string interface
13+
* MARCspec comparison string interface.
1614
*/
1715
interface ComparisonStringInterface
1816
{
19-
2017
/**
21-
* Constructor for ComparisonString
22-
*
23-
* @api
24-
*
25-
* @param string $raw The escaped comparison string
26-
*/
18+
* Constructor for ComparisonString.
19+
*
20+
* @api
21+
*
22+
* @param string $raw The escaped comparison string
23+
*/
2724
public function __construct($raw);
28-
25+
2926
/**
30-
* Get unescaped comparable string
31-
*
32-
* @api
33-
*
34-
* @return string The comparable string
35-
*/
27+
* Get unescaped comparable string.
28+
*
29+
* @api
30+
*
31+
* @return string The comparable string
32+
*/
3633
public function getComparable();
37-
34+
3835
/**
39-
* Get raw escaped string
40-
*
41-
* @api
42-
*
43-
* @return string The escaped string
44-
*/
36+
* Get raw escaped string.
37+
*
38+
* @api
39+
*
40+
* @return string The escaped string
41+
*/
4542
public function getRaw();
46-
43+
4744
/**
48-
* Escape a comparison string
49-
*
50-
* @api
51-
*
52-
* @param string $arg The unescaped string
53-
*
54-
* @return string The escaped string
55-
*/
45+
* Escape a comparison string.
46+
*
47+
* @api
48+
*
49+
* @param string $arg The unescaped string
50+
*
51+
* @return string The escaped string
52+
*/
5653
public static function escape($arg);
57-
54+
5855
/**
59-
* encodes ComparisonString as string
60-
*
61-
* @api
62-
*
63-
* @return string
64-
*/
56+
* encodes ComparisonString as string.
57+
*
58+
* @api
59+
*
60+
* @return string
61+
*/
6562
public function __toString();
66-
63+
6764
/**
68-
* Serialize ComparisonString as JSON
65+
* Serialize ComparisonString as JSON.
6966
*
7067
* @api
7168
*

0 commit comments

Comments
 (0)