Conditions | 5 |
Paths | 4 |
Total Lines | 15 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
53 | 15 | public function remove(string $data): string |
|
54 | { |
||
55 | 15 | $len = strlen($data); |
|
56 | 15 | if (!$len) { |
|
57 | 1 | throw new \UnexpectedValueException('No padding.'); |
|
58 | } |
||
59 | 14 | $n = ord($data[$len - 1]); |
|
60 | 14 | if ($len < $n || $n > $this->_blocksize) { |
|
61 | 3 | throw new \UnexpectedValueException('Invalid padding length.'); |
|
62 | } |
||
63 | 11 | $ps = substr($data, -$n); |
|
64 | 11 | if ($ps !== str_repeat(chr($n), $n)) { |
|
65 | 1 | throw new \UnexpectedValueException('Invalid padding string.'); |
|
66 | } |
||
67 | 10 | return substr($data, 0, -$n); |
|
68 | } |
||
70 |