---
name: build
on:
    push: ~
    pull_request: ~

jobs:
    linux_legacy:
        name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
        runs-on: ubuntu-18.04
        strategy:
            matrix:
                php: ['7.2']
                stability: [prefer-lowest, prefer-stable]
                phpunit-flags: [ '--coverage-text' ]
        steps:
            - name: Checkout code
              uses: actions/checkout@v2

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  coverage: xdebug
                  tools: composer:v2

            - name: Install dependencies
              run: composer update --no-progress ${{ matrix.composer-flags }}

            - name: Run Test suite
              run: composer phpunit
    linux_tests:
        name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
        runs-on: ubuntu-20.04
        strategy:
            matrix:
                php: ['7.3', '7.4', '8.0']
                stability: [prefer-lowest, prefer-stable]
                include:
                    -   php: '8.1'
                        flags: "--ignore-platform-req=php"
                        stability: prefer-stable
                phpunit-flags: [ '--coverage-text' ]
        steps:
            - name: Checkout code
              uses: actions/checkout@v2

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  coverage: xdebug
                  tools: composer:v2

            - name: Install dependencies
              run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress ${{ matrix.flags }}

            - name: Run Test suite
              run: composer phpunit

            - name: Run static analysis
              run: composer phpstan
              if: ${{ matrix.php == '8.0' }}

            - name: Run codind style check
              run: composer phpcs
              if: ${{ matrix.php == '8.0' }}
