Skip to content

Commit

Permalink
Improved codesniffer support.
Browse files Browse the repository at this point in the history
  • Loading branch information
codebymikey committed May 30, 2024
1 parent 8ddc8c9 commit 8b90f63
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .ddev/commands/web/phpcbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

## Description: Run PHP_CodeSniffer's code beautifier
## Usage: phpcbf [flags] [args]
## Example: "ddev phpcbf --standard=core/phpcs.xml.dist index.php" or "ddev phpcbf index.php"
## HostWorkingDir: true
## ExecRaw: true

if ! command -v phpcbf >/dev/null; then
echo "phpcbf is not available. You may need to 'ddev composer require squizlabs/php_codesniffer'"
exit 1
fi
phpcbf "$@"
13 changes: 13 additions & 0 deletions .ddev/commands/web/phpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

## Description: Run PHP_CodeSniffer's codesniffer
## Usage: phpcs [flags] [args]
## Example: "ddev phpcs --standard=core/phpcs.xml.dist index.php" or "ddev phpcs index.php"
## HostWorkingDir: true
## ExecRaw: true

if ! command -v phpcs >/dev/null; then
echo "phpcs is not available. You may need to 'ddev composer require squizlabs/php_codesniffer'"
exit 1
fi
phpcs "$@"
9 changes: 6 additions & 3 deletions .gitpod/drupal/drupalpod-setup/drupalpod-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ]; then
fi

time "${GITPOD_REPO_ROOT}"/.gitpod/drupal/install-essential-packages.sh
# Configure phpcs for drupal.
cd "$GITPOD_REPO_ROOT" &&
vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer

# Configure phpcs for drupal if it's not already set up by the
# dealerdirect/phpcodesniffer-composer-installer composer plugin.
if ! ddev phpcs --config-show | \grep -q 'installed_paths:'; then
ddev phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
fi

# ddev config auto updates settings.php and generates settings.ddev.php
ddev config --auto
Expand Down
9 changes: 9 additions & 0 deletions .gitpod/utils/env-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ sudo cp protect-my-git.template.sh /usr/local/bin/protect-my-git
# Create php command (run php inside ddev container)
sudo cp ddev-php.template.sh /usr/local/bin/php

# Create phpunit command (run phpunit inside ddev container)
sudo cp ddev-phpunit.template.sh /usr/local/bin/phpunit

# Create phpcs command (run phpcs inside ddev container)
sudo cp ddev-phpcs.template.sh /usr/local/bin/phpcs

# Create phpcbf command (run phpcbf inside ddev container)
sudo cp ddev-phpcbf.template.sh /usr/local/bin/phpcbf

# Create drush command (run drush inside ddev container)
sudo cp ddev-drush.template.sh /usr/local/bin/drush

Expand Down
16 changes: 16 additions & 0 deletions .gitpod/utils/script-templates/ddev-phpcbf.template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
>&2 echo "Notice: running 'phpcbf $*' in ddev"

if [ -n "${GITPOD_REPO_ROOT:-}" ]; then
# Replace all references to the absolute paths to the repo root.
# This will ensure IDEs like PHPStorm can pass files into it without issue.
arguments=()
for arg in "$@"; do
new_arg="${arg//${GITPOD_REPO_ROOT}//var/www/html}"
arguments+=("$new_arg")
done
else
arguments=("$@")
fi

ddev exec_d phpcbf "${arguments[@]}"
16 changes: 16 additions & 0 deletions .gitpod/utils/script-templates/ddev-phpcs.template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
>&2 echo "Notice: running 'phpcs $*' in ddev"

if [ -n "${GITPOD_REPO_ROOT:-}" ]; then
# Replace all references to the absolute paths to the repo root.
# This will ensure IDEs like PHPStorm can pass files into it without issue.
arguments=()
for arg in "$@"; do
new_arg="${arg//${GITPOD_REPO_ROOT}//var/www/html}"
arguments+=("$new_arg")
done
else
arguments=("$@")
fi

ddev exec_d phpcs "${arguments[@]}"
3 changes: 3 additions & 0 deletions .gitpod/utils/script-templates/ddev-phpunit.template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
>&2 echo "Notice: running 'phpunit $*' in ddev"
ddev exec_d phpunit "$@"

0 comments on commit 8b90f63

Please sign in to comment.