Skip to content

Commit 8b90f63

Browse files
committed
Improved codesniffer support.
1 parent 8ddc8c9 commit 8b90f63

File tree

7 files changed

+76
-3
lines changed

7 files changed

+76
-3
lines changed

.ddev/commands/web/phpcbf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
## Description: Run PHP_CodeSniffer's code beautifier
4+
## Usage: phpcbf [flags] [args]
5+
## Example: "ddev phpcbf --standard=core/phpcs.xml.dist index.php" or "ddev phpcbf index.php"
6+
## HostWorkingDir: true
7+
## ExecRaw: true
8+
9+
if ! command -v phpcbf >/dev/null; then
10+
echo "phpcbf is not available. You may need to 'ddev composer require squizlabs/php_codesniffer'"
11+
exit 1
12+
fi
13+
phpcbf "$@"

.ddev/commands/web/phpcs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
## Description: Run PHP_CodeSniffer's codesniffer
4+
## Usage: phpcs [flags] [args]
5+
## Example: "ddev phpcs --standard=core/phpcs.xml.dist index.php" or "ddev phpcs index.php"
6+
## HostWorkingDir: true
7+
## ExecRaw: true
8+
9+
if ! command -v phpcs >/dev/null; then
10+
echo "phpcs is not available. You may need to 'ddev composer require squizlabs/php_codesniffer'"
11+
exit 1
12+
fi
13+
phpcs "$@"

.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ]; then
8383
fi
8484

8585
time "${GITPOD_REPO_ROOT}"/.gitpod/drupal/install-essential-packages.sh
86-
# Configure phpcs for drupal.
87-
cd "$GITPOD_REPO_ROOT" &&
88-
vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
86+
87+
# Configure phpcs for drupal if it's not already set up by the
88+
# dealerdirect/phpcodesniffer-composer-installer composer plugin.
89+
if ! ddev phpcs --config-show | \grep -q 'installed_paths:'; then
90+
ddev phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
91+
fi
8992

9093
# ddev config auto updates settings.php and generates settings.ddev.php
9194
ddev config --auto

.gitpod/utils/env-setup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ sudo cp protect-my-git.template.sh /usr/local/bin/protect-my-git
1717
# Create php command (run php inside ddev container)
1818
sudo cp ddev-php.template.sh /usr/local/bin/php
1919

20+
# Create phpunit command (run phpunit inside ddev container)
21+
sudo cp ddev-phpunit.template.sh /usr/local/bin/phpunit
22+
23+
# Create phpcs command (run phpcs inside ddev container)
24+
sudo cp ddev-phpcs.template.sh /usr/local/bin/phpcs
25+
26+
# Create phpcbf command (run phpcbf inside ddev container)
27+
sudo cp ddev-phpcbf.template.sh /usr/local/bin/phpcbf
28+
2029
# Create drush command (run drush inside ddev container)
2130
sudo cp ddev-drush.template.sh /usr/local/bin/drush
2231

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
>&2 echo "Notice: running 'phpcbf $*' in ddev"
3+
4+
if [ -n "${GITPOD_REPO_ROOT:-}" ]; then
5+
# Replace all references to the absolute paths to the repo root.
6+
# This will ensure IDEs like PHPStorm can pass files into it without issue.
7+
arguments=()
8+
for arg in "$@"; do
9+
new_arg="${arg//${GITPOD_REPO_ROOT}//var/www/html}"
10+
arguments+=("$new_arg")
11+
done
12+
else
13+
arguments=("$@")
14+
fi
15+
16+
ddev exec_d phpcbf "${arguments[@]}"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
>&2 echo "Notice: running 'phpcs $*' in ddev"
3+
4+
if [ -n "${GITPOD_REPO_ROOT:-}" ]; then
5+
# Replace all references to the absolute paths to the repo root.
6+
# This will ensure IDEs like PHPStorm can pass files into it without issue.
7+
arguments=()
8+
for arg in "$@"; do
9+
new_arg="${arg//${GITPOD_REPO_ROOT}//var/www/html}"
10+
arguments+=("$new_arg")
11+
done
12+
else
13+
arguments=("$@")
14+
fi
15+
16+
ddev exec_d phpcs "${arguments[@]}"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
>&2 echo "Notice: running 'phpunit $*' in ddev"
3+
ddev exec_d phpunit "$@"

0 commit comments

Comments
 (0)