language: php
sudo: required
php:
  - 7.1
  - 7.2
  - 7.3
  - 7.4

env:
  global:
    - RUN_PHPSTAN="FALSE"
  matrix:
    - PREFER_LOWEST="" WITH_COVERAGE="--coverage-clover=coverage.xml"
    - PREFER_LOWEST="--prefer-lowest" $WITH_COVERAGE=""

matrix:
  include:
    - name: 'PHPStan'
      php: 7.2
      env: RUN_PHPSTAN="TRUE"
  fast_finish: true

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

install:
  - if [ $RUN_PHPSTAN == "TRUE"  ]; then composer require --dev phpstan/phpstan:^0.12; fi

before_script:
  - composer update --prefer-source $PREFER_LOWEST
  - PHP_BIN=$(phpenv which php)
  - sudo $PHP_BIN -S localhost:80 -t $TRAVIS_BUILD_DIR/tests/www 2>/dev/null &

script:
  - if [ $RUN_PHPSTAN == "FALSE"  ]; then ./bin/php-cs-fixer fix --dry-run --diff; fi
  - if [ $RUN_PHPSTAN == "FALSE"  ]; then ./bin/phpunit --configuration tests/phpunit.xml $WITH_COVERAGE; fi
  - if [ $RUN_PHPSTAN == "TRUE"  ]; then php ./bin/phpstan analyse -c phpstan.neon lib; fi

after_success:
  - bash <(curl -s https://codecov.io/bash)
