diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..d0d22db --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,46 @@ +name: PHP tests +on: [push, pull_request] +jobs: + phpstan: + permissions: + actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows + contents: read # for actions/checkout to fetch code + name: PHP Static Analysis + runs-on: ubuntu-latest + strategy: + matrix: + php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ] + fail-fast: false + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.0 + with: + access_token: ${{ github.token }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv, simplexml + + - uses: actions/checkout@v2 + + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache Composer Directory + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Composer Install + run: | + composer install --ansi --prefer-dist --no-interaction --no-progress + rm composer.lock + composer config platform.php ${{ matrix.php }} + + - name: Run phpstan + run: ./vendor/bin/phpstan analyse diff --git a/composer.json b/composer.json index c8a99b6..0bf1b1b 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "ext-SimpleXML": "*" }, "require-dev": { - "phpunit/phpunit": "~5.2" + "phpunit/phpunit": "~5.2", + "phpstan/phpstan": "^1.9" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index c1b1d58..0e25ee5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ac1cc801240b769f516f8b686bce361e", + "content-hash": "8b8189a56a2c6f495fe4a372a5fce419", "packages": [ { "name": "doctrine/inflector", @@ -1253,6 +1253,65 @@ }, "time": "2020-03-05T15:02:03+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.9.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "e08de53a5eec983de78a787a88e72518cf8fe43a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e08de53a5eec983de78a787a88e72518cf8fe43a", + "reference": "e08de53a5eec983de78a787a88e72518cf8fe43a", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/1.9.0" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2022-11-03T07:26:48+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "4.0.8", @@ -2299,5 +2358,5 @@ "ext-simplexml": "*" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.3.0" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..5fa5669 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +parameters: + paths: + - app + - src + level: 5 + parallel: + maximumNumberOfProcesses: 1 \ No newline at end of file diff --git a/src/Generator/EntityGenerator.php b/src/Generator/EntityGenerator.php index 79ca4b6..94e0afa 100644 --- a/src/Generator/EntityGenerator.php +++ b/src/Generator/EntityGenerator.php @@ -730,7 +730,7 @@ private function getRelationFromDependencies($relationName, $entityName) * * @param string $relationName * - * @return \SimpleXMLElement + * @return \SimpleXMLElement|null */ private function getRelationWithMatchingFieldsFromDependencies($relationName) { @@ -795,7 +795,7 @@ private function getRelationWithMatchingFieldsFromDependencies($relationName) * @param array $relations * @param array $relationFieldValue * - * @return null + * @return \SimpleXMLElement|null */ private function getMatchingRelation(&$relations, $relationFieldValue) { diff --git a/src/Service/XMLGeneratorService.php b/src/Service/XMLGeneratorService.php index df7a8b3..fd2a313 100644 --- a/src/Service/XMLGeneratorService.php +++ b/src/Service/XMLGeneratorService.php @@ -124,7 +124,7 @@ private static function generateXML( */ private static function sortModelWithDependencies(Finder $finder) { - $dependencies = $storedDependencies = []; + $dependencies = $storedDependencies = $parentEntities = []; foreach ($finder as $file) { $pathName = $file->getPathname();