language: php

sudo: false

matrix:
  include:
    - php: 7.0
      env: COLLECT_COVERAGE=false VALIDATE_CODING_STYLE=false RUN_PHPSTAN=false IGNORE_PLATFORMS=false
    - php: 7.1
      env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false RUN_PHPSTAN=false IGNORE_PLATFORMS=false
    - php: 7.2
      env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true RUN_PHPSTAN=true IGNORE_PLATFORMS=false
    - php: nightly
      env: COLLECT_COVERAGE=false VALIDATE_CODING_STYLE=false RUN_PHPSTAN=false IGNORE_PLATFORMS=true
  allow_failures:
    - php: nightly
  fast_finish: true

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

before_install:
  - travis_retry composer self-update

install:
  - if [ "$IGNORE_PLATFORMS" == "true" ]; then travis_retry composer update --no-interaction --prefer-source --ignore-platform-reqs; fi
  - if [ "$IGNORE_PLATFORMS" == "false" ]; then travis_retry composer update --no-interaction --prefer-source; fi

script:
  - composer phpunit
  - if [ "$VALIDATE_CODING_STYLE" == "true" ]; then composer phpcs; fi
  - if [ "$RUN_PHPSTAN" == "true" ]; then composer phpstan; fi

after_script:
 - if [ "$COLLECT_COVERAGE" == "true" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/clover.xml; fi
