name: build

on: 
    push:
        branches:
            - '**'
        tags:
            - '!**'
    pull_request:
        branches:
            - '**'

jobs:
    phpstan:
        runs-on: ubuntu-24.04
        name: PHPStan
        steps:
            - name: Checkout
              uses: actions/checkout@v4
            - name: PHPStan
              uses: docker://oskarstark/phpstan-ga:1.8.0
              env:
                  REQUIRE_DEV: true
                  CHECK_PLATFORM_REQUIREMENTS: false
              with:
                  args: analyse
    cs-fixer:
        runs-on: ubuntu-24.04
        name: PHP-CS-Fixer
        steps:
            - name: Checkout
              uses: actions/checkout@v4
            - name: Fix CS
              uses: docker://oskarstark/php-cs-fixer-ga
              with:
                args: --diff --dry-run
    tests:
        runs-on: ubuntu-24.04
        strategy:
            fail-fast: false
            matrix:
                include:
                    - description: 'Lowest'
                      php: '8.1'
                      composer_option: '--prefer-lowest'
                    - description: '8.1'
                      php: '8.1'
                    - description: '8.2'
                      php: '8.2'
                    - description: '8.3'
                      php: '8.3'
                    - description: 'Dev deps'
                      php: '8.4'
                      dev: true
        name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
        steps:
            - name: Checkout
              uses: actions/checkout@v4
            - name: Cache
              uses: actions/cache@v4
              with:
                  path: ~/.composer/cache/files
                  key: ${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }} 
            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: mongodb-stable, pdo_sqlite
            - name: Configure for PHP 8.1
              run: composer require --dev --no-update laminas/laminas-code 4.12.0
              if: matrix.php == '8.1'
            - name: Go for dev dependencies
              run: composer config minimum-stability dev && composer config prefer-stable true
              if: matrix.dev
            - run: composer update --no-interaction --no-progress --ansi ${{ matrix.composer_option }}
            - run: vendor/bin/phpunit

