name: Continuous Integration
on: [push]

jobs:
    linter:
        name: Code Style
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v2
            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: 8.1
                  coverage: xdebug
            - name: Get Composer Cache Directory
              id: composer-cache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"
            - name: Cache dependencies
              uses: actions/cache@v2
              with:
                  path: ${{ steps.composer-cache.outputs.dir }}
                  key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
                  restore-keys: ${{ runner.os }}-composer-
            - name: Install Dependencies
              run: composer install --no-progress
            - name: Run php-cs-fixture
              run: vendor/bin/php-cs-fixer fix -v --dry-run

    phpstan:
        name: Static analysis
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v2
            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: 8.1
                  coverage: xdebug
            - name: Get Composer Cache Directory
              id: composer-cache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"
            - name: Cache dependencies
              uses: actions/cache@v2
              with:
                  path: ${{ steps.composer-cache.outputs.dir }}
                  key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
                  restore-keys: ${{ runner.os }}-composer-
            - name: Install Dependencies
              run: composer install --no-progress
            - name: Run phpstan
              run: vendor/bin/phpstan

    phpunit:
        name: Unit Tests
        runs-on: ubuntu-latest
        strategy:
            matrix:
                php: ['8.1', '8.2', '8.3']
                flags: ['', '--prefer-lowest', '--prefer-stable']
        steps:
            - name: Checkout
              uses: actions/checkout@v2
            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  coverage: xdebug
            - name: Get Composer Cache Directory
              id: composer-cache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"
            - name: Cache dependencies
              uses: actions/cache@v2
              with:
                  path: ${{ steps.composer-cache.outputs.dir }}
                  key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
                  restore-keys: ${{ runner.os }}-composer-
            - name: Install Dependencies
              run: composer update --prefer-dist --no-interaction --optimize-autoloader --prefer-stable --no-progress $COMPOSER_FLAGS
              env:
                  COMPOSER_FLAGS: ${{ matrix.flags }}
            - name: Run PHPUnit
              run: vendor/bin/phpunit
