Skip to content

Commit ca77390

Browse files
committed
refactor: removed requirement of petrknap/shorts
1 parent 48072b3 commit ca77390

13 files changed

Lines changed: 55 additions & 15 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PetrKnap\Binary\Coder\Exception;
66

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

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

src/Coder/Exception/CoderCouldNotEncodeData.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\Exception;
66

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

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

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace PetrKnap\Binary\Exception;
66

7-
use PetrKnap\Shorts\Exception\CouldNotProcessData;
8-
97
/**
108
* @extends CouldNotProcessData<string>
119
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
* @template TData of mixed
14+
*/
15+
abstract class CouldNotProcessData extends RuntimeException
16+
{
17+
/**
18+
* @param non-empty-string $method
19+
* @param TData $data may contain binary data
20+
*/
21+
public function __construct(
22+
string $method,
23+
public readonly mixed $data,
24+
public readonly Throwable|null $reason = null,
25+
) {
26+
parent::__construct(
27+
message: sprintf(
28+
'%s could not process %s',
29+
$method,
30+
is_string($data) ? sprintf('string(%d)', strlen($data)) : (is_object($data) ? get_class($data) : gettype($data)),
31+
),
32+
previous: $reason
33+
);
34+
}
35+
}

src/Serializer/Exception/SerializerCouldNotSerializeData.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace PetrKnap\Binary\Serializer\Exception;
66

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

99
/**
10-
* @extends CouldNotProcessData<mixed>
10+
* @template TData of mixed
11+
*
12+
* @extends CouldNotProcessData<TData>
1113
*/
1214
final class SerializerCouldNotSerializeData extends CouldNotProcessData implements SerializerException
1315
{

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)