The PHP YAML parser is documented to parse a subset of YAML for configuration files.
It supports just the needed features to handle configuration files.
One things that is more difficult to get right, and what was left out is handling of multi-line scalar strings, the documentation even states that the much more simple to implement multi-line quoted messages (i.e. scalar strings) are not supported.
Codebeautify, who claim to be the best online YAML validator, cannot handle this correct YAML document either, with the same error, so they seem to be using the deficient PHP YAML parser as well.
If you are stuck with PHP, then you can do three things, the more readable is using literal style scalars as below (note the |
after the sequence element indicator -
):
sudo: false
language: php
php:
- 5.6
- 7.0
- 7.1
- hhvm
matrix:
allow_failures:
- php: 7.1
before_script:
- composer install --no-suggest ;
script:
- |
if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
vendor/bin/phpunit --coverage-clover clover.xml ;
vendor/bin/phpcs ;
else
vendor/bin/phpunit ;
fi
after_script:
- |
if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
vendor/bin/coveralls --coverage_clover=clover.xml -v ;
fi
this however changes the strings in that the newlines are preserved.
Similar to this is the folded style scalar string, if it weren't for the indented lines, it would remove the newlines at YAML load time. So if the above doesn't work you can do:
sudo: false
language: php
php:
- 5.6
- 7.0
- 7.1
- hhvm
matrix:
allow_failures:
- php: 7.1
before_script:
- composer install --no-suggest ;
script:
- >-
if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
vendor/bin/phpunit --coverage-clover clover.xml ;
vendor/bin/phpcs ;
else
vendor/bin/phpunit ;
fi
after_script:
- >-
if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then
vendor/bin/coveralls --coverage_clover=clover.xml -v ;
fi
And the final option is to rewrite the scalar strings to one line:
sudo: false
language: php
php:
- 5.6
- 7.0
- 7.1
- hhvm
matrix:
allow_failures:
- php: 7.1
before_script:
- composer install --no-suggest ;
script:
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then vendor/bin/phpunit --coverage-clover clover.xml ; vendor/bin/phpcs ; else vendor/bin/phpunit ; fi
after_script:
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ] ; then vendor/bin/coveralls --coverage_clover=clover.xml -v ; fi
This last version and the folded style load exactly the same as your YAML source by a more complete YAML parser than the one used by PHP. The literal style loads something different, but that might still work if your application treats newlines and spaces within those scalar strings in the same way.