From e330d49170d68bc3cb03a6105600b63db3e7f6c5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Jul 2021 16:38:11 +0200 Subject: [PATCH 1/8] Add GH Actions CI and linting --- .github/workflows/continuous-integration.yml | 80 ++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/continuous-integration.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 00000000..70c284ec --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,80 @@ +name: "Continuous Integration" + +on: + - push + - pull_request + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: "1" + +jobs: + tests: + name: "CI" + + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + + strategy: + matrix: + php-version: + - "5.3" + - "5.4" + - "5.5" + - "5.6" + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" +# - "8.0" + dependencies: [highest] + experimental: [false] + include: + - php-version: "5.3" + dependencies: highest + experimental: false + - php-version: "5.3" + dependencies: lowest + experimental: false +# - php-version: "8.0" +# dependencies: highest +# experimental: false +# - php-version: "8.1" +# dependencies: lowest-ignore +# experimental: true +# - php-version: "8.1" +# dependencies: highest-ignore +# experimental: true + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "intl, zip" + ini-values: "memory_limit=-1, phar.readonly=0, error_reporting=E_ALL, display_errors=On" + php-version: "${{ matrix.php-version }}" + tools: composer + + - name: "Handle lowest dependencies update" + if: "contains(matrix.dependencies, 'lowest')" + run: "echo \"COMPOSER_UPDATE_FLAGS=$COMPOSER_UPDATE_FLAGS --prefer-lowest\" >> $GITHUB_ENV" + + - name: "Handle ignore-platform-reqs dependencies update" + if: "contains(matrix.dependencies, 'ignore')" + run: "echo \"COMPOSER_FLAGS=$COMPOSER_FLAGS --ignore-platform-req=php\" >> $GITHUB_ENV" + + - name: "Update dependencies" + run: "composer update ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}" + + - name: "Validate composer.json" + run: "composer validate" + + - name: "Run tests" + run: "composer test" + + From 3d7aece766ee4af20912919bf5ddeab3df6e5180 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Jul 2021 16:38:35 +0200 Subject: [PATCH 2/8] Remove Travis CI config --- .travis.yml | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ca5eced3..00000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ -language: php - -cache: - directories: - - $HOME/.composer/cache - - $HOME/.phpcsfixer - -matrix: - fast_finish: true - include: - - php: 5.3 - dist: precise - - php: 5.4 - dist: trusty - - php: 5.5 - dist: trusty - - php: 5.6 - - php: 7.0 - env: WITH_COVERAGE=true - - php: 7.0 - env: WITH_PHPCSFIXER=true - - php: 7.1 - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: nightly - - php: hhvm-3.18 - dist: trusty - allow_failures: - - php: nightly - - php: hhvm-3.18 - -before_install: - - if [[ "$WITH_COVERAGE" != "true" && "$TRAVIS_PHP_VERSION" != "hhvm-3.18" && "$TRAVIS_PHP_VERSION" != "nightly" && "$TRAVIS_PHP_VERSION" != "7.1" ]]; then phpenv config-rm xdebug.ini; fi - - if [[ "$TRAVIS_PHP_VERSION" = "hhvm-3.18" || "$TRAVIS_PHP_VERSION" = "nightly" ]]; then sed -i '/^.*friendsofphp\/php-cs-fixer.*$/d' composer.json; fi - -install: - - if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]]; then travis_retry composer install; fi - - if [[ "$TRAVIS_PHP_VERSION" = "nightly" ]]; then travis_retry composer install --ignore-platform-reqs; fi - -script: - - if [[ "$WITH_COVERAGE" == "true" ]]; then ./vendor/bin/phpunit --coverage-text; else composer test; fi - - if [[ "$WITH_PHPCSFIXER" == "true" ]]; then mkdir -p $HOME/.phpcsfixer && vendor/bin/php-cs-fixer fix --cache-file "$HOME/.phpcsfixer/.php_cs.cache" --dry-run --diff --verbose; fi From 759978324383ab01b93e27a4e412d1206b991633 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Jul 2021 17:10:57 +0200 Subject: [PATCH 3/8] Add code coverage --- .github/workflows/code-cov.yml | 35 ++++++++++++++++++++ .github/workflows/continuous-integration.yml | 1 - 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/code-cov.yml diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml new file mode 100644 index 00000000..a8e2f18c --- /dev/null +++ b/.github/workflows/code-cov.yml @@ -0,0 +1,35 @@ +name: "Code Coverage" + +on: + - push + - pull_request + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + +jobs: + tests: + name: "Code Coverage" + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + extensions: "intl, zip" + ini-values: "memory_limit=-1, phar.readonly=0, error_reporting=E_ALL, display_errors=On" + php-version: "7.4" + tools: composer + coverage: xdebug2 + + - name: "Update dependencies" + run: "composer update ${{ env.COMPOSER_FLAGS }}" + + - name: "Run coverage" + run: "composer coverage" + + diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 70c284ec..f11ebd4e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -6,7 +6,6 @@ on: env: COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" - SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: "1" jobs: tests: From f7cf6ccbf2b7aa3dac51c2fc437a4bf848338949 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Jul 2021 17:12:22 +0200 Subject: [PATCH 4/8] Add php-cs-fixer check --- .github/workflows/code-cov.yml | 2 -- .github/workflows/style-check.yml | 33 +++++++++++++++++++++++++++++++ .php_cs.dist | 3 ++- composer.json | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/style-check.yml diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index a8e2f18c..868f8888 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -31,5 +31,3 @@ jobs: - name: "Run coverage" run: "composer coverage" - - diff --git a/.github/workflows/style-check.yml b/.github/workflows/style-check.yml new file mode 100644 index 00000000..bc0b190f --- /dev/null +++ b/.github/workflows/style-check.yml @@ -0,0 +1,33 @@ +name: "Style Check" + +on: + - push + - pull_request + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + +jobs: + tests: + name: "Style Check" + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "intl, zip" + ini-values: "memory_limit=-1, phar.readonly=0, error_reporting=E_ALL, display_errors=On" + php-version: "7.4" + tools: composer + + - name: "Update dependencies" + run: "composer update ${{ env.COMPOSER_FLAGS }}" + + - name: "Run style-check" + run: "composer style-check" diff --git a/.php_cs.dist b/.php_cs.dist index a9e7e4ed..35bc3c11 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -23,7 +23,8 @@ $config 'pre_increment' => false, 'increment_style' => false, 'simplified_null_return' => false, - 'trailing_comma_in_multiline_array' => false, + 'single_line_throw' => false, + 'trailing_comma_in_multiline' => false, 'yoda_style' => false, 'phpdoc_types_order' => array('null_adjustment' => 'none', 'sort_algorithm' => 'none'), 'no_superfluous_phpdoc_tags' => false, diff --git a/composer.json b/composer.json index a9184092..2433e385 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "icecave/parity": "1.0.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", + "friendsofphp/php-cs-fixer": "~2.2.20 || ^2.15.1", "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": "^4.8.35" }, From ec07e3ce5b23b3dc8490520e7b8af7063248a327 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Jul 2021 17:20:28 +0200 Subject: [PATCH 5/8] Add basic phpstan level 1 config/ci --- .github/workflows/phpstan.yml | 34 +++++++++++++++++++ phpstan-baseline.neon | 12 +++++++ phpstan.neon | 9 +++++ src/JsonSchema/Constraints/Constraint.php | 2 ++ src/JsonSchema/Constraints/Factory.php | 7 ++-- src/JsonSchema/Constraints/TypeConstraint.php | 13 +++---- 6 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/phpstan.yml create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 00000000..ebb9f1bb --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,34 @@ +name: "PHPStan" + +on: + - push + - pull_request + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + +jobs: + tests: + name: "PHPStan" + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "intl, zip" + ini-values: "memory_limit=-1" + php-version: "7.4" + + - name: "Update dependencies" + run: "composer update ${{ env.COMPOSER_FLAGS }}" + + - name: Run PHPStan + run: | + composer require --dev phpstan/phpstan:^0.12.93 marc-mabe/php-enum-phpstan ${{ env.COMPOSER_FLAGS }} + vendor/bin/phpstan analyse diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 00000000..fe2e7304 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,12 @@ +parameters: + ignoreErrors: + - + message: "#^PHPDoc tag @throws with type JsonSchema\\\\Exception\\\\ExceptionInterface is not subtype of Throwable$#" + count: 1 + path: src/JsonSchema/Constraints/ConstraintInterface.php + + - + message: "#^Access to an undefined property object\\:\\:\\$properties\\.$#" + count: 3 + path: src/JsonSchema/SchemaStorage.php + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..a2e28fe7 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + level: 2 + paths: + - ./src/ + ignoreErrors: [] + +includes: + - phpstan-baseline.neon + - vendor/marc-mabe/php-enum-phpstan/extension.neon diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index 53589977..d088fd49 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -87,6 +87,7 @@ protected function checkArray(&$value, $schema = null, JsonPointer $path = null, protected function checkObject(&$value, $schema = null, JsonPointer $path = null, $properties = null, $additionalProperties = null, $patternProperties = null, $appliedDefaults = array()) { + /** @var ObjectConstraint $validator */ $validator = $this->factory->createInstanceFor('object'); $validator->check($value, $schema, $path, $properties, $additionalProperties, $patternProperties, $appliedDefaults); @@ -119,6 +120,7 @@ protected function checkType(&$value, $schema = null, JsonPointer $path = null, */ protected function checkUndefined(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false) { + /** @var UndefinedConstraint $validator */ $validator = $this->factory->createInstanceFor('undefined'); $validator->check($value, $this->factory->getSchemaStorage()->resolveRefSchema($schema), $path, $i, $fromDefault); diff --git a/src/JsonSchema/Constraints/Factory.php b/src/JsonSchema/Constraints/Factory.php index 9c0f4f21..0895b265 100644 --- a/src/JsonSchema/Constraints/Factory.php +++ b/src/JsonSchema/Constraints/Factory.php @@ -185,6 +185,7 @@ public function setConstraintClass($name, $class) * @throws InvalidArgumentException if is not possible create the constraint instance * * @return ConstraintInterface|ObjectConstraint + * @phpstan-return ConstraintInterface&BaseConstraint */ public function createInstanceFor($constraintName) { @@ -202,7 +203,8 @@ public function createInstanceFor($constraintName) /** * Get the error context * - * @return string + * @return int + * @phpstan-return Validator::ERROR_DOCUMENT_VALIDATION|Validator::ERROR_SCHEMA_VALIDATION */ public function getErrorContext() { @@ -212,7 +214,8 @@ public function getErrorContext() /** * Set the error context * - * @param string $validationContext + * @param int $errorContext + * @phpstan-param Validator::ERROR_DOCUMENT_VALIDATION|Validator::ERROR_SCHEMA_VALIDATION $errorContext */ public function setErrorContext($errorContext) { diff --git a/src/JsonSchema/Constraints/TypeConstraint.php b/src/JsonSchema/Constraints/TypeConstraint.php index ff4eba71..b57c6f5e 100644 --- a/src/JsonSchema/Constraints/TypeConstraint.php +++ b/src/JsonSchema/Constraints/TypeConstraint.php @@ -81,11 +81,12 @@ public function check(&$value = null, $schema = null, JsonPointer $path = null, * of $isValid to true, if at least one $type mateches the type of $value or the value * passed as $isValid is already true. * - * @param mixed $value Value to validate - * @param array $type TypeConstraints to check against - * @param array $validTypesWording An array of wordings of the valid types of the array $type - * @param bool $isValid The current validation value - * @param $path + * @param mixed $value Value to validate + * @param array $type TypeConstraints to check against + * @param array $validTypesWording An array of wordings of the valid types of the array $type + * @param bool $isValid The current validation value + * @param ?JsonPointer $path + * @param bool $coerce */ protected function validateTypesArray(&$value, array $type, &$validTypesWording, &$isValid, $path, $coerce = false) { @@ -239,7 +240,7 @@ protected function validateType(&$value, $type, $coerce = false) /** * Converts a value to boolean. For example, "true" becomes true. * - * @param $value The value to convert to boolean + * @param mixed $value The value to convert to boolean * * @return bool|mixed */ From f8f4bfddb5e2a416a9a625a33862be158e5b7442 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 22 Jul 2021 08:54:36 +0200 Subject: [PATCH 6/8] Fix php cs fixer deprecation warnings --- .php_cs.dist => .php-cs-fixer.dist.php | 1 - 1 file changed, 1 deletion(-) rename .php_cs.dist => .php-cs-fixer.dist.php (96%) diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 96% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 35bc3c11..979388db 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -20,7 +20,6 @@ 'phpdoc_no_package' => false, 'phpdoc_order' => true, 'phpdoc_summary' => false, - 'pre_increment' => false, 'increment_style' => false, 'simplified_null_return' => false, 'single_line_throw' => false, From cb830840e86d9daf063e14fee1e63799dab8f3f6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 22 Jul 2021 08:57:13 +0200 Subject: [PATCH 7/8] Fix README build status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26060a57..a883b19c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JSON Schema for PHP -[![Build Status](https://travis-ci.org/justinrainbow/json-schema.svg?branch=master)](https://travis-ci.org/justinrainbow/json-schema) +[![Build Status](https://github.com/justinrainbow/json-schema/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/justinrainbow/json-schema/actions) [![Latest Stable Version](https://poser.pugx.org/justinrainbow/json-schema/v/stable.png)](https://packagist.org/packages/justinrainbow/json-schema) [![Total Downloads](https://poser.pugx.org/justinrainbow/json-schema/downloads.png)](https://packagist.org/packages/justinrainbow/json-schema) From d11928e6aa4278fcfdef87812ddd177af93b1a96 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 28 Jul 2021 10:44:17 +0200 Subject: [PATCH 8/8] Pin php-cs-fixer to 2.19 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2433e385..f1b69142 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "icecave/parity": "1.0.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20 || ^2.15.1", + "friendsofphp/php-cs-fixer": "~2.2.20 || ~2.19.0", "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": "^4.8.35" },