env:
  global:
    - CC_TEST_REPORTER_ID=4eed0d135b9e1a1668a68e5e29cc71faf872937d13c42efa4faf42dad5ed3375

language: php

php:
  - 7.2.0
  - 7.2
  - 7.3

env:
  - phpunitflags="--stop-on-failure --testdox --exclude-group=live"

matrix:
  fast_finish: true
  include:
    - php: 7.2.0
      dist: xenial
      env:
        - lint="yes"
        - phpunitflags="do not run"
    - php: 7.4
      dist: bionic
      env:
        - analysis=yes
        - phpunitflags="do not run"
    - php: 7.4
      dist: bionic
      env:
        - lint=no
        - coverage=yes
        - phpunitflags="--stop-on-failure --testdox --coverage-clover=clover.xml"

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

before_script:
  - if [[ "$coverage" != "yes" ]]; then phpenv config-rm xdebug.ini; fi
  - composer install --no-interaction
  - if [[ "$coverage" = "yes" ]]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter; fi
  - if [[ "$coverage" = "yes" ]]; then chmod +x ./cc-test-reporter; fi
  - if [[ "$coverage" = "yes" ]]; then ./cc-test-reporter before-build; fi

script:
  - if [[ "$lint" != "no" ]]; then vendor/bin/parallel-lint .php_cs.dist src tests examples; fi
  - if [[ "$phpunitflags" != "do not run" ]]; then vendor/bin/phpunit $phpunitflags; fi
  - if [[ "$analysis" = "yes" ]]; then vendor/bin/composer-require-checker check ./composer.json; fi
  - if [[ "$analysis" = "yes" ]]; then vendor/bin/phpmnd ./ --exclude=./.github/ --exclude=./examples/ --exclude=./vendor/ --exclude=./psalm/cache/ --non-zero-exit-on-violation --hint; fi
  - if [[ "$analysis" = "yes" ]]; then vendor/bin/psalm --show-info=false --shepherd --diff --diff-methods; fi
  - if [[ "$lint" = "yes" ]]; then vendor/bin/php-cs-fixer fix --allow-risky=yes --no-interaction --dry-run --diff-format=udiff -v; fi
  - if [[ "$lint" = "yes" ]]; then vendor/bin/phpcpd src tests; fi

after_script:
  - if [[ "$coverage" = "yes" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT -t clover; fi
