Skip to content

Commit

Permalink
Merge pull request #66 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
1.0.0-alpha1
  • Loading branch information
jrfnl authored Jan 23, 2020
2 parents 0c0e832 + 0d57749 commit 17c3692
Show file tree
Hide file tree
Showing 197 changed files with 32,073 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json
service_name: travis-ci
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
# https://blog.madewithlove.be/post/gitattributes/
#
/.coveralls.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/Tests/ export-ignore

#
# Auto detect text files and perform LF normalization
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
build/
vendor/
composer.lock
/composer.lock
/.phpcs.xml
/phpcs.xml
/phpunit.xml
/.phpunit.result.cache
186 changes: 180 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,203 @@ language: php

## Cache composer and apt downloads.
cache:
apt: true
directories:
# Cache directory for older Composer versions.
- $HOME/.composer/cache/files
# Cache directory for more recent Composer versions.
- $HOME/.cache/composer/files

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

env:
- PHPCS_VERSION="dev-master" LINT=1
- PHPCS_VERSION="3.1.0"
- PHPCS_VERSION="2.9.2"
- PHPCS_VERSION="2.6.0"

# Define the stages used.
# For non-PRs, only the sniff and quicktest stages are run.
# For pull requests and merges, the full script is run (skipping quicktest).
# Note: for pull requests, "develop" is the base branch name.
# See: https://docs.travis-ci.com/user/conditions-v1
stages:
- name: sniff
- name: quicktest
if: type = push AND branch NOT IN (master, develop)
- name: test
if: branch IN (master, develop)
- name: coverage
if: branch IN (master, develop)

jobs:
fast_finish: true
include:
#### SNIFF STAGE ####
- stage: sniff
php: 7.3
env: PHPCS_VERSION="dev-master"
addons:
apt:
packages:
- libxml2-utils
install: skip
script:
# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- composer validate --no-check-all --strict

# Check the code style of the code base.
- composer travis-checkcs

# Validate the xml files.
# @link http://xmlsoft.org/xmllint.html
- xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./PHPCSUtils/ruleset.xml
- xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./PHPCS23Utils/ruleset.xml

# Check the code-style consistency of the xml files.
- diff -B ./PHPCSUtils/ruleset.xml <(xmllint --format "./PHPCSUtils/ruleset.xml")
- diff -B ./PHPCS23Utils/ruleset.xml <(xmllint --format "./PHPCS23Utils/ruleset.xml")

#### QUICK TEST STAGE ####
# This is a much quicker test which only runs the unit tests and linting against the low/high
# supported PHP/PHPCS combinations.
# These are basically the same builds as in the Coverage stage, but then without doing
# the code-coverage.
- stage: quicktest
php: 7.4
env: PHPCS_VERSION="dev-master" LINT=1
- stage: quicktest
php: 7.3
# PHPCS is only compatible with PHP 7.3 as of version 3.3.1/2.9.2.
env: PHPCS_VERSION="2.9.2"

- stage: quicktest
php: 5.4
env: PHPCS_VERSION="dev-master" LINT=1
- stage: quicktest
php: 5.4
env: PHPCS_VERSION="2.6.0"

#### TEST STAGE ####
# Additional builds to prevent issues with PHPCS versions incompatible with certain PHP versions.
- stage: test
php: 7.3
env: PHPCS_VERSION="dev-master" LINT=1
- php: 7.3
# PHPCS is only compatible with PHP 7.3 as of version 3.3.1/2.9.2.
env: PHPCS_VERSION="3.3.1"

- php: 5.4
env: PHPCS_VERSION="3.1.0"
- php: 5.4
env: PHPCS_VERSION="2.9.2"

# PHPCS is only compatible with PHP 7.4 as of version 3.5.0.
- php: 7.4
env: PHPCS_VERSION="3.5.0"

# One extra build to verify issues around PHPCS annotations when they weren't fully accounted for yet.
- php: 7.2
env: PHPCS_VERSION="3.2.0"

- php: "nightly"
env: PHPCS_VERSION="n/a" LINT=1

