Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@
"name": "petrknap/binary",
"require": {
"php": ">=8.1",
"petrknap/optional": "^3.1",
"petrknap/shorts": "^3.0"
"petrknap/has-requirements": "^1.0",
"petrknap/optional": "^3.1"
},
"require-dev": {
"ext-igbinary": "*",
"ext-mbstring": "*",
"ext-zlib": "*",
"nunomaduro/phpinsights": "^2.11",
"petrknap/shorts": "^3.0",
"petrknap/xz-utils": "*",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^10.5",
Expand Down
2 changes: 1 addition & 1 deletion src/Byter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PetrKnap\Binary;

use PetrKnap\Shorts\HasRequirements;
use PetrKnap\HasRequirements\HasRequirements;
use RuntimeException;

final class Byter
Expand Down
2 changes: 1 addition & 1 deletion src/Coder/Exception/CoderCouldNotDecodeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PetrKnap\Binary\Coder\Exception;

use PetrKnap\Shorts\Exception\CouldNotProcessData;
use PetrKnap\Binary\Exception\CouldNotProcessData;

/**
* @extends CouldNotProcessData<string>
Expand Down
2 changes: 1 addition & 1 deletion src/Coder/Exception/CoderCouldNotEncodeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PetrKnap\Binary\Coder\Exception;

use PetrKnap\Shorts\Exception\CouldNotProcessData;
use PetrKnap\Binary\Exception\CouldNotProcessData;

/**
* @extends CouldNotProcessData<string>
Expand Down
2 changes: 1 addition & 1 deletion src/Coder/Xz.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PetrKnap\Binary\Coder;

use PetrKnap\Shorts\HasRequirements;
use PetrKnap\HasRequirements\HasRequirements;
use PetrKnap\XzUtils\Xz as Inner;

final class Xz extends Coder
Expand Down
2 changes: 1 addition & 1 deletion src/Coder/Zlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace PetrKnap\Binary\Coder;

use PetrKnap\HasRequirements\HasRequirements;
use PetrKnap\Optional\OptionalString;
use PetrKnap\Shorts\HasRequirements;

/**
* @see zlib_encode()
Expand Down
2 changes: 0 additions & 2 deletions src/Exception/ByterCouldNotBiteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace PetrKnap\Binary\Exception;

use PetrKnap\Shorts\Exception\CouldNotProcessData;

/**
* @extends CouldNotProcessData<string>
*/
Expand Down
35 changes: 35 additions & 0 deletions src/Exception/CouldNotProcessData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace PetrKnap\Binary\Exception;

use RuntimeException;
use Throwable;

/**
* @note this is public helper, this class is not supposed to implement {@see Exception}

Check notice on line 11 in src/Exception/CouldNotProcessData.php

View workflow job for this annotation

GitHub Actions / run

* [Line length] Line exceeds 80 characters; contains 88 characters
*
* @template TData of mixed

Check notice on line 13 in src/Exception/CouldNotProcessData.php

View workflow job for this annotation

GitHub Actions / run

* [Disallow mixed type hint] Usage of "mixed" type hint is disallowed.
*/
abstract class CouldNotProcessData extends RuntimeException
{
/**
* @param non-empty-string $method
* @param TData $data may contain binary data
*/
public function __construct(
string $method,
public readonly mixed $data,
public readonly Throwable|null $reason = null,
) {
parent::__construct(
message: sprintf(
'%s could not process %s',
$method,
is_string($data) ? sprintf('string(%d)', strlen($data)) : (is_object($data) ? get_class($data) : gettype($data)),

Check notice on line 30 in src/Exception/CouldNotProcessData.php

View workflow job for this annotation

GitHub Actions / run

* [Modern class name reference] Class name referenced via call of function get_class(). * [Line length] Line exceeds maximum limit of 100 characters; contains 129 characters
),
previous: $reason
);
}
}
6 changes: 4 additions & 2 deletions src/Serializer/Exception/SerializerCouldNotSerializeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace PetrKnap\Binary\Serializer\Exception;

use PetrKnap\Shorts\Exception\CouldNotProcessData;
use PetrKnap\Binary\Exception\CouldNotProcessData;

/**
* @extends CouldNotProcessData<mixed>
* @template TData of mixed
*
* @extends CouldNotProcessData<TData>
*/
final class SerializerCouldNotSerializeData extends CouldNotProcessData implements SerializerException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PetrKnap\Binary\Serializer\Exception;

use PetrKnap\Shorts\Exception\CouldNotProcessData;
use PetrKnap\Binary\Exception\CouldNotProcessData;

/**
* @extends CouldNotProcessData<string>
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/Igbinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace PetrKnap\Binary\Serializer;

use PetrKnap\HasRequirements\HasRequirements;
use PetrKnap\Optional\Optional;
use PetrKnap\Optional\OptionalString;
use PetrKnap\Shorts\HasRequirements;

/**
* @see igbinary_serialize()
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/OneWaySelfSerializerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface OneWaySelfSerializerInterface
/**
* @return string binary representation of this instance
*
* @throws Exception\SerializerCouldNotSerializeData
* @throws Exception\SerializerCouldNotSerializeData<$this>
*/
public function toBinary(): string;
}
6 changes: 5 additions & 1 deletion src/Serializer/SerializerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
interface SerializerInterface
{
/**
* @throws Exception\SerializerCouldNotSerializeData
* @template TSerializable of mixed
*
* @param TSerializable $serializable
*
* @throws Exception\SerializerCouldNotSerializeData<TSerializable>
*/
public function serialize(mixed $serializable): string;

Expand Down
Loading