sudo: false

language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

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

env:
  matrix:
  - DEPENDENCIES_PREFERENCE="--prefer-lowest"
  - DEPENDENCIES_PREFERENCE=""

before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"

install:
- >
  export IGNORE_PLATFORM_REQS="$(composer php:version |grep -q '^7.3' && printf -- --ignore-platform-reqs)";
  echo;
  echo "Updating the dependencies";
  composer update $IGNORE_PLATFORM_REQS --with-dependencies $DEPENDENCIES_PREFERENCE;
  composer show;

script:
- >
  echo;
  echo "Validating the composer.json";
  composer validate --no-check-all --no-check-lock --strict;

- >
  echo;
  echo "Linting all PHP files";
  composer ci:php:lint;

- >
  echo;
  echo "Running the unit tests";
  composer ci:tests:unit;

- >
  echo;
  echo "Running PHPMD";
  composer ci:php:md;

- >
  echo;
  function version_gte() { test "$(printf '%s\n' "$@" | sort -n -t. -r | head -n 1)" = "$1"; };
  if version_gte $(composer php:version) 7; then
    echo "Installing slevomat/coding-standard only for PHP 7.x";
    composer require $IGNORE_PLATFORM_REQS --dev slevomat/coding-standard:^4.0 $DEPENDENCIES_PREFERENCE;
    echo "Running PHP_CodeSniffer";
    composer ci:php:sniff;
  else
    echo "Skipped PHP_CodeSniffer due to insufficient PHP version: $(composer php:version)";
  fi;
