diff --git a/.gitattributes b/.gitattributes index b74e648..1d21574 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,7 @@ .github export-ignore .gitattributes export-ignore .gitignore export-ignore -CONDUCT.md export-ignore -CONTRIBUTING.md export-ignore -ISSUE_TEMPLATE.md export-ignore +tests export-ignore LICENSE.md export-ignore -PULL_REQUEST_TEMPLATE.md export-ignore README.md export-ignore -tests export-ignore -benchmarks export-ignore phpunit.xml export-ignore -phpbench.json export-ignore diff --git a/CONDUCT.md b/.github/CONDUCT.md similarity index 100% rename from CONDUCT.md rename to .github/CONDUCT.md diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md diff --git a/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md similarity index 78% rename from ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE.md index 06d4118..fcff0de 100644 --- a/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -18,7 +18,7 @@ Not obligatory, but suggest an idea for implementing addition or change. Include as many relevant details about the environment you experienced the bug in and how to reproduce it. -* Version used (e.g. PHP 7.0, PHP 7.1.2): -* Operating system and version (e.g. Ubuntu 16.04, Windows 7): +* Version used (e.g. PHP 8.0, PHP 7.1.2): +* Operating system and version (e.g. Ubuntu 20.04, Windows 10): * Link to your project or gist, code sample -* Other important for issuer reproduce information +* Other important for issue reproduce information diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7d4e435 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: "Continuous Integration" + +on: [ push ] + +jobs: + phpunit: + strategy: + matrix: + os: [ ubuntu-latest ] + php: [ '7.3', '7.4', '8.0' ] + name: PHPUnit (PHP ${{ matrix.php }}) tests on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + env: + PHP_EXTENSIONS: mbstring, dom, intl, json, libxml, xml, xmlwriter, sockets + PHP_INI_VALUES: assert.exception=1, zend.assertions=1 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP with extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.PHP_EXTENSIONS }} + ini-values: ${{ env.PHP_INI_VALUES }} + tools: composer:v2 + + - name: Install dependencies + run: composer update -ov + + - name: Run tests with phpunit + run: php ./vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 4cf5b36..3973e9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ -.phpunit.result.cache composer.lock /.vscode /.idea +/tmp /vendor -/build diff --git a/README.md b/README.md index 58ccf30..50acbbf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Latest Version on Packagist][ico-version]][link-packagist] [![Software License][ico-license]](LICENSE.md) -[![Coverage Status][ico-scrutinizer]][link-scrutinizer] [![Total Downloads][ico-downloads]][link-downloads] PHPinnacle Buffer is a simple tool for operating binary data in PHP. Mostly it simply wraps PHP pack/unpack functions. @@ -68,7 +67,7 @@ And results with enabled [extension][link-extension]: ## Contributing -Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CONDUCT](.github/CONDUCT.md) for details. ## Security @@ -85,12 +84,10 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio [ico-version]: https://img.shields.io/packagist/v/phpinnacle/buffer.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square -[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/phpinnacle/buffer.svg?style=flat-square [ico-downloads]: https://img.shields.io/packagist/dt/phpinnacle/buffer.svg?style=flat-square [link-extension]: https://github.com/phpinnacle/ext-buffer [link-packagist]: https://packagist.org/packages/phpinnacle/buffer -[link-scrutinizer]: https://scrutinizer-ci.com/g/phpinnacle/buffer/code-structure [link-downloads]: https://packagist.org/packages/phpinnacle/buffer [link-author]: https://github.com/phpinnacle [link-contributors]: https://github.com/phpinnacle/buffer/graphs/contributors diff --git a/benchmarks/AppendBench.php b/benchmarks/AppendBench.php deleted file mode 100644 index a641597..0000000 --- a/benchmarks/AppendBench.php +++ /dev/null @@ -1,81 +0,0 @@ -buffer = new ByteBuffer; - $this->string = \str_repeat('str', 1000); - } - - /** - * @Revs(1000) - * @Iterations(100) - * - * @return void - */ - public function benchAppendIntegers(): void - { - $this->buffer - ->appendInt8(1) - ->appendInt16(1) - ->appendInt32(1) - ->appendInt64(1) - ->appendUint8(1) - ->appendUint16(1) - ->appendUint32(1) - ->appendUint64(1) - ; - } - - /** - * @Revs(1000) - * @Iterations(100) - * - * @return void - */ - public function benchAppendFloats(): void - { - $this->buffer - ->appendFloat(1.0) - ->appendFloat(-1.0) - ->appendFloat(\M_PI) - ->appendDouble(1.0) - ->appendDouble(-1.0) - ->appendDouble(\M_PI) - ; - } - - /** - * @Revs(1000) - * @Iterations(100) - * - * @return void - */ - public function benchAppendString(): void - { - $this->buffer - ->append('some string') - ->append("other string") - ->append($this->string) - ; - } -} diff --git a/benchmarks/ConsumeBench.php b/benchmarks/ConsumeBench.php deleted file mode 100644 index cc502c5..0000000 --- a/benchmarks/ConsumeBench.php +++ /dev/null @@ -1,74 +0,0 @@ -buffer = new ByteBuffer; - - for ($i = 0; $i < $this->revs; ++$i) { - $this->buffer - ->appendInt8(1) - ->appendInt16(1) - ->appendInt32(1) - ->appendInt64(1) - ->appendUint8(1) - ->appendUint16(1) - ->appendUint32(1) - ->appendUint64(1) - ->appendFloat(1.1) - ->appendFloat(-1.1) - ->appendFloat(\M_PI) - ->appendDouble(1.1) - ->appendDouble(-1.1) - ->appendDouble(\M_PI) - ->append('some string') - ->append("other string") - ; - } - } - - /** - * @Revs(1000) - * @Iterations(100) - * - * @return void - */ - public function benchConsume(): void - { - $this->buffer->consumeInt8(); - $this->buffer->consumeInt16(); - $this->buffer->consumeInt32(); - $this->buffer->consumeInt64(); - $this->buffer->consumeUint8(); - $this->buffer->consumeUint16(); - $this->buffer->consumeUint32(); - $this->buffer->consumeUint64(); - $this->buffer->consumeFloat(); - $this->buffer->consumeFloat(); - $this->buffer->consumeFloat(); - $this->buffer->consumeDouble(); - $this->buffer->consumeDouble(); - $this->buffer->consumeDouble(); - $this->buffer->consume(11); - $this->buffer->consume(12); - } -} diff --git a/benchmarks/ReadBench.php b/benchmarks/ReadBench.php deleted file mode 100644 index ffea0a8..0000000 --- a/benchmarks/ReadBench.php +++ /dev/null @@ -1,66 +0,0 @@ -buffer = new ByteBuffer; - $this->buffer - ->appendInt8(1) - ->appendInt16(1) - ->appendInt32(1) - ->appendInt64(1) - ->appendUint8(1) - ->appendUint16(1) - ->appendUint32(1) - ->appendUint64(1) - ->appendFloat(1.1) - ->appendFloat(-1.1) - ->appendFloat(\M_PI) - ->appendDouble(1.1) - ->appendDouble(-1.1) - ->appendDouble(\M_PI) - ->append('some string') - ->append("other string") - ; - } - - /** - * @Revs(1000) - * @Iterations(100) - * - * @return void - */ - public function benchRead(): void - { - $this->buffer->readInt8(); - $this->buffer->readInt16(1); - $this->buffer->readInt32(3); - $this->buffer->readInt64(7); - $this->buffer->readUint8(15); - $this->buffer->readUint16(16); - $this->buffer->readUint32(18); - $this->buffer->readUint64(22); - $this->buffer->readFloat(30); - $this->buffer->readFloat(34); - $this->buffer->readFloat(38); - $this->buffer->readDouble(42); - $this->buffer->readDouble(50); - $this->buffer->readDouble(58); - $this->buffer->read(11, 66); - $this->buffer->read(12, 77); - } -} diff --git a/composer.json b/composer.json index d22f41e..74b886c 100644 --- a/composer.json +++ b/composer.json @@ -16,10 +16,9 @@ } ], "require": { - "php": "^7.1 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpbench/phpbench": "^0.17", "phpunit/phpunit": "^9.0" }, "suggest": { @@ -27,17 +26,16 @@ }, "autoload": { "psr-4": { - "PHPinnacle\\Buffer\\": "src" + "PHPinnacle\\Buffer\\": "src/" } }, "autoload-dev": { "psr-4": { - "PHPinnacle\\Buffer\\Tests\\": "tests" + "PHPinnacle\\Buffer\\Tests\\": "tests/" } }, "scripts": { - "test": "phpunit", - "bench": "phpbench run benchmarks --report=aggregate" + "test": "phpunit" }, "extra": { "branch-alias": { diff --git a/phpbench.json b/phpbench.json deleted file mode 100644 index 466f9e5..0000000 --- a/phpbench.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "bootstrap": "vendor/autoload.php" -} \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 09bb3af..bd96845 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,29 +1,23 @@ - - - - tests - - - - - src/ - - - - - - - - - + + + + ./tests/ + + + + + + + + ./src + + + ./tests + + + + + + diff --git a/src/BufferOverflow.php b/src/BufferOverflow.php index aa55b58..7eb5dd3 100644 --- a/src/BufferOverflow.php +++ b/src/BufferOverflow.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Buffer; diff --git a/src/ByteBuffer.php b/src/ByteBuffer.php index 19c2089..16924f6 100644 --- a/src/ByteBuffer.php +++ b/src/ByteBuffer.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Buffer; @@ -138,17 +138,18 @@ public function discard(int $n): self /** * @param int $n + * @param int $offset * * @return static * @throws BufferOverflow */ - public function slice(int $n): self + public function slice(int $n, int $offset = 0): self { if ($this->size < $n) { throw new BufferOverflow; } - return $this->size === $n ? new static($this->data) : new static(\substr($this->data, 0, $n)); + return $this->size === $n ? new static($this->data) : new static(\substr($this->data, $offset, $n)); } /** @@ -178,6 +179,14 @@ public function shift(int $n): self return new static($buffer); } + /** + * @return string + */ + public function bytes(): string + { + return $this->data; + } + /** * @return string */ diff --git a/tests/ByteBufferTest.php b/tests/ByteBufferTest.php index 2c5004e..0c852ed 100644 --- a/tests/ByteBufferTest.php +++ b/tests/ByteBufferTest.php @@ -8,6 +8,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace PHPinnacle\Buffer\Tests; use PHPinnacle\Buffer\ByteBuffer as Buffer;