name: "PHPStan"

on:
  push:
  pull_request:

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

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"
          ini-values: "memory_limit=-1"
          php-version: "${{ matrix.php-version }}"


      - name: "Determine composer cache directory"
        id: "determine-composer-cache-directory"
        run: "echo \"::set-output name=directory::$(php bin/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 }}-${{ hashFiles('**/composer.json') }}"
          restore-keys: "php-${{ matrix.php-version }}"

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

      - name: Run PHPStan
        run: |
          composer require --dev phpstan/phpstan:^0.12.26
          vendor/bin/phpstan analyse --configuration=phpstan-config.neon
