diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..5e730ae --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,68 @@ +name: Static analysis +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + +jobs: + phpstan: + name: PHPStan code analysis [PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest ] + php: [8.2, 8.3, 8.4] + #dependency-version: [ prefer-lowest, prefer-stable ] + dependency-version: [ prefer-stable ] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl + coverage: none + + - name: Copy .env + run: php -r "copy('.env.actions', '.env');" + - name: Run composer install + run: composer install --prefer-dist + - name: Run larastan (PHPStan) - Static code analysis + run: ./vendor/bin/phpstan analyse --memory-limit=2G + + phpcs: + name: PHPcs PSR check [PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest ] + php: [8.2, 8.3, 8.4] + #dependency-version: [ prefer-lowest, prefer-stable ] + dependency-version: [ prefer-stable ] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl + coverage: none + + - name: Copy .env + run: php -r "copy('.env.actions', '.env');" + - name: Run composer install + run: composer install --prefer-dist + + - name: Run phpcs - PSR2 check +# run: ./vendor/bin/phpcs --standard=phpcs.xml src # Run with warnings > This will still trigger failure + run: ./vendor/bin/phpcs --standard=phpcs.xml src -n # To run errors only +# run: ./vendor/bin/phpcs --standard=PSR2 src diff --git a/.gitignore b/.gitignore index 14f1b51..c30d214 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ nb-configuration.xml # OS .DS_Store + +composer.lock +composer.phar diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..d444647 --- /dev/null +++ b/changelog.md @@ -0,0 +1,4 @@ +# v2.1.0 +- Changed PHP requirements to `^8.2` +- Minimum version for "guzzlehttp/guzzle" is now `^7.9` +- Minimum version for "psr/log" is now `^3.0` diff --git a/composer.json b/composer.json index c9ea373..d850c2f 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,33 @@ { - "name": "ecodenl/lvbag-php-wrapper", - "description": "PHP Wrapper for the LVBAG API ", - "type": "library", - "license": "OSL-3.0", - "authors": [ - { - "name": "Bodhi Looij", - "email": "b.looij@wedesignit.nl", - "role": "Developer" + "name": "ecodenl/lvbag-php-wrapper", + "description": "PHP Wrapper for the LVBAG API ", + "type": "library", + "license": "OSL-3.0", + "authors": [ + { + "name": "Bodhi Looij", + "email": "b.looij@wedesignit.nl", + "role": "Developer" + }, + { + "name": "Yannick Schrijvers", + "email": "y.schrijvers@wedesignit.nl", + "role": "Developer" + } + ], + "require": { + "php": "^8.2", + "guzzlehttp/guzzle": "^7.9", + "psr/log": "^3.0", + "ext-json": "*" + }, + "autoload": { + "psr-4": { + "Ecodenl\\LvbagPhpWrapper\\": "src" + } + }, + "require-dev": { + "phpstan/phpstan": "^2.0", + "squizlabs/php_codesniffer": "^3.11" } - ], - "require": { - "php": "^7.4.0|^8.0", - "guzzlehttp/guzzle": "^6.3.1|^7.4.5", - "psr/log": "^1.1.4|^3.0" - }, - "autoload": { - "psr-4": { - "Ecodenl\\LvbagPhpWrapper\\": "src" - } - } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..d6a12f5 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,107 @@ + + + The coding standard for our project. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + vendor/* + storage/* + bootstrap/* + public/* + */migrations/* + */seeds/* + *.blade.php + *.js + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..ae349ea --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,22 @@ +#includes: + # Example: + #- vendor/nesbot/carbon/extension.neon + +parameters: + + paths: + - src/ + + # Level 10 is the highest level, see https://phpstan.org/user-guide/rule-levels + level: 5 + + #excludePaths: + # Example: + #- ./src/Traits/FluentCaller.php + + ignoreErrors: + # These errors are ignored because we are 100% certain it's not actually an issue + - '#Unsafe usage of new static(.*)#' + + #tips: + #treatPhpDocTypesAsCertain: false diff --git a/readme.md b/readme.md index fdf4d2d..993e284 100644 --- a/readme.md +++ b/readme.md @@ -4,9 +4,12 @@ A simple PHP wrapper for IMBAG API (LVBAG) ## Version Information -| Package version | API Version | Status | PHP Version | -|:----------------|:------------|:------------------------|:------------| -| 2.x.x | 2.x.x | Active support :rocket: | ^7.4.0 \| ^8.0 | +To keep versioning simple, the package version is aligned with the LV BAG API version. + +| Package version | API Version | Status | PHP Version | +|:----------------|:------------|:------------------------|:---------------| +| 2.1.x | 2.x.x | Active support :rocket: | ^8.2 | +| 2.0.x | 2.x.x | No active support :x: | ^7.4.0 \| ^8.0 | ## Installing diff --git a/src/Client.php b/src/Client.php index c249648..6497623 100644 --- a/src/Client.php +++ b/src/Client.php @@ -27,8 +27,9 @@ public function __construct( string $secret, string $crs, bool $useProductionEndpoint = false, - LoggerInterface $logger = null - ) { + ?LoggerInterface $logger = null + ) + { $this->logger = $logger; if ($useProductionEndpoint) { @@ -85,5 +86,4 @@ public function get(string $uri, array $options = []): array { return $this->request('GET', $uri, $options); } - } diff --git a/src/Resources/AdresUitgebreid.php b/src/Resources/AdresUitgebreid.php index 4882a31..a259e4c 100644 --- a/src/Resources/AdresUitgebreid.php +++ b/src/Resources/AdresUitgebreid.php @@ -6,10 +6,6 @@ class AdresUitgebreid extends Resource { /** * Returns specific data about the given identification. - * - * @param string $nummeraanduidingIdentificatie - * - * @return array */ public function show(string $nummeraanduidingIdentificatie): array { @@ -18,15 +14,11 @@ public function show(string $nummeraanduidingIdentificatie): array /** * Returns a list of address(es) from given attributes. - * - * @param array $attributes - * - * @return array */ - public function list(array $attributes): ?array + public function list(array $attributes): array { $response = $this->client->get($this->uri, static::buildQuery($this->paginate() + $attributes)); - return $response['_embedded']['adressen'] ?? null; + return $response['_embedded']['adressen'] ?? []; } } diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index 007ca20..2a6c0a5 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -7,7 +7,6 @@ abstract class Resource { - /** @var Client $client */ protected Client $client; protected int $page = 1; diff --git a/src/Resources/Woonplaats.php b/src/Resources/Woonplaats.php index 0dabf0b..6cfc8ac 100644 --- a/src/Resources/Woonplaats.php +++ b/src/Resources/Woonplaats.php @@ -6,11 +6,6 @@ class Woonplaats extends Resource { /** * Returns specific data about the given identification. - * - * @param string $identificatie - * @param array $attributes - * - * @return array */ public function show(string $identificatie, array $attributes = []): array { @@ -19,15 +14,11 @@ public function show(string $identificatie, array $attributes = []): array /** * Returns a list of cities from given attributes. - * - * @param array $attributes - * - * @return array */ - public function list(array $attributes): ?array + public function list(array $attributes): array { $response = $this->client->get($this->uri, static::buildQuery($this->paginate() + $attributes)); - return $response['_embedded']['woonplaatsen'] ?? null; + return $response['_embedded']['woonplaatsen'] ?? []; } } diff --git a/src/Traits/FluentCaller.php b/src/Traits/FluentCaller.php index cb842aa..026a416 100644 --- a/src/Traits/FluentCaller.php +++ b/src/Traits/FluentCaller.php @@ -2,7 +2,8 @@ namespace Ecodenl\LvbagPhpWrapper\Traits; -trait FluentCaller { +trait FluentCaller +{ public static function init() { diff --git a/upgrading.md b/upgrading.md new file mode 100644 index 0000000..570bf48 --- /dev/null +++ b/upgrading.md @@ -0,0 +1,7 @@ +# From v2.0 to v2.1 +To keep the LV BAG wrapper up to date, we have to drop support for deprecated PHP versions and packages. +Changes are limited, and most likely you won't have to do anything. + +## PHP +The minimum PHP version is now 8.2. Ensure your PHP version is up to date. +