diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7421706..7a62b96 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,152 +1,148 @@ name: CI on: - pull_request: - push: - branches: - - 'main' + pull_request: + push: + branches: + - 'main' jobs: - composer-validate: - runs-on: ubuntu-latest - name: "Composer Validate" - steps: - - name: 'Checkout Code' - uses: actions/checkout@v2 - - - name: 'Validate composer.json' - run: composer validate --no-check-all --strict --no-check-lock - - composer-install: - needs: composer-validate - runs-on: ubuntu-latest - name: "Composer Install" - steps: - - name: 'Checkout Code' - uses: actions/checkout@v2 - - - name: 'Install Dependencies' - run: composer install --prefer-dist --no-progress --no-interaction - - code-style: - needs: composer-install - runs-on: ubuntu-latest - name: "Code Style" - strategy: - fail-fast: false - steps: - - name: 'Checkout Code' - uses: actions/checkout@v2 - - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - ini-values: memory_limit=-1 - coverage: none - tools: composer:v2 - - - name: 'Install PHP dependencies with Composer' - run: composer install --prefer-dist --no-progress --optimize-autoloader - working-directory: './' - - - name: 'Run CodeSniffer' - run: ./vendor/bin/phpcs ./ -p --encoding=utf-8 --extensions=php --ignore="vendor|Tests|src|public" --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony - - static-analysis: - needs: composer-install - runs-on: ubuntu-latest - name: "Static Analysis" - strategy: - fail-fast: false - steps: - - name: 'Checkout Code' - uses: actions/checkout@v2 - - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - ini-values: memory_limit=-1 - coverage: none - tools: composer:v2 - - - name: 'Install PHP dependencies with Composer' - run: composer install --prefer-dist --no-progress --optimize-autoloader - working-directory: './' - - - name: 'Run PHPStan' - run: ./vendor/bin/phpstan analyse --no-progress -c phpstan.neon ./ - - test: - needs: composer-install - runs-on: ubuntu-latest - name: "Tests (PHP ${{ matrix.php-version }} / Symfony ${{ matrix.symfony-version }})" - strategy: - fail-fast: false - matrix: - php-version: - - '7.4' - - '8.0' - - '8.1' - symfony-version: - - '5.3' - - '5.4' - - '6.0' - steps: - - name: 'Checkout Code' - uses: actions/checkout@v2 - - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - ini-values: memory_limit=-1 - coverage: none - tools: composer:v2 - env: - SYMFONY_VERSION: ${{ matrix.symfony-version }} - - - name: 'Install PHP dependencies with Composer' - run: composer install --prefer-dist --no-progress --optimize-autoloader - working-directory: './' - - - name: 'Run PHPUnit' - run: ./vendor/bin/phpunit -v -c phpunit.xml.dist - - code-coverage: - needs: test - runs-on: ubuntu-latest - name: "Code Coverage" - strategy: - fail-fast: false - steps: - - name: 'Checkout Code' - uses: actions/checkout@v2 - - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - ini-values: memory_limit=-1 - coverage: pcov - tools: composer:v2 - - - name: 'Install PHP dependencies with Composer' - run: composer install --prefer-dist --no-progress --optimize-autoloader - working-directory: './' - - - name: 'Run PHPUnit with Code Coverage' - run: ./vendor/bin/phpunit -v -c phpunit.xml.dist --coverage-clover=coverage.xml - - - name: 'Download Coverage Files' - uses: actions/download-artifact@v2 - with: - path: reports - - - name: 'Upload to Codecov' - uses: codecov/codecov-action@v1 - with: - files: ./coverage.xml - fail_ci_if_error: true - verbose: true + composer-validate: + runs-on: ubuntu-latest + name: "Composer Validate" + steps: + - name: 'Checkout Code' + uses: actions/checkout@v2 + + - name: 'Validate composer.json' + run: composer validate --no-check-all --strict --no-check-lock + + composer-install: + needs: composer-validate + runs-on: ubuntu-latest + name: "Composer Install" + steps: + - name: 'Checkout Code' + uses: actions/checkout@v2 + + - name: 'Install Dependencies' + run: composer install --prefer-dist --no-progress --no-interaction + + code-style: + needs: composer-install + runs-on: ubuntu-latest + name: "Code Style" + strategy: + fail-fast: false + steps: + - name: 'Checkout Code' + uses: actions/checkout@v2 + + - name: 'Setup PHP' + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + ini-values: memory_limit=-1 + coverage: none + tools: composer:v2 + + - name: 'Install PHP dependencies with Composer' + run: composer install --prefer-dist --no-progress --optimize-autoloader + working-directory: './' + + - name: 'Run CodeSniffer' + run: ./vendor/bin/phpcs ./ -p --encoding=utf-8 --extensions=php --ignore="vendor|Tests|src|public" --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony + + static-analysis: + needs: composer-install + runs-on: ubuntu-latest + name: "Static Analysis" + strategy: + fail-fast: false + steps: + - name: 'Checkout Code' + uses: actions/checkout@v2 + + - name: 'Setup PHP' + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + ini-values: memory_limit=-1 + coverage: none + tools: composer:v2 + + - name: 'Install PHP dependencies with Composer' + run: composer install --prefer-dist --no-progress --optimize-autoloader + working-directory: './' + + - name: 'Run PHPStan' + run: ./vendor/bin/phpstan analyse --no-progress -c phpstan.neon ./ + + test: + needs: composer-install + runs-on: ubuntu-latest + name: "Tests (PHP ${{ matrix.php-version }} / Symfony ${{ matrix.symfony-version }})" + strategy: + fail-fast: false + matrix: + php-version: + - '8.1' + symfony-version: + - '6.1' + steps: + - name: 'Checkout Code' + uses: actions/checkout@v2 + + - name: 'Setup PHP' + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + ini-values: memory_limit=-1 + coverage: none + tools: composer:v2 + env: + SYMFONY_VERSION: ${{ matrix.symfony-version }} + + - name: 'Install PHP dependencies with Composer' + run: composer install --prefer-dist --no-progress --optimize-autoloader + working-directory: './' + + - name: 'Run PHPUnit' + run: ./vendor/bin/phpunit -v -c phpunit.xml.dist + + code-coverage: + needs: test + runs-on: ubuntu-latest + name: "Code Coverage" + strategy: + fail-fast: false + steps: + - name: 'Checkout Code' + uses: actions/checkout@v2 + + - name: 'Setup PHP' + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + ini-values: memory_limit=-1 + coverage: pcov + tools: composer:v2 + + - name: 'Install PHP dependencies with Composer' + run: composer install --prefer-dist --no-progress --optimize-autoloader + working-directory: './' + + - name: 'Run PHPUnit with Code Coverage' + run: ./vendor/bin/phpunit -v -c phpunit.xml.dist --coverage-clover=coverage.xml + + - name: 'Download Coverage Files' + uses: actions/download-artifact@v2 + with: + path: reports + + - name: 'Upload to Codecov' + uses: codecov/codecov-action@v1 + with: + files: ./coverage.xml + fail_ci_if_error: true + verbose: true diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 2d43eea..bf2471e 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,10 +1,10 @@ checks: - php: true + php: true filter: - excluded_paths: - - vendor/* - - Tests/* + excluded_paths: + - vendor/* + - Tests/* before_commands: - - "composer install --prefer-dist" + - "composer install --prefer-dist" diff --git a/.styleci.yml b/.styleci.yml index 984d295..abb4d41 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -3,17 +3,17 @@ preset: symfony tab-width: 4 use-tabs: false enabled: - - combine_consecutive_unsets - - ordered_class_elements - - alpha_ordered_imports - - declare_strict_types - - phpdoc_order + - combine_consecutive_unsets + - ordered_class_elements + - alpha_ordered_imports + - declare_strict_types + - phpdoc_order disabled: - - no_superfluous_phpdoc_tags_symfony - - native_function_invocation_symfony + - no_superfluous_phpdoc_tags_symfony + - native_function_invocation_symfony finder: - exclude: - - "Tests" - - "vendor" - name: - - "*.php" + exclude: + - "Tests" + - "vendor" + name: + - "*.php" diff --git a/Config/ConfigParser.php b/Config/ConfigParser.php index 579ac4a..8118e0b 100644 --- a/Config/ConfigParser.php +++ b/Config/ConfigParser.php @@ -12,6 +12,7 @@ namespace StfalconStudio\SwaggerBundle\Config; +use StfalconStudio\SwaggerBundle\Exception\UnexpectedValueException; use Symfony\Component\Finder\Finder; use Symfony\Component\Yaml\Yaml; @@ -31,20 +32,24 @@ public function __construct(string $configFolder) } /** - * @return array + * @return mixed[] */ public function parse(): array { $config = Yaml::parseFile($this->configFolder.'index.yaml'); - $config = $this->iterate($config); + if (!\is_array($config)) { + throw new UnexpectedValueException(); + } - return $config; + return $this->iterate($config); } /** - * @param array $config + * @param mixed[] $config + * + * @throws UnexpectedValueException * - * @return array + * @return mixed[] */ private function iterate(array $config): array { @@ -77,7 +82,9 @@ private function iterate(array $config): array /** * @param string $dirPath * - * @return array + * @throws UnexpectedValueException + * + * @return mixed[] */ private function parseDir(string $dirPath): array { @@ -92,7 +99,12 @@ private function parseDir(string $dirPath): array $nestedDirs = []; if ($finder->hasResults()) { foreach ($finder as $file) { - $nestedDirs = \array_replace_recursive($nestedDirs, Yaml::parseFile($file->getPathname())); + $replacements = Yaml::parseFile($file->getPathname()); + if (!\is_array($replacements)) { + throw new UnexpectedValueException(); + } + + $nestedDirs = \array_replace_recursive($nestedDirs, $replacements); if (!\is_array($nestedDirs)) { throw new \UnexpectedValueException('Expected array after parsing, NULL given'); @@ -106,10 +118,18 @@ private function parseDir(string $dirPath): array /** * @param string $filePath * - * @return array + * @throws UnexpectedValueException + * + * @return mixed[] */ private function parseFile(string $filePath): array { - return Yaml::parseFile($filePath); + $result = Yaml::parseFile($filePath); + + if (!\is_array($result)) { + throw new UnexpectedValueException(); + } + + return $result; } } diff --git a/Exception/UnexpectedValueException.php b/Exception/UnexpectedValueException.php new file mode 100644 index 0000000..0545877 --- /dev/null +++ b/Exception/UnexpectedValueException.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace StfalconStudio\SwaggerBundle\Exception; + +/** + * UnexpectedValueException. + */ +class UnexpectedValueException extends \UnexpectedValueException +{ +} diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index 7f065d5..1aeea2d 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -1,11 +1,11 @@ services: - _defaults: - autowire: true - autoconfigure: true - public: false - bind: - $configFolder: "%swagger.config_folder%" - $docsFolder: "%kernel.project_dir%/public/api/" + _defaults: + autowire: true + autoconfigure: true + public: false + bind: + $configFolder: "%swagger.config_folder%" + $docsFolder: "%kernel.project_dir%/public/api/" - StfalconStudio\SwaggerBundle\: - resource: '../../{Command,Config,Generator}' + StfalconStudio\SwaggerBundle\: + resource: '../../{Command,Config,Generator}' diff --git a/Tests/Exception/UnexpectedValueExceptionTest.php b/Tests/Exception/UnexpectedValueExceptionTest.php new file mode 100644 index 0000000..e549742 --- /dev/null +++ b/Tests/Exception/UnexpectedValueExceptionTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace StfalconStudio\SwaggerBundle\Tests\DependencyInjection\Exception; + +use PHPUnit\Framework\TestCase; +use StfalconStudio\SwaggerBundle\Exception\UnexpectedValueException; + +/** + * UnexpectedValueExceptionTest. + */ +final class UnexpectedValueExceptionTest extends TestCase +{ + public function testConstructor(): void + { + $exception = new UnexpectedValueException(); + + self::assertInstanceOf(\UnexpectedValueException::class, $exception); + } +} diff --git a/composer.json b/composer.json index 0336eae..422ac5e 100644 --- a/composer.json +++ b/composer.json @@ -9,30 +9,30 @@ "issues": "https://github.com/stfalcon-studio/swagger-bundle/issues" }, "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-ctype": "*", "ext-iconv": "*", - "symfony/console": "^5.4 || ^6.0", - "symfony/flex": "^1.17", - "symfony/framework-bundle": "^5.4 || ^6.0", - "symfony/twig-bundle": "^5.4 || ^6.0", - "symfony/yaml": "^5.4 || ^6.0", - "symfony/asset": "^5.4 || ^6.0", - "symfony/finder": "^5.4 || ^6.0", - "symfony/polyfill-ctype": "^1.13", - "twig/twig": "^3.3" + "symfony/console": "^6.1", + "symfony/flex": "^v2.2", + "symfony/framework-bundle": "^6.1", + "symfony/twig-bundle": "^6.1", + "symfony/yaml": "^6.1", + "symfony/asset": "^6.1", + "symfony/finder": "^6.1", + "symfony/polyfill-ctype": "^1.26", + "twig/twig": "^3.4" }, "require-dev": { "escapestudios/symfony2-coding-standard": "^3.12", - "phpstan/phpstan": "^1.2", - "phpstan/phpstan-doctrine": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-symfony": "^1.0", + "phpstan/phpstan": "^1.7.10", + "phpstan/phpstan-doctrine": "^1.3", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-symfony": "^1.2", "thecodingmachine/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5", - "symfony/dotenv": "^5.4 || ^6.0", - "symfony/filesystem": "^5.4 || ^6.0", - "symfony/phpunit-bridge": "^5.4 || ^6.0" + "symfony/dotenv": "^6.1", + "symfony/filesystem": "^6.1", + "symfony/phpunit-bridge": "^6.1" }, "autoload": { "psr-4": {