Skip to content

Commit 52df0e5

Browse files
committed
wip
1 parent 5aa356f commit 52df0e5

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ See the examples below for more information, or check out [`Encoder`](./src/Enco
77
namespace PetrKnap\Binary;
88

99
$data = base64_decode('hmlpFnFwbchsoQARSibVpfbWVfuwAHLbGxjFl9eC8fiGaWkWcXBtyGyhABFKJtWl9tZV+7AActsbGMWX14Lx+A==');
10-
$encoded = Binary::encode($data)->checksum()->zlib()->base64(urlSafe: true)->toBinary();
11-
$decoded = Binary::decode($encoded)->base64()->zlib()->checksum()->toBinary();
10+
$encoded = Binary::encode($data)->checksum()->zlib()->base64(urlSafe: true)->data;
11+
$decoded = Binary::decode($encoded)->base64()->zlib()->checksum()->data;
1212

1313
printf('Data was coded into `%s` %s.', $encoded, $decoded === $data ? 'successfully' : 'unsuccessfully');
1414
```

src/Coder.php

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

55
namespace PetrKnap\Binary;
66

7-
abstract class Coder implements BinariableInterface
7+
abstract class Coder
88
{
9-
use BinariableTrait;
10-
119
final public function __construct(
12-
protected readonly string $data = '',
10+
public readonly string $data = '',
1311
) {
1412
}
1513

@@ -18,7 +16,10 @@ final public function withData(string $data): static
1816
return new static($data);
1917
}
2018

21-
final public function toBinary(): string
19+
/**
20+
* @deprecated use readonly property $data
21+
*/
22+
final public function getData(): string
2223
{
2324
return $this->data;
2425
}

tests/DecoderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ public function testDecodesBase64(): void
1212
{
1313
self::assertSame(
1414
Coder\Base64Test::getDecodedData(),
15-
(new Decoder(Coder\Base64Test::getEncodedData()))->base64()->toBinary(),
15+
(new Decoder(Coder\Base64Test::getEncodedData()))->base64()->data,
1616
);
1717
}
1818

1919
public function testDecodesChecksum(): void
2020
{
2121
self::assertSame(
2222
Coder\ChecksumTest::getDecodedData(),
23-
(new Decoder(Coder\ChecksumTest::getEncodedData()))->checksum()->toBinary(),
23+
(new Decoder(Coder\ChecksumTest::getEncodedData()))->checksum()->data,
2424
);
2525
}
2626

2727
public function testDecodesHex(): void
2828
{
2929
self::assertSame(
3030
Coder\HexTest::getDecodedData(),
31-
(new Decoder(Coder\HexTest::getEncodedData()))->hex()->toBinary(),
31+
(new Decoder(Coder\HexTest::getEncodedData()))->hex()->data,
3232
);
3333
}
3434

3535
public function testDecodesZlib(): void
3636
{
3737
self::assertSame(
3838
Coder\ZlibTest::getDecodedData(),
39-
(new Decoder(Coder\ZlibTest::getEncodedData()))->zlib()->toBinary(),
39+
(new Decoder(Coder\ZlibTest::getEncodedData()))->zlib()->data,
4040
);
4141
}
4242
}

tests/EncoderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ public function testEncodesBase64(): void
1212
{
1313
self::assertSame(
1414
Coder\Base64Test::getEncodedData(),
15-
(new Encoder(Coder\Base64Test::getDecodedData()))->base64()->toBinary(),
15+
(new Encoder(Coder\Base64Test::getDecodedData()))->base64()->data,
1616
);
1717
}
1818

1919
public function testEncodesChecksum(): void
2020
{
2121
self::assertSame(
2222
Coder\ChecksumTest::getEncodedData(),
23-
(new Encoder(Coder\ChecksumTest::getDecodedData()))->checksum()->toBinary(),
23+
(new Encoder(Coder\ChecksumTest::getDecodedData()))->checksum()->data,
2424
);
2525
}
2626

2727
public function testEncodesHex(): void
2828
{
2929
self::assertSame(
3030
Coder\HexTest::getEncodedData(),
31-
(new Encoder(Coder\HexTest::getDecodedData()))->hex()->toBinary(),
31+
(new Encoder(Coder\HexTest::getDecodedData()))->hex()->data,
3232
);
3333
}
3434

3535
public function testEncodesZlib(): void
3636
{
3737
self::assertSame(
3838
Coder\ZlibTest::getEncodedData(),
39-
(new Encoder(Coder\ZlibTest::getDecodedData()))->zlib()->toBinary(),
39+
(new Encoder(Coder\ZlibTest::getDecodedData()))->zlib()->data,
4040
);
4141
}
4242
}

0 commit comments

Comments
 (0)