diff --git a/.editorconfig b/.editorconfig index 616af73..19e2b68 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,5 +8,11 @@ insert_final_newline = true indent_style = space indent_size = 4 -[*.yml] +[{*.yaml,*.yml,*.neon,*.json}] indent_size = 2 + +[*.md] +max_line_length = 80 + +[{Dockerfile,Makefile}] +indent_style = tab diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index 69c481f..d253600 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -14,7 +14,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: "7.2" + php-version: "7.1" ini-values: memory_limit=-1 tools: composer:v2, phpcs - name: Run PHPCS diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 2e43418..19ccb03 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -6,11 +6,11 @@ on: jobs: phpstan: - name: PHPStan + name: phpstan runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 with: @@ -18,7 +18,7 @@ jobs: ini-values: memory_limit=-1 tools: composer:v2 - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.composer/cache @@ -28,5 +28,5 @@ jobs: - name: Install dependencies run: composer install --no-interaction --no-progress - - name: Run PHPStan + - name: Analyze run: vendor/bin/phpstan diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1310f0..169f6df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,9 +14,10 @@ jobs: - "7.1" - "7.4" - "8.0" + - "8.4" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 with: @@ -25,7 +26,7 @@ jobs: ini-values: memory_limit=-1 tools: composer:v2 - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.composer/cache diff --git a/Dockerfile b/Dockerfile index 68b7a4c..c043976 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,31 @@ -FROM php:7.1-cli-buster +ARG PHP_TAG=7.1-cli-buster +FROM php:${PHP_TAG} -RUN docker-php-ext-enable opcache && \ - docker-php-source delete +RUN <<-EOF + docker-php-ext-enable opcache + docker-php-source delete +EOF -RUN echo '\ -display_errors=On\n\ -error_reporting=E_ALL\n\ -date.timezone=UTC\n\ -' >> /usr/local/etc/php/conf.d/php.ini +RUN <<-EOF + cat <<-SHELL >> /usr/local/etc/php/conf.d/php.ini + display_errors=On + error_reporting=E_ALL + date.timezone=UTC + SHELL +EOF ENV COMPOSER_ALLOW_SUPERUSER 1 -RUN apt-get update && \ - apt-get install unzip && \ - curl -s https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet && \ - mv composer.phar /usr/local/bin/composer && \ - echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"\n' >> /root/.bashrc +RUN <<-EOF + apt-get update + apt-get install unzip + curl -s https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet + mv composer.phar /usr/local/bin/composer + cat <<-SHELL >> /root/.bashrc + export PATH="$HOME/.composer/vendor/bin:$PATH" + SHELL +EOF RUN composer global require squizlabs/php_codesniffer + +ENV COMPOSER_ROOT_VERSION 2.1.0 diff --git a/Makefile b/Makefile index 4fb070b..0906bc9 100755 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ # customization -PACKAGE_NAME = icanboogie/common PHPUNIT = vendor/bin/phpunit # do not edit the following lines @@ -26,11 +25,19 @@ test-coveralls: test-dependencies @XDEBUG_MODE=coverage $(PHPUNIT) --coverage-clover build/logs/clover.xml .PHONY: test-container -test-container: - @docker-compose run --rm app bash +test-container: test-container-71 + +.PHONY: test-container-71 +test-container-71: + @-docker-compose run --rm app71 bash + @docker-compose down -v + +.PHONY: test-container-84 +test-container-84: + @-docker-compose run --rm app84 bash @docker-compose down -v .PHONY: lint lint: - @phpcs - @vendor/bin/phpstan + @XDEBUG_MODE=none phpcs + @XDEBUG_MODE=none vendor/bin/phpstan diff --git a/README.md b/README.md index f29a85a..62b85d8 100755 --- a/README.md +++ b/README.md @@ -1,17 +1,16 @@ # Common [![Release](https://img.shields.io/packagist/v/icanboogie/common.svg)](https://packagist.org/packages/icanboogie/common) -[![Code Quality](https://img.shields.io/scrutinizer/g/ICanBoogie/Common.svg)](https://scrutinizer-ci.com/g/ICanBoogie/Common) -[![Code Coverage](https://img.shields.io/coveralls/ICanBoogie/Common.svg)](https://coveralls.io/r/ICanBoogie/Common) +[![Code Coverage](https://img.shields.io/coveralls/ICanBoogie/Common/badge.svg?branch=2.1)](https://coveralls.io/r/ICanBoogie/Common?branch=2.1) [![Packagist](https://img.shields.io/packagist/dt/icanboogie/common.svg)](https://packagist.org/packages/icanboogie/common) This package provides basic classes and helpers shared by many [ICanBoogie][] -packages. It provides offset exceptions, property exceptions, some interfaces, and helpers to -transform strings and arrays. +packages. It provides offset exceptions, property exceptions, some interfaces, +and helpers to transform strings and arrays. #### Installation -```bash +```shell composer require icanboogie/common ``` @@ -21,7 +20,7 @@ composer require icanboogie/common ### Offset exceptions -The following exceptions related to array offset are defined by the package: +The package defines the following exceptions related to array offset: * [OffsetError][]: Interface for offset errors. * [OffsetNotDefined][]: Exception thrown when an array offset is not defined. @@ -63,7 +62,7 @@ class A ## Interfaces -The following interfaces are defined by the package: +The package defines the following interfaces: - [ToArray][]: Should be implemented by classes whose instances can be converted into arrays. - [ToArrayRecursive][]: Should be implemented by classes whose instances can be converted into @@ -96,41 +95,34 @@ class A implements ToArrayRecursive The project is continuously tested by [GitHub actions](https://github.com/ICanBoogie/Common/actions). -[![Tests](https://github.com/ICanBoogie/Common/workflows/test/badge.svg?branch=master)](https://github.com/ICanBoogie/master/actions?query=workflow%3Atest) -[![Static Analysis](https://github.com/ICanBoogie/Common/workflows/static-analysis/badge.svg?branch=master)](https://github.com/ICanBoogie/Common/actions?query=workflow%3Astatic-analysis) -[![Code Style](https://github.com/ICanBoogie/Common/workflows/code-style/badge.svg?branch=master)](https://github.com/ICanBoogie/Common/actions?query=workflow%3Acode-style) +[![Tests](https://github.com/ICanBoogie/Common/actions/workflows/test.yml/badge.svg?branch=2.1)](https://github.com/ICanBoogie/Common/actions/workflows/test.yml) +[![Static Analysis](https://github.com/ICanBoogie/Common/actions/workflows/static-analysis.yml/badge.svg?branch=2.1)](https://github.com/ICanBoogie/Common/actions/workflows/static-analysis.yml) +[![Code Style](https://github.com/ICanBoogie/Common/actions/workflows/code-style.yml/badge.svg?branch=2.1)](https://github.com/ICanBoogie/Common/actions/workflows/code-style.yml) ## Code of Conduct -This project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project and its -community, you are expected to uphold this code. +This project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in +this project and its community, you're expected to uphold this code. ## Contributing -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. +See [CONTRIBUTING](CONTRIBUTING.md) for details. -## License - -**icanboogie/common** is released under the [BSD-3-Clause](LICENSE). - - - -[documentation]: https://icanboogie.org/api/common/1.2/ -[OffsetError]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.OffsetError.html -[OffsetNotDefined]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.OffsetNotDefined.html -[OffsetNotReadable]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.OffsetNotReadable.html -[OffsetNotWritable]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.OffsetNotWritable.html -[PropertyError]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.PropertyError.html -[PropertyNotDefined]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.PropertyNotDefined.html -[PropertyNotReadable]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.PropertyNotReadable.html -[PropertyNotWritable]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.PropertyNotWritable.html -[ToArray]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.ToArray.html -[ToArrayRecursive]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.ToArrayRecursive.html -[ToArrayRecursiveTrait]: https://icanboogie.org/api/common/1.2/class-ICanBoogie.ToArrayRecursiveTrait.html +[OffsetError]: lib/OffsetError.php +[OffsetNotDefined]: lib/OffsetNotDefined.php +[OffsetNotReadable]: lib/OffsetNotReadable.php +[OffsetNotWritable]: lib/OffsetNotWritable.php +[PropertyError]: lib/PropertyError.php +[PropertyNotDefined]: lib/PropertyNotDefined.php +[PropertyNotReadable]: lib/PropertyNotReadable.php +[PropertyNotWritable]: lib/PropertyNotWritable.php +[ToArray]: lib/ToArray.php +[ToArrayRecursive]: lib/ToArrayRecursive.php +[ToArrayRecursiveTrait]: lib/ToArrayRecursiveTrait.php [ICanBoogie]: https://icanboogie.org/ diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..af5fc41 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,21 @@ +--- +services: + app71: + build: + context: . + args: + PHP_TAG: 7.1-cli-buster + environment: &env + PHP_IDE_CONFIG: 'serverName=icanboogie-common' + volumes: &vol + - .:/app:delegated + - ~/.composer:/root/.composer:delegated + working_dir: /app + app84: + build: + context: . + args: + PHP_TAG: 8.4.0RC4-cli-bookworm + environment: *env + volumes: *vol + working_dir: /app diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index ee2537e..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -version: "3.2" -services: - app: - build: . - environment: - PHP_IDE_CONFIG: 'serverName=icanboogie-common' - volumes: - - .:/app:delegated - - ~/.composer:/root/.composer:delegated - working_dir: /app diff --git a/lib/helpers.php b/lib/helpers.php index 557ea08..7f4cde4 100755 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -89,7 +89,7 @@ function capitalize(string $str, bool $preserve_str_end = false): string * @param float $position Position at which characters can be removed. * @param bool $shortened `true` if the string was shortened, `false` otherwise. */ -function shorten(string $str, int $length = 32, float $position = .75, bool &$shortened = null): string +function shorten(string $str, int $length = 32, float $position = .75, ?bool &$shortened = null): string { $l = mb_strlen($str); @@ -298,7 +298,7 @@ function format(string $str, array $args = []): string * * @param array $array */ -function stable_sort(array &$array, callable $picker = null): void +function stable_sort(array &$array, ?callable $picker = null): void { static $transform, $restore; diff --git a/tests/SampleToArrayRecursive.php b/tests/SampleToArrayRecursive.php index cbcbe73..f662d0e 100644 --- a/tests/SampleToArrayRecursive.php +++ b/tests/SampleToArrayRecursive.php @@ -11,9 +11,11 @@ namespace Tests\ICanBoogie; +use AllowDynamicProperties; use ICanBoogie\ToArrayRecursive; use ICanBoogie\ToArrayRecursiveTrait; +#[AllowDynamicProperties] class SampleToArrayRecursive implements ToArrayRecursive { use ToArrayRecursiveTrait;