name: PHPStan Analysis

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-22.04

    strategy:
      fail-fast: false
      matrix:
        include:
          - php: '8.2'
            moodle-branch: 'MOODLE_405_STABLE'
          - php: '8.3'
            moodle-branch: 'MOODLE_405_STABLE'
          - php: '8.4'
            moodle-branch: 'MOODLE_500_STABLE'

    steps:
      - name: Setup moodle-branch
        uses: actions/checkout@v4
        with:
          repository: 'moodle/moodle'
          ref: ${{ matrix.moodle-branch }}
          path: .

      - name: Check out repository code
        uses: actions/checkout@v4
        with:
          path: ./local/learnwise

      - name: Setup PHP ${{ matrix.php }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: ${{ matrix.extensions }}
          ini-values: max_input_vars=5000
          # If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
          # If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
          coverage: none

      - name: Install PHPStan
        run: |
          composer require --dev micaherne/phpstan-moodle

      - name: Copy config
        run: |
          cp config-dist.php config.php

      - name: Run PHPStan on local/learnwise
        run: |

          # Run PHPStan on the local/learnwise directory
          vendor/bin/phpstan analyse local/learnwise -c local/learnwise/phpstan.neon
