name: CI

on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master
  workflow_dispatch:

jobs:
  cs-fix:
    name: CS Fixer
    runs-on: ubuntu-22.04

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'

    - name: Install dependencies
      run: composer install

    - name: Run CS Fixer
      run: composer run-script cs

  phpstan:
    name: PHPStan
    runs-on: ubuntu-22.04

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'

    - name: Install dependencies
      run: composer install

    - name: Run CS Fixer
      run: composer run-script phpstan

  tests:
    name: PHPUnit on PHP ${{ matrix.php-versions }}
    runs-on: ubuntu-22.04

    strategy:
      fail-fast: true
      matrix:
        php-versions: ['8.1', '8.2', '8.3', '8.4']

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php-versions }}

    - name: Install dependencies
      run: composer install

    - name: Run tests
      run: composer run-script test