#### CODE COVERAGE STAGE ####
# N.B.: Coverage is only checked on the lowest and highest stable PHP versions for all PHPCS versions.
# These builds are left out off the "test" stage so as not to duplicate test runs.
# The script used is the default script below, the same as for the `test` stage.
- stage: coverage
php: 7.4
env: PHPCS_VERSION="dev-master" LINT=1 COVERALLS_VERSION="^2.0"
- php: 7.3
# PHPCS is only compatible with PHP 7.3 as of version 3.3.1/2.9.2.
env: PHPCS_VERSION="2.9.2" COVERALLS_VERSION="^2.0"

- php: 5.4
env: PHPCS_VERSION="dev-master" LINT=1 COVERALLS_VERSION="^1.0"
- php: 5.4
env: PHPCS_VERSION="2.6.0" COVERALLS_VERSION="^1.0"


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


before_install:
# Speed up build time by disabling Xdebug when its not needed.
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Coverage" ]]; then
phpenv config-rm xdebug.ini || echo 'No xdebug config.'
fi
# On stable PHPCS versions, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Sniff" && $PHPCS_VERSION != "dev-master" && "$PHPCS_VERSION" != "n/a" ]]; then
echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
fi
- export XMLLINT_INDENT=" "


install:
# Set up test environment using Composer.
- |
if [[ $PHPCS_VERSION != "n/a" ]]; then
composer require --no-update --no-scripts squizlabs/php_codesniffer:${PHPCS_VERSION}
fi
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then
composer require --dev --no-update --no-suggest --no-scripts php-coveralls/php-coveralls:${COVERALLS_VERSION}
fi
- |
if [[ $PHPCS_VERSION == "n/a" ]]; then
# Don't install PHPUnit when it's not needed.
composer remove --dev phpunit/phpunit --no-update --no-scripts
elif [[ "$PHPCS_VERSION" < "3.1.0" ]]; then
# PHPCS < 3.1.0 is not compatible with PHPUnit 6.x.
composer require --dev phpunit/phpunit:"^4.0||^5.0" --no-update --no-scripts
elif [[ "$PHPCS_VERSION" < "3.2.3" ]]; then
# PHPCS < 3.2.3 is not compatible with PHPUnit 7.x.
composer require --dev phpunit/phpunit:"^4.0||^5.0||^6.0" --no-update --no-scripts
fi
# --prefer-dist will allow for optimal use of the travis caching ability.
# The Composer PHPCS plugin takes care of setting the installed_paths for PHPCS.
- composer install --prefer-dist --no-suggest


before_script:
- if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then mkdir -p build/logs; fi
- phpenv rehash


script:
# Validate the composer.json file on low/high PHP versions.
# @link https://getcomposer.org/doc/03-cli.md#validate
- composer validate --no-check-all --strict
# Lint PHP files against parse errors.
- if [[ "$LINT" == "1" ]]; then composer lint; fi

# Run the unit tests.
- |
if [[ $PHPCS_VERSION != "n/a" && "$TRAVIS_BUILD_STAGE_NAME" != "Coverage" ]]; then
composer test
elif [[ $PHPCS_VERSION != "n/a" && "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then
composer coverage
fi
after_success:
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" && $COVERALLS_VERSION == "^1.0" ]]; then
php vendor/bin/coveralls -v -x build/logs/clover.xml
fi
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" && $COVERALLS_VERSION == "^2.0" ]]; then
php vendor/bin/php-coveralls -v -x build/logs/clover.xml
fi
52 changes: 52 additions & 0 deletions PHPCS23Utils/Sniffs/Load/LoadUtilsSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
*
* @package PHPCSUtils
* @copyright 2019 PHPCSUtils Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSUtils
*/

namespace PHPCS23Utils\Sniffs\Load;

/*
* Here be magic.
*
* This include allows for the Utility functions to work PHPCS cross-version.
*/
require_once \dirname(\dirname(\dirname(__DIR__))) . '/phpcsutils-autoload.php';

/**
* Dummy Sniff.
*
* This sniff doesn't do anything. It's just here to trigger the above include.
*
* @since 1.0.0
*/
class LoadUtilsSniff
{

/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return [];
}

/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process($phpcsFile, $stackPtr)
{
}
}
4 changes: 4 additions & 0 deletions PHPCS23Utils/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCS23Utils" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<description>Standard which makes the PHPCSUtils utility methods for external PHPCS standards available in PHPCS 2.x.</description>
</ruleset>
Loading

0 comments on commit 17c3692

Please sign in to comment.