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

First part of the PHPStorm guide #35

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ indent_size = 4
[*.{yml,yaml,neon}]
indent_size = 2

[*.md]
max_line_length = 80

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ tutorials available:

* [How to add a new static code analysis tool](doc/howto/HowToAddANewTool.md)
* [Adding new information to your TerminalCommand](doc/howto/HowToAddInformationSources.md)

## Integrating the Coding Standard into PHPStorm

If you want to integrate the ZooRoyal Coding Standard into PHPStorm, have a look
at the guides in the [doc/ideConfig](doc/ideConfig/IdeConfig.md) folder.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
],
"infection": [
"@test",
"infection -n --threads=$(getconf _NPROCESSORS_ONLN) --only-covered --skip-initial-tests --coverage=tmp/phpunit --no-progress"
"infection -n --threads=$(getconf _NPROCESSORS_ONLN) --skip-initial-tests --coverage=tmp/phpunit --no-progress"
]
},
"config": {
Expand Down
17 changes: 17 additions & 0 deletions doc/ideConfig/IdeConfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# How to use the Coding-Standard in PHPStorm

## Introduction

The Coding-Standard application is designed as an integrated application to make
sure it has as few dependencies as possible. As a result, it is less obvious how
to use the IDE with the project. This document will guide you through the steps
necessary to get code highlighting and auto-fixing working in your IDE.

The Coding-Standard incorporates different tools to check and fix your code.
Here are the guides to set up PHPStorm for each tool:

- [PHP Code Sniffer](phpCS/PhpCodeSniffer.md)




29 changes: 29 additions & 0 deletions doc/ideConfig/SetUpFromSource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Setup coding-standard-source

We need to make sure the coding-standard-source is installed and available
in your environment.

1) Clone the coding-standard-source repository
```bash
git clone git@github.com:ZooRoyal/coding-standard-source.git
```
2) Install the dependencies
```bash
composer install
```
Notice how npm dependencies are also installed. This is because of a
custom script in the composer.json file. ("post-install-cmd")

#### Optional

Check if everything works by running the coding-standard from source. For
this your need to switch to a git repository on your disc containing a composer.
json file and execute a test run.

```bash
cd /path/to/your/project
/path/to/coding-standard-source/tests/run-coding-standard.sh sca:all
```
The script understands the same parameters as the coding-standard
application. As it will build the coding-standard application from source it
will take a little longer then a normal run.
41 changes: 41 additions & 0 deletions doc/ideConfig/phpCS/PhpCodeSniffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Set up PHPStorm for PHP CodeSniffer

This guide will help you set up PHPStorm to use PHP CodeSniffer. You will be
able to see code highlighting and use auto-fixing in your IDE.

How long will it take: 15 minutes

Pre-requisites:
- Completed guide: [PHP-Interpreter](../phpInterpreter/PhpInterpreter.md)
- A local composer project, fully installed

## Steps

1) Open the PHPStorm IDE and load up the project you want to work on.
2) Open the settings dialog by pressing `Ctrl + Alt + S`(Windows + Linux)
`CMD + ,` (macOS).
3) Navigate to "PHP" -> "Quality Tools" -> "PHP CodeSniffer" and open the
Configuration by clicking on the "..." button.
![PHP CodeSniffer](php-code-sniffer.png)
4) If your [PHP interpreter](#Set-up-the-PHP-interpreter) we just set up in the
last step is not automatically added to the list click on the "+" button to
add it now.
5) Fill the Dialog as follows
* `PHP_CodeSniffer path` must be `/coding-standard/vendor/bin/phpcs`
* `Path to phpcbf` must be `/coding-standard/vendor/bin/phpcbf`

![PHP CodeSniffer Configuration](php-code-sniffer-configuration.png)
6) Click on the Folder Icon in `Docker container` and change the Volume bindings
as follows. The only entry allowed here is Hostpath = absolute Path to your
project -> Container path = /app

![PHP CodeSniffer Configuration](php-code-sniffer-configuration-docker.png)
7) Return to "PHP" -> "Quality Tools" -> "PHP_CodeSniffer".
8) Choose your newly added configuration and Switch it on.
9) Now we have to do something wierd. Close the settings dialog. Navigate to a
PHP file and do any change. Any change will do. Just add a space.
10) Return to the settings dialog by pressing `Ctrl + Alt + S`(Windows + Linux)
`CMD + ,` (macOS).
11) Navigate to "PHP" -> "Quality Tools" -> "PHP CodeSniffer" and
choose `ZooRoyal` as Coding standard.
12) Close dialog. You are done.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/ideConfig/phpCS/php-code-sniffer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions doc/ideConfig/phpInterpreter/PhpInterpreter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Set up the PHP interpreter


## Docker

This guide will show you how to install the PHP-Interpreter you need to execute
the coding-standard application.

How long will it take: 5 minutes

Pre-requisites:
- Running Docker service on your local machine

## Steps

1) Open the PHPStorm IDE and load up the project you want to work on.
2) Open the settings dialog by pressing `Ctrl + Alt + S`(Windows + Linux)
`CMD + ,` (macOS).
3) Remember what interpreter you are using right now
4) Navigate to "PHP" and open the interpreter settings by clicking on the
"..." button next to the interpreter dropdown.
![PHP Settings](php-settings.png)
5) Click on the "+" button to add a new interpreter.
Choose `From Docker`. In the following dialog choose `Docker` and use the image
`ghcr.io/zooroyal/coding-standard-source:latest`. Check that all settings are
equal to the image linked below.
![PHP Interpreter](php-settings-interpreter.png)
6) Make sure you don't forget to tick `Visible for all projects`.
7) Close this dialog.
8) Do not choose this interpreter as default CLI Interpreter. Use what you saw in step 2).

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/ideConfig/phpInterpreter/php-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"timeout": 20,
"minMsi": 94,
"minMsi": 86,
"minCoveredMsi": 94,
"source": {
"directories": [
Expand Down
Loading