name: CI

on:
  push:
  pull_request:

jobs:
  php-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
          tools: composer

      - name: Composer validate
        run: composer validate --no-check-publish

      - name: Composer install
        run: composer install --no-interaction --no-progress

      - name: PHP lint (non-vendor)
        shell: bash
        run: |
          set -euo pipefail
          files=$(find . -type f -name "*.php" -not -path "./vendor/*")
          for f in $files; do
            php -l "$f" > /dev/null
          done
          echo "Lint OK"

      - name: PHPUnit (if present)
        shell: bash
        run: |
          set -euo pipefail
          if [ -x "vendor/bin/phpunit" ] && [ -d "tests" ]; then
            vendor/bin/phpunit
          else
            echo "No tests to run"
          fi
