Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for phpcs #111

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ env:
# This needs to match your .coveralls.yml file.
- DRUPAL_TI_COVERAGE_FILE="build/logs/clover.xml"

# === PHPCS specific variables.
# These arguments are passed to the phpcs command.
- DRUPAL_TI_PHPCS_ARGS=""
# The version of drupal/coder that should be used.
- DRUPAL_TI_DRUPAL_CODER_VERSION="drupal/coder:^8.2"

# Debug options
#- DRUPAL_TI_DEBUG="-x -v"
# Set to "all" to output all files, set to e.g. "xvfb selenium" or "selenium",
Expand Down
29 changes: 29 additions & 0 deletions functions/phpcs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# @file
# Common functionality for installing phpcs and friends.

#
# Ensures that phpcs is installed.
#
function drupal_ti_ensure_phpcs() {
# This function is re-entrant.
if [ -r "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" ]
then
return
fi

# Check if drupal/coder is already available.
DRUPAL_CODER=$(composer info --no-interaction drupal/coder || echo "")

if [ -z "$DRUPAL_CODER" ]
then
# Install drupal/coder globally.
echo "Installing drupal/coder: $DRUPAL_TI_DRUPAL_CODER_VERSION"
composer global require --no-interaction "$DRUPAL_TI_DRUPAL_CODER_VERSION"
else
echo "phpcs $DRUPAL_TI_DRUPAL_CODER_VERSION is already installed."
composer global install --no-interaction
fi

touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed"
}
7 changes: 7 additions & 0 deletions runners/phpcs/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Simple script to install dependencies for travis-ci running.

set -e $DRUPAL_TI_DEBUG

# Ensure that phpcs is installed.
drupal_ti_ensure_phpcs
9 changes: 9 additions & 0 deletions runners/phpcs/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# @file
# phpcs integration - Script step.

set -e $DRUPAL_TI_DEBUG

ARGS=( $DRUPAL_TI_PHPCS_ARGS )

$HOME/.composer/vendor/bin/phpcs "${ARGS[@]}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about also using phpcsp (Code Sniffer Drupal Practice) ?

ARGS=( $DRUPAL_TI_PHPCSP_ARGS )
$HOME/.composer/vendor/bin/phpcsp "${ARGS[@]}"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the phpcsp binary. Is there something I can read to learn about it?

I made a couple of modifications to provide default arguments and to make it easier to invoke drupal/coder standards.

2 changes: 1 addition & 1 deletion tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ln -sf "$SCRIPT_DIR/drupal-ti" /tmp/drupal_ti/bin/

# Setup runners.
export DRUPAL_TI_RUNNERS="success"
/tmp/drupal_ti/bin/drupal-ti script && echo "- Test succeeed as expected." || exit 1
/tmp/drupal_ti/bin/drupal-ti script && echo "- Test succeeded as expected." || exit 1

export DRUPAL_TI_RUNNERS="failure"
/tmp/drupal_ti/bin/drupal-ti script && exit 1 || echo "- Test failed as expected."
Expand Down