sudo: false
language: php

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

matrix:
  fast_finish: true
  include:
    - php: 5.3
      dist: precise
    - php: 5.4
    - php: 5.5
    - php: 5.6
    - php: 7.0
      env: WITH_COVERAGE=true WITH_PHPCSFIXER=true
    - php: 7.1
    - php: 7.2
    - php: 'nightly'
    - php: hhvm
      dist: trusty
  allow_failures:
    - php: 'nightly'
    - php: hhvm

before_install:
  - if [[ "$WITH_COVERAGE" != "true" && "$TRAVIS_PHP_VERSION" != "hhvm" && "$TRAVIS_PHP_VERSION" != "nightly" && "$TRAVIS_PHP_VERSION" != "7.1" ]]; then phpenv config-rm xdebug.ini; fi
  - if [[ "$TRAVIS_PHP_VERSION" = "hhvm" || "$TRAVIS_PHP_VERSION" = "nightly" ]]; then sed -i '/^.*friendsofphp\/php-cs-fixer.*$/d' composer.json; fi

install:
  - travis_retry composer install --no-interaction --prefer-dist

script:
  - if [[ "$WITH_COVERAGE" == "true" ]]; then ./vendor/bin/phpunit --coverage-text; else composer test; fi
  - if [[ "$WITH_PHPCSFIXER" == "true" ]]; then mkdir -p $HOME/.phpcsfixer && vendor/bin/php-cs-fixer fix --cache-file "$HOME/.phpcsfixer/.php_cs.cache" --dry-run --diff --verbose; fi
