language: php

dist: bionic

php:
  - 7.1
  - 7.2
  - 7.3
  - 7.4
env:
  - 'PHPUNIT=true'
  
# Cache Composer deps
cache:
  directories:
    - $HOME/.composer/cache

matrix:
  include:
    - name: 'PHP: 7.1; Lowest Stable Dependencies PHPUnit'
      php: 7.1
      env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest" PHPUNIT=true'
    - name: 'PHP: 8.0-dev; PHPUnit'
      php: nightly
      env: 'COMPOSER_FLAGS="--ignore-platform-reqs" PHPUNIT=true'
    - name: phpstan
      php: 7.1
      env: 'PHPSTAN=true'
    - name: rips
      php: 7.1
      env: 'RIPS=true'
      if: type != pull_request
      sudo: true
  allow_failures:
    - php: nightly
      env: 'COMPOSER_FLAGS="--ignore-platform-reqs" PHPUNIT=true'
  fast_finish: true

install:
  - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist

script:
  - if [[ $PHPSTAN ]]; then vendor/bin/phpstan analyse; fi
  - if [[ $PHPUNIT ]]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi
  - |
    if [[ $RIPS ]]; then
      docker run --rm -it -e RIPS_BASE_URI -e RIPS_PASSWORD -e RIPS_EMAIL -v `pwd`:/data rips/rips-cli:3 \
        rips:scan:start -p /data -T "$TRAVIS_BRANCH" -t high:0 -t critical:0 -t 5 -a 698
    fi

after_script:
  - if [[ $PHPUNIT ]] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi
