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

Touch up documentation for phpcs locally #1897

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
13 changes: 6 additions & 7 deletions docs/technical-documentation/checking-coding-standards.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

# Checking Code Style

Before opening a pull request, you should check your code style. If you are using the [Vagrant](https://github.com/Islandora-Devops/claw-playbook), you can run `phpcs` within the Drupal installation directory (on the Vagrant, that is `/var/www/html/drupal`) or from within the `web` directory (`/var/www/html/drupal/web`) as follows:
Before opening a pull request, you should check your code style using PHP_CodeSniffer (phpcs). We use the Drupal coding standards provided by [Drupal coder](https://www.drupal.org/project/coder). If you are using the [Ansible Playbook](https://github.com/Islandora-Devops/islandora-playbook), phpcs and Drupal Coder are installed and phpcs can be run as follows:

* from within Drupal's root directory: `./vendor/bin/phpcs --standard=./vendor/drupal/coder/coder_sniffer/Drupal modules/contrib/my_module`, where `modules/contrib/my_module` is the relative or full path to the PHP file you want to check.
* from within Drupal's `web` directory: `../vendor/bin/phpcs --standard=../vendor/drupal/coder/coder_sniffer/Drupal yourfile`, where `yourfile` is the relative or full path to the PHP file you want to check.
* from within Drupal's root directory: `./vendor/bin/phpcs --standard=./vendor/drupal/coder/coder_sniffer/Drupal --ignore=*.md --extensions=php,module,inc,install,test,profile,theme,css,info web/modules/contrib/my_module`
* from within Drupal's `web` directory: `../vendor/bin/phpcs --standard=../vendor/drupal/coder/coder_sniffer/Drupal --ignore=*.md --extensions=php,module,inc,install,test,profile,theme,css,info modules/contrib/my_module`
Copy link
Member

Choose a reason for hiding this comment

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

we also use the DrupalPractice library

Copy link
Member Author

Choose a reason for hiding this comment

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

@elizoller I thought i knew what you meant but I'm not sure that I do!

In https://github.com/Islandora/islandora_ci/blob/main/travis_scripts.sh we run two commands: phpcs --standard=Drupal and phpcpd. The second one looks to me to be a "copy paste detector".

Looking into Drupal's docs on PHP CodeSniffer CommandLine Usage, they mention "Check Drupal Best Practices" with the example phpcs --standard=DrupalPractice.

I don't see where we actually run this in our code checks. From my knowledge, what's in travis_scripts.sh in the islandora_ci library is the code check that applies to all our repos.

@dannylamb or @whikloj might also know?


In both cases:

* `modules/contrib/my_module` is the relative or full path to the PHP file or directory you want to check.
* the path to the coding standard file can be relative to where you are running it from, e.g. when in `web`: `--standard=../vendor/drupal/coder/coder_sniffer/Drupal`
* you can specify a single file to check, or a directory path; in the latter case, all files in that directory will be checked.
* the options `--ignore=*.md --extensions=php,module,inc,install,test,profile,theme,css,info` are what is used in our Travis CI environment (specified in the [Islandora CI](https://github.com/Islandora/islandora_ci/blob/main/travis_scripts.sh) shared module), which will cause your Pull Request to pass or fail its checks.

Islandora 8 runs `phpcs` in its Travis continuous integration environment, and there, it specifies which files to ignore and which files to check. It is a good idea for developers to specify the same options when running `phpcs` locally, prior to opening a pull request. For example (running `phpcs` from the within Drupal's `web` directory), you should use the following `--ignore` and `--extensions` options:

`../vendor/bin/phpcs --standard=../vendor/drupal/coder/coder_sniffer/Drupal --ignore=*.md --extensions=php,module,inc,install,test,profile,theme,css,info modules/contrib/my_module`
If using a non-Ansible method of deployment, you may need to install phpcs and coder yourself, and the paths may vary.
Copy link
Member

Choose a reason for hiding this comment

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

This is a helpful bit of documentation if you're not using the ansible stuff