---
name: Continuous Integration

on: [push, pull_request]

jobs:

  php-cs-fixer:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
          coverage: none
          tools: cs2pr, composer
      - run: composer --working-dir=tools/php-cs-fixer install
      - run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --diff --dry-run --format=checkstyle | cs2pr

  phpstan:
    runs-on: ubuntu-latest
    name: phpstan
    steps:
      - uses: actions/checkout@v3
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
          coverage: none
          tools: cs2pr, composer
      - run: composer update
      - run: composer --working-dir=tools/phpstan install
      - run: tools/phpstan/vendor/bin/phpstan --error-format=checkstyle | cs2pr

  phpunit:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: [8.2, 8.1, 8.0, 7.4, 7.3]
        stability: [prefer-lowest, prefer-stable]
    name: PHPUnit on PHP ${{ matrix.php }}@${{ matrix.stability }}
    steps:
      - uses: actions/checkout@v3
      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: mbstring
          coverage: xdebug
      - run: |
          echo "::add-matcher::${{ runner.tool_cache }}/php.json"
          echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
      - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction # yamllint disable-line
      - run: vendor/bin/phpunit

  yamllint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ibiqlik/action-yamllint@v3
        with:
          format: github
