---
name: Test and analyze PHP
on:
  push: {}
  pull_request:
    branches:
      - main
      - develop
jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        php:
          - "8.0"
          - "8.1"
          - "8.2"
        include:
          - php-version: "8.0"
            phpunit: "9.5"
            phpunit-config: "phpunit.xml.dist"

    steps:
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "${{ matrix.php }}"
          extensions: redis, apcu, ctype, dom, iconv, gd, mbstring, fileinfo, intl, json, mysql, bcmath, zip
          coverage: none # disable xdebug, pcov
          ini-values: post_max_size=256M memory
          tools: cs2pr, pecl, php-cs-fixer, vimeo/psalm, phpstan, phpcs

      - uses: actions/checkout@v3

      - uses: "ramsey/composer-install@v2"
        with:
          composer-options: "--no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist -q"

      - name: PHPUnit tests
        uses: php-actions/phpunit@v3
        with:
          version: "${{ matrix.phpunit }}"
          configuration: "${{ matrix.phpunit-config }}"
          memory_limit: "256M"

      - name: Run phpstan
        run: phpstan analyse --error-format=checkstyle -c "phpstan.neon" | cs2pr

      #- name: Run psalm
      #  run: psalm -c psalm.xml --output-format=github

      - name: Check PHP code style
        continue-on-error: true
        run: phpcs --standard=phpcs.xml --parallel=2 --report-full --report-checkstyle=./phpcs-report.xml

      - name: Show PHPCS results in PR
        run: cs2pr ./phpcs-report.xml
