Skip to content
Merged
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: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests export-ignore
Dockerfile export-ignore
bin export-ignore
.github export-ignore
.molireali export-ignore
56 changes: 56 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
- [ ] This pull request does not contain any breaking change.
- [ ] I asked [the AI](https://copilot.microsoft.com/) to briefly summarize, use and improve the feature(s), and I'm okay with the output:
<!-- ⇅ remove it if it doesn't make sense ⇅ -->
<!-- ↓ here belongs the AI inputs (>>) and outputs (>) ↓ -->
>> Could you briefly summarize the following code for me?
>> ```python
>> class Tiger:
>> def __init__(self, name):
>> self.name = name
>>
>> def roar(self):
>> print(f"{self.name} lets out a powerful roar!")
>> ```
>
> This code defines a Python class named `Tiger` with a constructor that initializes the tiger's name, and a `roar` method that prints a message including the tiger's name. Simple and elegant, just like a tiger! 🐅
>
>> Could you show me how to use it?
>
> Sure, here's how to create and use a `Tiger` object with the class you have:
> ```python
> # Create an instance of Tiger
> my_tiger = Tiger("Gopal")
>
> # Call the roar method
> my_tiger.roar()
> ```
>
> When you run this code, it will output:
> ```
> Gopal lets out a powerful roar!
> ```
>
> That's how you bring your Tiger to life! 🎉
>
>> Is there any way to do it better?
>
> Absolutely. You could add error handling, additional methods, or even inheritance. Here's an enhanced version:
> ```python
> class Tiger:
> def __init__(self, name):
> self.name = name
>
> def roar(self):
> print(f"{self.name} lets out a powerful roar!")
>
> def introduce(self):
> print(f"Meet {self.name}, the majestic tiger!")
>
> # Usage
> my_tiger = Tiger("Gopal")
> my_tiger.introduce() # Output: Meet Gopal, the majestic tiger!
> my_tiger.roar() # Output: Gopal lets out a powerful roar!
> ```
>
> Now your tiger can introduce itself, too. 🐯📢
<!-- ↑ this is an example, replace it ↑ -->
1 change: 1 addition & 0 deletions .molireali
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ composer PetrKnap\\Binary
dockerfile php 8.1-cli
docker-scripts petrknap/php-binary
donation
github-templates
github-workflow docker "composer ci-script"
github-workflow linter-docker
github-workflow linter-php 8.1
Expand Down
7 changes: 1 addition & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git \
unzip \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "copy('https://composer.github.io/installer.sig', 'composer-setup.php.sig');" \
&& php -r "if (trim(hash_file('SHA384', 'composer-setup.php')) === trim(file_get_contents('composer-setup.php.sig'))) { echo 'Installer verified' . PHP_EOL; exit(0); } else { echo 'Installer corrupt' . PHP_EOL; unlink('composer-setup.php'); unlink('composer-setup.php.sig'); exit(-1); }" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php'); unlink('composer-setup.php.sig');" \
&& mv composer.phar /usr/local/bin/composer \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
;
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
# endregion

# region included composer-library
Expand Down
21 changes: 14 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,28 @@
"ext-mbstring": "*",
"ext-zlib": "*",
"nunomaduro/phpinsights": "^2.11",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.7"
},
"scripts": {
"test": "phpunit --colors=always --testdox tests",
"validate": [
"composer outdated \"petrknap/*\" --major-only --strict --ansi --no-interaction",
"ci-script": [
"@check-implementation",
"@check-requirements",
"@test-implementation"
],
"check-implementation": [
"phpcs --colors --standard=PSR12 --exclude=Generic.Files.LineLength src tests",
"phpstan analyse --level max src",
"phpstan analyse --level 5 tests",
"phpstan analyse --level max src --ansi --no-interaction",
"phpstan analyse --level 5 tests --ansi --no-interaction",
"phpinsights analyse src --ansi --no-interaction"
],
"ci-script": [
"@validate",
"check-requirements": [
"composer update \"petrknap/*\"",
"composer outdated \"petrknap/*\" --major-only --strict --ansi --no-interaction"
],
"test-implementation": [
"@test"
]
},
Expand Down
4 changes: 3 additions & 1 deletion src/BinariableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

namespace PetrKnap\Binary;

/**
* @psalm-require-implements BinariableInterface
*/
trait BinariableTrait
{
/**
* Unfortunately PHP uses string for binary data, so the magic clashes.
*/
public function __toString(): string
{
/** @var BinariableInterface $this */
$binary = $this->toBinary();
trigger_error(
'Returned binary string',
Expand Down
8 changes: 4 additions & 4 deletions src/Coder/Zlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ final class Zlib extends Coder
public const LEVEL = -1;
public const MAX_LENGTH = 0;

private int $encoding;
private int $level;
private int $maxLength;

public function __construct()
{
self::checkRequirements(
Expand All @@ -31,10 +35,6 @@ functions: [
);
}

private int $encoding;
private int $level;
private int $maxLength;

public function encode(string $decoded, ?int $encoding = null, ?int $level = null): string
{
$this->encoding = $encoding ?? self::ENCODING;
Expand Down
2 changes: 2 additions & 0 deletions src/Serializer/SelfSerializerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* If your {@see self::__construct()} argument is an instance of {@see SelfSerializerInterface} then
* accept it as a union type `YourClass|string` and call {@see SelfSerializerInterface::fromBinary()} if it is a string.
*
* @psalm-require-implements SelfSerializerInterface
*/
trait SelfSerializerTrait
{
Expand Down
Loading