Project is based on Lando recipe drupal8, webroot is web and xdebug is enabled. .lando.yml example:
recipe: drupal8
services:
appserver:
webroot: web
xdebug: true
PHPCS (Code sniffer)
Add coder to composer.json
"drupal/coder": "^8.2"
or composer require
lando composer require drupal/coder
It will install squizlabs/php_codesniffer + Drupal coding standards sniffers.
Sometimes could be better to install PHPCS locally rather than install it inside project. Create some special dir for Coder and install via Composer.
composer require drupal/coder:8.2.12
.lando.yml
services:
appserver:
build:
- "mkdir -p /app/coder && cd /app/coder && composer require drupal/coder:8.2.12"
- "/app/coder/vendor/bin/phpcs --config-set installed_paths /app/coder/vendor/drupal/coder/coder_sniffer"
If you have PHPCS already installed via Lando, set only path to phpcs (/app/coder/vendor/bin/phpcs) into PHPstorm.
[ ] TODO: Find out solution: Set path to coding standards to /app/coder/vendor/drupal/coder/coder_sniffer for both Drupal + DrupalPractice standards at once causes error during checking code.
To manually register the Drupal
and DrupalPractice
Standard with PHPCS, you must set the installed paths. Go to appserver container.
lando ssh
You should stay at /app dir.
/app$ vendor/bin/phpcs --config-set installed_paths /app/vendor/drupal/coder/coder_sniffer
It will create file /vendor/squizlabs/php_codesniffer/CodeSniffer.conf and it should contain the valid path to sniffers. If PHPCS throws an errors, check this file.
Check status for Drupal standards.
app$ vendor/bin/phpcs -i
The installed coding standards are PSR2,.... PHPCS, Drupal and DrupalPractice
Now, you can run PHPCS manually to check your work.
app$ /path_to_coder/vendor/bin/phpcs --standard=Drupal,DrupalPractice path_to_module
e.g:
app$ vendor/bin/phpcs --standard=Drupal,DrupalPractice web/modules/contrib/default_content_deploy/
You can use . for current dir.
Add handy tool for PHPCS.
tooling:
phpcs:
service: appserver
cmd: "/app/coder/vendor/bin/phpcs --standard=Drupal,DrupalPractice"
options:
description: Run phpcs for given folder or file.
Run new command
lando phpcs relative_path/to_your_module/folder
lando phpcs relative_path/to_your_module/file.module
- Set PHP interpreter.
- Go to File → Settings… → Languages & Frameworks →PHP →CLI Interpreter →Click on the tree dots →Add. Select From Docker, Vagrant, VM, Remote…
- Select Docker from radio button options.
- Set Image name to devwithlando/php:7.1-fpm (you can find out the name by executing docker ps command). Uncheck Visible only for this project.
-
Go to File →Settings→Languages & Frameworks→PHP→Code Sniffer.
-
Go to File →Settings→Editor→Inspection.
-
Set Coding standards to Custom.
-
Choose one.
-
Set Path to ruleset /app/vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml.
-
No need to install Xdebug helper extension!
-
Refresh page in browser. An popup should appear in PHPstrom. Select the appropriate file. After confirming this popup, PHPstorm creates also new server (File →Settings→Languages & Frameworks→PHP→Servers) with name appserver.
-
Set PHP Server. If you already used debugging from browser, this setting should be already present.
-
Set path mappings. /app → your/local/path/to/project ** /app/vendor/drush -> /usr/local/bin/drush
-
Export environment variable. lando ssh appserver export PHP_IDE_CONFIG="serverName=appserver"
-
Set breakpoint.
-
Use drush commands from the appserver container. lando ssh cd web drush status