name: CI
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - development
      - main
jobs:
  setup:
    name: Project Setup
    runs-on: ubuntu-latest
    permissions:
      contents: read
      actions: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.4'
          coverage: none
      - name: Cache vendor directory
        id: cache-vendor
        uses: actions/cache@v4
        with:
          path: ./vendor
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-composer-
      - name: Install dependencies (if needed)
        run: composer install --no-ansi --no-interaction --no-progress
        if: steps.cache-vendor.outputs.cache-hit != 'true'
      - name: Validate composer.json
        run: composer validate --no-ansi --strict composer.json
  phpstan:
    name: PHPStan
    needs: setup
    runs-on: ubuntu-latest
    permissions:
      contents: read
      actions: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.4'
          coverage: none
      - name: Cache vendor directory
        id: cache-vendor
        uses: actions/cache@v4
        with:
          path: ./vendor
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-composer-
      - name: Install dependencies (if needed)
        run: composer install --no-ansi --no-interaction --no-progress
        if: steps.cache-vendor.outputs.cache-hit != 'true'
      - name: Run PHPStan
        run: composer phpstan
  phpcs:
    name: PHP CodeSniffer
    needs: setup
    runs-on: ubuntu-latest
    permissions:
      contents: read
      actions: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.4'
          coverage: none
      - name: Cache vendor directory
        id: cache-vendor
        uses: actions/cache@v4
        with:
          path: ./vendor
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-composer-
      - name: Install dependencies (if needed)
        run: composer install --no-ansi --no-interaction --no-progress
        if: steps.cache-vendor.outputs.cache-hit != 'true'
      - name: Run PHP CodeSniffer
        run: composer phpcs
  phpunit:
    name: PHPUnit Tests
    needs: setup
    runs-on: ubuntu-latest
    permissions:
      contents: read
      actions: read
    strategy:
      matrix:
        php-version: [8.4, 8.5]
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}
          coverage: none
      - name: Cache vendor directory
        id: cache-vendor
        uses: actions/cache@v4
        with:
          path: ./vendor
          key: ${{ runner.os }}-composer-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-composer-${{ matrix.php-version }}-
      - name: Install dependencies (if needed)
        run: composer install --no-ansi --no-interaction --no-progress
        if: steps.cache-vendor.outputs.cache-hit != 'true'
      - name: Dump composer autoload
        run: composer dump-autoload
      - name: Generate Transfer Objects
        env:
          PROJECT_ROOT: ${{ github.workspace }}
        run: composer transfer-generate -- -c ./config/generator.config.yml
      - name: Run PHPUnit
        env:
          PROJECT_ROOT: ${{ github.workspace }}
        run: composer phpunit
 
  |