sudo: false
language: php

php:
    - 7.1
    - 7.2
    - 7.3
    - 7.4
    - nightly

cache:
    directories:
        - $HOME/.composer/cache
        - vendor

before_install:
    - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"

install: travis_retry composer install

before_script:
  - wget -O phpunit https://phar.phpunit.de/phpunit-9.phar
  - chmod +x phpunit
  - mkdir -p build/logs

script:
    - ./phpunit -c phpunit.xml.dist

jobs:
    allow_failures:
        - php: nightly

    include:
        - stage: Metrics and quality
          env: COVERAGE
          before_script:
              - wget -O phpunit https://phar.phpunit.de/phpunit-9.phar
              - chmod +x phpunit
              - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.2.0/php-coveralls.phar
              - chmod +x php-coveralls.phar
              - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
              - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
          script:
              - ./phpunit --coverage-clover build/logs/clover.xml
          after_script:
              - ./php-coveralls.phar --no-interaction

        - stage: Metrics and quality
          env: STATIC_ANALYSIS
          script:
              - ./vendor/bin/phpstan analyse

        - stage: Metrics and quality
          env: STATIC_ANALYSIS
          before_script:
              - wget -O phpunit https://phar.phpunit.de/phpunit-9.phar
              - chmod +x phpunit
              - ./phpunit --coverage-xml=build/coverage-xml --log-junit=build/junit.xml
              - wget https://github.com/infection/infection/releases/download/0.17.0/infection.phar
              - wget https://github.com/infection/infection/releases/download/0.17.0/infection.phar.asc
              - chmod +x infection.phar
          script:
              - ./infection.phar -s --threads=$(nproc) --coverage=build

        - stage: Security Check
          env: SECURITY_CHECK
          before_script:
              - wget -c https://get.sensiolabs.org/security-checker.phar
              - chmod +x security-checker.phar
          script:
              - ./security-checker.phar security:check
