stages:
  - check
  - build
  - test

default:
  image: php:latest
  cache:
    paths:
      - vendor/
  before_script:
    - apt update -yqq
    - apt install git libzip-dev -yqq
    - docker-php-ext-install zip
    - curl -sS https://getcomposer.org/installer | php
    - php composer.phar install

job:check:php:
  stage: check
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  before_script:
    - curl -o /usr/local/bin/parallel-lint -fsL https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/latest/download/parallel-lint.phar
  script:
    - php /usr/local/bin/parallel-lint --exclude .git --exclude vendor .

job:build:
  stage: build
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  script:
    - php composer.phar audit --abandoned=report

job:test:php-latest:
  stage: test
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: never # on_success — réactiver quand des tests existent
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  script:
    - vendor/bin/phpunit --no-coverage

job:test:php-8.2:
  stage: test
  needs:
    - job:test:php-latest
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: never
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  image: php:8.2
  script:
    - vendor/bin/phpunit --no-coverage

job:test:ecs:
  stage: test
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  script:
    - php -d display_errors=0 vendor/bin/ecs check --output-format=gitlab > ecs-quality-report.json
  artifacts:
    paths:
      - ecs-quality-report.json
    reports:
      codequality: ecs-quality-report.json

job:test:phpstan:
  stage: test
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: never
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  script:
    - php -d memory_limit=1G vendor/bin/phpstan analyse --error-format gitlab > phpstan-quality-report.json
  artifacts:
    paths:
      - phpstan-quality-report.json
    reports:
      codequality: phpstan-quality-report.json