[HELP] I don't understand how to customize and configure PhpStorm.
Closed this issue · 6 comments
Hi, thanks for the tool, it's very handy!
I'm following the docs and trying to add some customizations as well as configuring my IDE (PhpStorm) to with with PhpCodeSniffer and PHP-CS-Fixer but I'm having some trouble.
For PhpCodeSniffer I went ahead and created the .phpcs.xml.dist
file as the docs says but when I enable PhpCodeSniffer for PhpStorm I get the error: phpcs: ERROR: Referenced sniff "Tighten" does not exist
.
For PHP-CS-Fixer I also created the file .php-cs-fixer.dist.php
as the docs says but then I get all sorts of errors since classes like App\Support\PhpCsFixer
and App\Fixer\ClassNotation\CustomPhpUnitOrderFixer
don't exist.
I wonder what am I doing wrong and if you can share some light?
Thanks!
Hey @maxacarvalho
The config file was designed to work within Duster, but we do have a few options.
- You disable PHP_CodeSniffer for PhpStorm and just allow Duster to handle the lining. This is my preferred option because it reduces noise in the editor. If you're going to use Duster anyways, just let it do its thing.
- Copy the
standards
folder from Duster into your codebase and point PHP_CodeSniffer there; you'll probably need to tell PHP_CodeSniffer about the location; best to automate this incomposer.json
:
"scripts": {
"post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ./standards/Tighten/",
"post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ./standards/Tighten/"
}
- Update your composer to pull in Duster's source:
"config": {
"preferred-install": {
"laravel/duster": "source",
"*": "dist"
},
This will download all source files, not just the bin
.
Hi @driftingly
Thank a lot for your answer. I'd prefer the IDE to give me tips during the coding phase so the CI only catches what was missed.
The third option seems to be the best one for my use case but I can't use it since the namespace App\...
conflicts with my own.
Option two is risky since I'd miss updates.
I'll stick with the option 1 for now and keep an eye on the next releases. Thank you again.
Ok. If this becomes more of an issue I may just namespace under something like Tighten\Duster
instead of App
to provide more flexibility.
@driftingly I wonder if you have an idea for that to work with the option 3?
I don't think there's a way to overwrite a composer package namespace right?
Not that I know of; I tried to do that in Duster to work around conflicts between Duster and Pint which are both Laravel Zero apps.
You may be experiencing some issues with the installation and configuration of PhpCodeSniffer and PHP-CS-Fixer in PhpStorm. Here are some steps you can try to troubleshoot the issues:
For PhpCodeSniffer:
Make sure that you have installed the latest version of PhpCodeSniffer on your system. You can check the version by running the phpcs --version command in the terminal.
Ensure that the Tighten coding standard is installed. You can do this by running the following command in the terminal: composer global require "tightenco/tlint"
Check that the Tighten coding standard is listed in the phpcs.xml.dist file. You can add it manually by adding the following line to the file:
In PhpStorm, make sure that the PhpCodeSniffer plugin is installed and enabled. You can check this by going to Settings > Plugins and searching for PhpCodeSniffer.
Configure the path to the phpcs executable in PhpStorm. You can do this by going to Settings > Languages & Frameworks > PHP > Code Sniffer and specifying the path to the phpcs executable.
Check that the coding standard is set correctly in PhpStorm. You can do this by going to Settings > Editor > Inspections > PHP > PHP Code Sniffer Validation and selecting the Tighten coding standard.
For PHP-CS-Fixer:
Ensure that you have installed the latest version of PHP-CS-Fixer on your system. You can check the version by running the php-cs-fixer --version command in the terminal.
Check that the required classes are present in your project. If you are using Laravel, make sure that the App\Support\PhpCsFixer and App\Fixer\ClassNotation\CustomPhpUnitOrderFixer classes are present in the project. If not, you may need to install them using Composer.
Check that the php-cs-fixer.dist.php file is correctly configured. Make sure that the required fixers are enabled and that the paths to the files to be fixed are correctly specified.
In PhpStorm, make sure that the PHP-CS-Fixer plugin is installed and enabled. You can check this by going to Settings > Plugins and searching for PHP-CS-Fixer.
Configure the path to the php-cs-fixer executable in PhpStorm. You can do this by going to Settings > Languages & Frameworks > PHP > PHP-CS-Fixer and specifying the path to the php-cs-fixer executable.
Check that the PHP-CS-Fixer validation is set correctly in PhpStorm. You can do this by going to Settings > Editor > Inspections > PHP > PHP-CS-Fixer Validation and selecting the php-cs-fixer.dist.php configuration file.