name: "PHPStan"

on:
  push:
    paths-ignore:
      - 'doc/**'
  pull_request:
    paths-ignore:
      - 'doc/**'

env:
  COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --no-suggest --prefer-dist"
  SYMFONY_PHPUNIT_VERSION: ""

jobs:
  tests:
    name: "PHPStan"

    runs-on: ubuntu-latest

    strategy:
      matrix:
        php-version:
          - "7.4"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v2"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "none"
          extensions: "intl"
          ini-values: "memory_limit=-1"
          php-version: "${{ matrix.php-version }}"
          tools: "cs2pr"

      - name: "Determine composer cache directory"
        id: "determine-composer-cache-directory"
        run: "echo \"::set-output name=directory::$(composer config cache-dir)\""

      - name: "Cache dependencies installed with composer"
        uses: "actions/cache@v1"
        with:
          path: "${{ steps.determine-composer-cache-directory.outputs.directory }}"
          key: "php-${{ matrix.php-version }}-symfony-php-unit-version-${{ env.SYMFONY_PHPUNIT_VERSION }}-${{ hashFiles('**/composer.lock') }}"
          restore-keys: "php-${{ matrix.php-version }}-symfony-php-unit-version-${{ env.SYMFONY_PHPUNIT_VERSION }}"

      - name: "Install highest dependencies from composer.json using composer binary provided by system"
        run: "composer config platform --unset && composer update ${{ env.COMPOSER_FLAGS }}"

      - name: Run PHPStan
        run: |
          bin/composer require --dev phpstan/phpstan:^0.12 phpunit/phpunit:^7.5 --with-all-dependencies
          vendor/bin/phpstan analyse --configuration=phpstan/config.neon --error-format=checkstyle | cs2pr