Skip to content

Commit

Permalink
chore: updated shorts
Browse files Browse the repository at this point in the history
  • Loading branch information
petrknap committed Apr 17, 2024
1 parent 5a9b322 commit 4d66416
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 53 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"name": "petrknap/binary",
"require": {
"php": ">=8.1",
"petrknap/shorts": "^1.5"
"petrknap/shorts": "^2.0"
},
"require-dev": {
"ext-mbstring": "*",
Expand Down
16 changes: 8 additions & 8 deletions src/Coder/Checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

namespace PetrKnap\Binary\Coder;

use PetrKnap\Binary\HasRequirementsTrait;
use PetrKnap\Shorts\HasRequirements;

/**
* @see hash()
*
* @link https://en.wikipedia.org/wiki/Checksum
*/
final class Checksum extends Coder implements HasRequirements
final class Checksum extends Coder
{
use HasRequirementsTrait;
use HasRequirements;

public const ALGORITHM = 'crc32';
private const REQUIRED_FUNCTIONS = [
'mb_strlen',
'mb_strcut',
];

private string $algorithm;

public function __construct()
{
self::checkRequirements();
self::checkRequirements(
functions: [
'mb_strlen',
'mb_strcut',
],
);
}

public function encode(string $decoded, ?string $algorithm = null): string
Expand Down
22 changes: 15 additions & 7 deletions src/Coder/Zlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@

namespace PetrKnap\Binary\Coder;

use PetrKnap\Binary\HasRequirementsTrait;
use PetrKnap\Shorts\HasRequirements;

/**
* @see zlib_encode()
* @see zlib_decode()
*/
final class Zlib extends Coder implements HasRequirements
final class Zlib extends Coder
{
use HasRequirementsTrait;
use HasRequirements;

public const ENCODING = ZLIB_ENCODING_RAW;
public const LEVEL = -1;
public const MAX_LENGTH = 0;
private const REQUIRED_FUNCTIONS = [
'zlib_encode',
'zlib_decode',
];

public function __construct()
{
self::checkRequirements(
functions: [
'zlib_encode',
'zlib_decode',
],
constants: [
'ZLIB_ENCODING_RAW',
],
);
}

private int $encoding;
private int $level;
Expand Down
30 changes: 0 additions & 30 deletions src/HasRequirementsTrait.php

This file was deleted.

18 changes: 11 additions & 7 deletions src/Serializer/Igbinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

namespace PetrKnap\Binary\Serializer;

use PetrKnap\Binary\HasRequirementsTrait;
use PetrKnap\Shorts\HasRequirements;

/**
* @see igbinary_serialize()
* @see igbinary_unserialize()
*/
final class Igbinary extends Serializer implements HasRequirements
final class Igbinary extends Serializer
{
use HasRequirementsTrait;
use HasRequirements;

private const REQUIRED_FUNCTIONS = [
'igbinary_serialize',
'igbinary_unserialize',
];
public function __construct()
{
self::checkRequirements(
functions: [
'igbinary_serialize',
'igbinary_unserialize',
],
);
}

protected function doSerialize(mixed $serializable): string
{
Expand Down

0 comments on commit 4d66416

Please sign in to comment.