name: Static analysis

on:
  push:
  pull_request:

jobs:
  phpstan:
    name: PHPStan
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false

    steps:
      - name: Check out code
        uses: actions/checkout@v6.0.1

      - name: Install PHP
        uses: shivammathur/setup-php@2.36.0
        with:
          php-version: '7.4'
          tools: composer:v2
          coverage: none

      - name: Install dependencies
        uses: nick-fields/retry@v3.0.2
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --no-interaction --no-progress

      - name: Install PHPStan
        uses: nick-fields/retry@v3.0.2
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer bin phpstan update --no-interaction --no-progress

      - name: Run PHPStan
        run: make phpstan

  phan:
    name: Phan
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false

    steps:
      - name: Check out code
        uses: actions/checkout@v6.0.1

      - name: Install PHP
        uses: shivammathur/setup-php@2.36.0
        with:
          php-version: '7.4'
          tools: composer:v2
          coverage: none

      - name: Install dependencies
        uses: nick-fields/retry@v3.0.2
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --no-interaction --no-progress

      - name: Install Phan
        uses: nick-fields/retry@v3.0.2
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer bin phan update --no-interaction --no-progress

      - name: Symlink Phan binary
        run: ln -sf ../../vendor-bin/phan/vendor/phan/phan/phan vendor/bin/phan

      - name: Run Phan
        run: vendor/bin/phan --allow-polyfill-parser --load-baseline=.phan/baseline-ci.php
