Skip to content

Commit d196bd9

Browse files
authored
Merge pull request #8 from petrknap/updated-shorts
Updated `Shorts`
2 parents 5a9b322 + 4d66416 commit d196bd9

File tree

5 files changed

+35
-53
lines changed

5 files changed

+35
-53
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"name": "petrknap/binary",
4141
"require": {
4242
"php": ">=8.1",
43-
"petrknap/shorts": "^1.5"
43+
"petrknap/shorts": "^2.0"
4444
},
4545
"require-dev": {
4646
"ext-mbstring": "*",

src/Coder/Checksum.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44

55
namespace PetrKnap\Binary\Coder;
66

7-
use PetrKnap\Binary\HasRequirementsTrait;
87
use PetrKnap\Shorts\HasRequirements;
98

109
/**
1110
* @see hash()
1211
*
1312
* @link https://en.wikipedia.org/wiki/Checksum
1413
*/
15-
final class Checksum extends Coder implements HasRequirements
14+
final class Checksum extends Coder
1615
{
17-
use HasRequirementsTrait;
16+
use HasRequirements;
1817

1918
public const ALGORITHM = 'crc32';
20-
private const REQUIRED_FUNCTIONS = [
21-
'mb_strlen',
22-
'mb_strcut',
23-
];
2419

2520
private string $algorithm;
2621

2722
public function __construct()
2823
{
29-
self::checkRequirements();
24+
self::checkRequirements(
25+
functions: [
26+
'mb_strlen',
27+
'mb_strcut',
28+
],
29+
);
3030
}
3131

3232
public function encode(string $decoded, ?string $algorithm = null): string

src/Coder/Zlib.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,32 @@
44

55
namespace PetrKnap\Binary\Coder;
66

7-
use PetrKnap\Binary\HasRequirementsTrait;
87
use PetrKnap\Shorts\HasRequirements;
98

109
/**
1110
* @see zlib_encode()
1211
* @see zlib_decode()
1312
*/
14-
final class Zlib extends Coder implements HasRequirements
13+
final class Zlib extends Coder
1514
{
16-
use HasRequirementsTrait;
15+
use HasRequirements;
1716

1817
public const ENCODING = ZLIB_ENCODING_RAW;
1918
public const LEVEL = -1;
2019
public const MAX_LENGTH = 0;
21-
private const REQUIRED_FUNCTIONS = [
22-
'zlib_encode',
23-
'zlib_decode',
24-
];
20+
21+
public function __construct()
22+
{
23+
self::checkRequirements(
24+
functions: [
25+
'zlib_encode',
26+
'zlib_decode',
27+
],
28+
constants: [
29+
'ZLIB_ENCODING_RAW',
30+
],
31+
);
32+
}
2533

2634
private int $encoding;
2735
private int $level;

src/HasRequirementsTrait.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Serializer/Igbinary.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44

55
namespace PetrKnap\Binary\Serializer;
66

7-
use PetrKnap\Binary\HasRequirementsTrait;
87
use PetrKnap\Shorts\HasRequirements;
98

109
/**
1110
* @see igbinary_serialize()
1211
* @see igbinary_unserialize()
1312
*/
14-
final class Igbinary extends Serializer implements HasRequirements
13+
final class Igbinary extends Serializer
1514
{
16-
use HasRequirementsTrait;
15+
use HasRequirements;
1716

18-
private const REQUIRED_FUNCTIONS = [
19-
'igbinary_serialize',
20-
'igbinary_unserialize',
21-
];
17+
public function __construct()
18+
{
19+
self::checkRequirements(
20+
functions: [
21+
'igbinary_serialize',
22+
'igbinary_unserialize',
23+
],
24+
);
25+
}
2226

2327
protected function doSerialize(mixed $serializable): string
2428
{

0 commit comments

Comments
 (0)