Skip to content

Commit e63fc12

Browse files
committed
refactor: removed requirement of petrknap/shorts
1 parent c3d6857 commit e63fc12

11 files changed

Lines changed: 44 additions & 21 deletions

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@
4444
"name": "petrknap/binary",
4545
"require": {
4646
"php": ">=8.1",
47-
"petrknap/optional": "^3.1",
48-
"petrknap/shorts": "^3.0"
47+
"petrknap/has-requirements": "^1.0",
48+
"petrknap/optional": "^3.1"
4949
},
5050
"require-dev": {
5151
"ext-igbinary": "*",
5252
"ext-mbstring": "*",
5353
"ext-zlib": "*",
5454
"nunomaduro/phpinsights": "^2.11",
55+
"petrknap/shorts": "^3.0",
5556
"petrknap/xz-utils": "*",
5657
"phpstan/phpstan": "^1.12",
5758
"phpunit/phpunit": "^10.5",

src/Byter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PetrKnap\Binary;
66

7-
use PetrKnap\Shorts\HasRequirements;
7+
use PetrKnap\HasRequirements\HasRequirements;
88
use RuntimeException;
99

1010
final class Byter

src/Coder/Exception/CoderCouldNotDecodeData.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
namespace PetrKnap\Binary\Coder\Exception;
66

7-
use PetrKnap\Shorts\Exception\CouldNotProcessData;
7+
use PetrKnap\Binary\Exception\CouldNotProcessData;
88

9-
/**
10-
* @extends CouldNotProcessData<string>
11-
*/
129
final class CoderCouldNotDecodeData extends CouldNotProcessData implements CoderException
1310
{
1411
}

src/Coder/Exception/CoderCouldNotEncodeData.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
namespace PetrKnap\Binary\Coder\Exception;
66

7-
use PetrKnap\Shorts\Exception\CouldNotProcessData;
7+
use PetrKnap\Binary\Exception\CouldNotProcessData;
88

9-
/**
10-
* @extends CouldNotProcessData<string>
11-
*/
129
final class CoderCouldNotEncodeData extends CouldNotProcessData implements CoderException
1310
{
1411
}

src/Coder/Xz.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PetrKnap\Binary\Coder;
66

7-
use PetrKnap\Shorts\HasRequirements;
7+
use PetrKnap\HasRequirements\HasRequirements;
88
use PetrKnap\XzUtils\Xz as Inner;
99

1010
final class Xz extends Coder

src/Coder/Zlib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace PetrKnap\Binary\Coder;
66

7+
use PetrKnap\HasRequirements\HasRequirements;
78
use PetrKnap\Optional\OptionalString;
8-
use PetrKnap\Shorts\HasRequirements;
99

1010
/**
1111
* @see zlib_encode()

src/Exception/ByterCouldNotBiteData.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
namespace PetrKnap\Binary\Exception;
66

7-
use PetrKnap\Shorts\Exception\CouldNotProcessData;
8-
9-
/**
10-
* @extends CouldNotProcessData<string>
11-
*/
127
final class ByterCouldNotBiteData extends CouldNotProcessData implements ByterException
138
{
149
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PetrKnap\Binary\Exception;
6+
7+
use RuntimeException;
8+
use Throwable;
9+
10+
/**
11+
* @note this is public helper, this class is not supposed to implement {@see Exception}
12+
*/
13+
abstract class CouldNotProcessData extends RuntimeException
14+
{
15+
/**
16+
* @param non-empty-string $method
17+
* @param string $data may contain binary data
18+
*/
19+
public function __construct(
20+
string $method,
21+
public readonly string $data,
22+
public readonly Throwable|null $reason = null,
23+
) {
24+
parent::__construct(
25+
message: sprintf(
26+
'%s could not process string(%d)',
27+
$method,
28+
strlen($data),
29+
),
30+
previous: $reason
31+
);
32+
}
33+
}

src/Serializer/Exception/SerializerCouldNotSerializeData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PetrKnap\Binary\Serializer\Exception;
66

7-
use PetrKnap\Shorts\Exception\CouldNotProcessData;
7+
use PetrKnap\Binary\Exception\CouldNotProcessData;
88

99
/**
1010
* @extends CouldNotProcessData<mixed>

src/Serializer/Exception/SerializerCouldNotUnserializeData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PetrKnap\Binary\Serializer\Exception;
66

7-
use PetrKnap\Shorts\Exception\CouldNotProcessData;
7+
use PetrKnap\Binary\Exception\CouldNotProcessData;
88

99
/**
1010
* @extends CouldNotProcessData<string>

0 commit comments

Comments
 (0)