sudo: false

language: php

matrix:
  fast_finish: true
  include:

    - php: 5.2
      env: PHPCS_VERSION="1.5.6"
    - php: 5.2
      env: PHPCS_VERSION="2.9"

    - php: 5.3
      env: PHPCS_VERSION=">=1.5.1,<2.0" COVERALLS_VERSION="~1.0"
    - php: 5.3
      env: PHPCS_VERSION=">=2.0,<3.0" COVERALLS_VERSION="~1.0"

    - php: 5.4
      env: PHPCS_VERSION=">=1.5.1,<2.0" COVERALLS_VERSION="~1.0"
    - php: 5.4
      env: PHPCS_VERSION=">=2.0,<3.0" COVERALLS_VERSION="~1.0"

    - php: 5.5
      env: PHPCS_VERSION=">=1.5.1,<2.0" COVERALLS_VERSION="dev-master"
    - php: 5.5
      env: PHPCS_VERSION=">=2.0,<3.0" COVERALLS_VERSION="dev-master"
    - php: 5.5
      env: PHPCS_VERSION="2.9.x-dev" COVERALLS_VERSION="dev-master"

    - php: 5.6
      env: PHPCS_VERSION=">=1.5.1,<2.0" COVERALLS_VERSION="dev-master"
    - php: 5.6
      env: PHPCS_VERSION=">=2.0,<3.0" COVERALLS_VERSION="dev-master"
    - php: 5.6
      env: PHPCS_VERSION="2.9.x-dev" COVERALLS_VERSION="dev-master"

    - php: 7.0
      env: PHPCS_VERSION=">=1.5.1,<2.0" COVERALLS_VERSION="dev-master"
    - php: 7.0
      env: PHPCS_VERSION=">=2.0,<3.0" COVERALLS_VERSION="dev-master"
    - php: 7.0
      env: PHPCS_VERSION="2.9.x-dev" SNIFF=1 COVERALLS_VERSION="dev-master"

    - php: 7.1
      env: PHPCS_VERSION=">=1.5.1,<2.0" COVERALLS_VERSION="dev-master"
    - php: 7.1
      env: PHPCS_VERSION=">=2.0,<3.0" COVERALLS_VERSION="dev-master"
    - php: 7.1
      env: PHPCS_VERSION="2.9.x-dev" COVERALLS_VERSION="dev-master"

    - php: nightly
      env: PHPCS_VERSION=">=1.5.1,<2.0"
    - php: nightly
      env: PHPCS_VERSION=">=2.0,<3.0"
    - php: nightly
      env: PHPCS_VERSION="2.9.x-dev"

    - php: hhvm
      dist: trusty
      env: PHPCS_VERSION=">=1.5.1,<2.0"
    - php: hhvm
      dist: trusty
      env: PHPCS_VERSION="2.9.x-dev"

  allow_failures:
    # Allow failures for unstable builds.
    - php: nightly
    - php: hhvm

before_install:
  - export XMLLINT_INDENT="    "
  # PHP 5.3+: set up test environment using Composer.
  - if [[ $TRAVIS_PHP_VERSION > "5.2" ]]; then composer self-update; fi
  - if [[ $TRAVIS_PHP_VERSION > "5.2" && $COVERALLS_VERSION ]]; then composer require --dev satooshi/php-coveralls:${COVERALLS_VERSION};fi
  - if [[ $TRAVIS_PHP_VERSION > "5.2" ]]; then composer require squizlabs/php_codesniffer:${PHPCS_VERSION}; fi
  - if [[ $TRAVIS_PHP_VERSION == hhv* ]]; then composer require phpunit/phpunit:~4.0; fi
  - if [[ $TRAVIS_PHP_VERSION > "5.2" ]]; then composer install; fi
  # PHP 5.2: set up test environment using git cloning.
  - if [[ $TRAVIS_PHP_VERSION < "5.3" ]]; then export PHPCS_DIR=/tmp/phpcs; fi
  - if [[ $TRAVIS_PHP_VERSION < "5.3" ]]; then export PHPCS_BIN=$PHPCS_DIR/scripts/phpcs; fi
  - if [[ $TRAVIS_PHP_VERSION < "5.3" ]]; then mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_VERSION $PHPCS_DIR; fi
  - if [[ $TRAVIS_PHP_VERSION < "5.3" ]]; then $PHPCS_BIN --config-set installed_paths "$(dirname "$(pwd)")"; fi

before_script:
  - if [[ $COVERALLS_VERSION ]]; then mkdir -p build/logs; fi
  - phpenv rehash

script:
  # Lint all PHP files against parse errors.
  - if [[ $TRAVIS_PHP_VERSION > "5.2" ]]; then ln -s `pwd` vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility; fi
  - if [[ $TRAVIS_PHP_VERSION > "5.2" ]]; then find -L . -path ./Tests/sniff-examples -prune -o -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l; fi
  - if [[ $TRAVIS_PHP_VERSION < "5.3" ]]; then find -L . -path ./Tests/sniff-examples -prune -o -path ./Tests/PHPUnit6Compat.php -prune -o -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l; fi
  # Check the code style of the code base.
  - if [[ "$SNIFF" == "1" ]]; then vendor/bin/phpcs . --standard=./phpcs.xml --runtime-set ignore_warnings_on_exit 1; fi
  # Run the unit tests.
  - if [[ $COVERALLS_VERSION ]]; then phpunit --configuration phpunit-travis.xml --coverage-clover build/logs/clover.xml; fi
  - if [[ $TRAVIS_PHP_VERSION == "5.2" || $TRAVIS_PHP_VERSION == "nightly" ]]; then phpunit --configuration phpunit.xml; fi
  - if [[ $TRAVIS_PHP_VERSION == hhv* ]]; then vendor/bin/phpunit --configuration phpunit.xml; fi
  # Validate the xml file.
  # @link http://xmlsoft.org/xmllint.html
  - if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./ruleset.xml; fi
  # Check the code-style consistency of the xml files.
  - if [[ "$SNIFF" == "1" ]]; then diff -B ./ruleset.xml <(xmllint --format "./ruleset.xml"); fi

after_success:
  - if [[ $COVERALLS_VERSION ]]; then php vendor/bin/coveralls -v -x build/logs/clover.xml; fi
