PhpStorm Tips, ticks and standard setup
- Tips and Tracks for PHPStorm (PHPStorm Tips and Tricks.md)
- Standard setup for PHP projects (Standard.md)
DPC2017: PhpStorm Tips Tricks - Gary Hockin
Will toggle the navigation panel
Recent files list
Open a file by its file name
Double shift will open search Everywhere, which will search all files, methods, classes etc.
Open the version control panel
Toggle all open panels, just leaving the code windows, press again to restore them.
When in the code Ctrl + Shift + T will move to the corresponding unit test. The same keys will toggle back.
Keep pressing Escape to close all open windows and return to the core window.
Hover over the inspections in the right gutter to see what PHPStorm thinks is wrong, colour coded for severity. Red is a warning, orange is info.
Jump to the next highlighted error
When on an error a quick fix light bulb will display. Alt + enter will open the menu for the possible actions. E.g. Add method, Update PHPDoc Comment.
Move to the previous position in the core window. Will toggle between files too.
Will open the Refactor This menu. Press the number corresponding the the required refactor. Note the direct shortcut is also listed for future use.
If the method is camel case, then the caret can jump to the next word.
Highlight a block of code, then Ctrl + Alt + M will open the Extract Method window. The code block can be given a method name and automatically moved to its own method, the original code will call the new method.
Jumps to the method declaration.
Create your own code snippets or use the built in one, start typing the code name and press tab for it to complete.
Start typing live templates to quickly search for the location (Editor > Live Templates), there are live templates for many languages, expand PHP to see the key words. Built in include:
Example type fore
to create a foreach loop, the first variable should be a plural, the second variable will automatically be changed to the singular. Press Tab to navigate to the next item. (Choose Lookup Item Replace via ->| (Tab))
Example for vdd for Var Dump and Die.
Search for Postfix.
Built in include:
Type in the expression then dot keyword for the code block to be generated
Example:
$name.isset
Tab will convert to:
if (isset($name)) {
}
You can't add your own Postfix completions, at the moment.
Click in a code block, press Ctrl + w to select the item clicked, press ctrl + w again to expand the selection, e.g. to an if statement, press ctrl + w again to expand again, e.g. to the code block.
Contact the selection back to the original cursor location.
Type in Split
and enter to select Split Horizontally. Ctrl + F4 to close the file (and window). Alt + Tab to switch file
Search for Xdebug, it is available under Preferences
Hover over the inspections in the right gutter to see what PHPStorm thinks is wrong, a mini window called the editor lens will show the code without having to navigate to that section in the file.
Choose the required language and a new scratch file will open, you can enter code snippets too.
The code will run in the Run terminal (Alt + 4 to toggle) or Right Click and select run
Saves all the documents, including scratch files.
Displayed in the bottom right of the screen. Highlighting Level can be changed for PHP and HTML, Power Save Mode can be used, to save battery.
When a method/function is called the type hints for the parameter name is displayed. Turn off under Editor > General > Appearance > Show parameter name hints.
PHPStorm has support for PHP 7 including strict declaration
Search for missing declaration
Editor > Inspections under PHP > Type compatibility > Missing strict types declaration
The syntax highlighting will show a missing strict type declaration, F2 to goto the error, Alt + Enter to select the quick fix and Enter again will automatically add:
declare(strict_types=1);
The severity can also be changed from Warning (yellow) to Error (red).
Type hinting and return types will ne highlighted, if there are any errors.
Will pull up the inspections, type declaration and select Missing strict types declaration, then against the Project, including tests. The inspection will highlight all files, they can be checked one by one or click Add strict types declaration
to apply it to the whole project.
Can be used for an inspections, for example to convert old array syntax to short array syntax.
Version control (git).
VCS > Local History > Show History
Independent version control built into PHPStorm.
Make API calls (similar to Postman) from within PHPStorm
Example: HTTP Method: GET Host/Port: http://api.joind.in Path: /v2.1/events Ctrl + Enter to submit
Search for external tools, it is under Tools > External Tools.
Gary demonstrates PHPCS.
Program is the location of the phpcs file (or bat file)
Working directory is
PHPMD can also be configured.
Commands can be bound to their own keyboard shortcut.
Multiple terminals can be opened, e.g. to run php artisan serve
Install the JetBrains extension in your browser
Google JetBrains IDE Support for chrome
Changes made in HTML are live viewed in Chrome.
Example: div>lorem10*3TAB will create three div tags with Lorem Ipsum text.
Hold down Alt, while clicking the space to use a cursor will add an additional cursor, keep holding Alt and clicking for multiple. Start typing and the text will be entered at all selected locations.
Esc key will exit multiple cursor mode.
There is also Column Selection Mode Alt + Shift + Insert to toggle. the cursor keys can be moved up and down to expand multiple cursors.
See the recoding on the YouTube channel.
Opens the database browser.
Browse the database tables, write SQL statements in the console.
Once the database browser is configured completion is available in the code editor.
If writing in one language, but code completion is needed for another use Alt + Enter and select Inject language or reference
. Useful inside a string or heredoc.
It is also possible to use a PHPDoc to declare the language using the same Alt + Enter quick hint.
File > Open, select the project folder and Open, then choose This Window
or New Window
Opening a new project in this window, the original project will have the code styles.
Reformat the code to the set coding standard.
Help menu > Productivity Guide.
This is also Help > New Support Request
the Productivity guide shows PHPStorm features which have been used and how often.
The focus in setting up PHP Projects in PHPStorm, in particular a Laravel project.
Composer with php codeSniffer, PHPUnit, and easy coding standard. Also some simplify projects to allow the output to be displayed in PHPStorm.
Below are some other options, including psalm, Rector and PHP Mess Detector.
Example snippet of a composer.json
{
"require-dev": {
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.5.0",
"squizlabs/php_codesniffer": "^3.5.3",
"symplify/easy-coding-standard": "^7.1",
"symplify/phpstan-extensions": "^7.1",
"nunomaduro/larastan": "^0.5.0",
"phpstan/phpstan-phpunit": "^0.12.2",
},
"scripts": {
"checkcode": "phpcs src tests --standard=PSR12",
"fixcode": "phpcbf src tests --standard=PSR12",
"test": "phpunit",
"tests": "phpunit",
"check-cs": "ecs check src tests --ansi",
"fix-cs": "ecs check src tests --fix --ansi",
"phpstan": "phpstan analyse src tests --ansi --error-format symplify",
}
}
Example .editorconfig
file, normally found in the root of a project.
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
Xdebug is used to debug PHP script, however due to how it analyses the script it makes PHP very slow, debugging should only enable it when debugging is required.
Add the following to the php.ini:
[xdebug]
zend_extension=xdebug
xdebug.remote_enable=1
xdebug.remote_port=9000
Note: PhpStorm will automatically enable xdebug, when the following is configure and debugging is enable, there is no need to leave xdebug enabled in php.ini. To temporarily disable xdebug comment out and the line. Using Laragon: Menu > PHP > Quick settings > xdebug, click to toggle on and off. This will be the same as manually adding a ; to the php.ini file:
[xdebug]
;zend_extension=xdebug
...
TL;DR (parts copied from above PhpStorm Tutorials, full version below)
In the Settings/Preferences dialog Ctrl+Alt+S, select Languages & Frameworks | PHP.
Check the Xdebug installation associated with the selected PHP interpreter:
a. On the PHP page, choose the relevant PHP installation from the CLI Interpreter list and click the Browse button next to the field.
b. The CLI Interpreters dialog that opens shows the following:
i. The version of the selected PHP installation. (e.g. D:\laragon\bin\php\php-7.4.4-Win32-vc15-x64\php.exe)
ii. The name and version of the debugging engine associated with the selected PHP installation (Xdebug). (e.g. D:\laragon\bin\php\php-7.4.4-Win32-vc15-x64\ext\php_xdebug.dll)
iii Once set click OK.
Define the Xdebug behaviour. Click Debug under the PHP node (Languages & Frameworks | PHP | Debug.). On the Debug page that opens, specify the following settings in the Xdebug area:
Set a breakpoint in the file to be inspected.
Open public/index.php, wait for the file to open, then in to top right there will be a floating bar with a list of browsers. Click Chrome (Alt+F2 + Choose Chrome)
Chrome browser will launch and open the projects webpage. If the Debug icon isn't already green, click the Debug icon for Xdebug helper extension. From the drop down list click Debug option, the icon will then display green.
Navigate the project's website, to the page which uses the file that has the breakpoint set. As soon as the page is hit PhpStorm will open (it may be behind the browser).
In PhpStorm, accept the connection (this warning normally only displays the first hit and accepted once).
Debug information will display in the console, including the option to inspect variables and evaluate.
For the full version of the above see Configuring Xdebug in PhpStorm and Browser Debugging Extensions, click the link for Xdebug for Chrome and install Xdebug Helper.
Youtube: Step Into Debugging with PhpStorm by Gary Hockin, 58 min video on Debugging.
How to Debug using Xdebug and PHPStorm from a Remote Server
PHPStorm has an inspection to set strict mode.
Strict types declaration setting can be found under Type compatibility in the Inspections pane of the Preferences window.
Or double shift search for Missing Strict types declaration tick the inspection.
To run the inspection against the whole project (code base): CTRL + ALT + SHIFT + I or double shift search for run inspection by name. Search for missing strict type declaration, Enter for whole project. The inspection will run, click on each file and click Add strict types declaration
Add the Laravel code standard for PHP code sniffer, static analysis for PHPStan and PHPStorm helper.
composer require --dev emielmolenaar/phpcs-laravel
composer require --dev nunomaduro/larastan
composer require --dev barryvdh/laravel-ide-helper
Example script to run phpcs using the phpcs-laravel standard:
phpcs --standard=phpcs-laravel
After updating composer, add the service provider to the providers
array in config/app.php
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
To generate helper files, run the following:
php artisan ide-helper:generate
php artisan ide-helper:models --write
php artisan ide-helper:meta
It is a good idea to add the generated files to .gitignore
echo /.phpstorm.meta.php >> .gitignore
echo /_ide_helper.php >> .gitignore
echo /_ide_helper_models.php >> .gitignore
PHP Static Analysis Tool - discover bugs in your code without running it!
composer require phpstan/phpstan --dev
PHPStan needs a phpstan.neon
file an example can be found here
Example phpstan.neon
includes:
- vendor/nunomaduro/larastan/extension.neon
- vendor/symplify/phpstan-extensions/config/config.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
paths:
- app
- tests
# The level 8 is the highest level
level: 8
checkGenericClassInNonGenericObjectType: false
# Larstan recommendation:
checkMissingIterableValueType: false
# to allow installing with various phpstan versions without reporting old errors here
reportUnmatchedIgnoredErrors: false
ignoreErrors:
# Larstan recommendation:
- '#Unsafe usage of new static#'
# Ignore errors in Laravel's Middleware classes
-
message: '#Method App\\Http\\Middleware\\RedirectIfAuthenticated\:\:handle\(\) has no return typehint specified#'
path: app\Http\Middleware\RedirectIfAuthenticated.php
-
message: '#Method App\\Http\\Middleware\\Authenticate\:\:redirectTo\(\) should return string\|null but return statement is missing#'
path: app\Http\Middleware\Authenticate.php
# buggy
# mixed
# cache buggy
# tests
# iterable
The above includes placeholders (buggy/mixed etc) for ignored files or rules. See the documentation for how to add.
Another phpstan.neon example from Larastan:
includes:
- ./vendor/nunomaduro/larastan/extension.neon
parameters:
paths:
- app
# The level 8 is the highest level
level: 5
ignoreErrors:
- '#Unsafe usage of new static#'
excludes_analyse:
- ./*/*/FileToBeExcluded.php
checkMissingIterableValueType: false
phpstan analyse src tests --level max --error-format checkstyle
Go to Preferences > Tools > External Tools and click + to add a new tool.
phpstan.bat
executable; On Windows path separators must be a \
)Press Cmd/Ctrl + Shift + A (Find Action), search for phpstan, and then hit Enter. It will run phpstan for all files in the project.
You can also create a keyboard shortcut in Preferences > Keymap to run phpstan.
I have also tried setting up PHPStan as a watcher as follows:
It runs PHPStan on every save, but only opens the console when PHPStan detects an error. Not as good as integrated analysis, but a good compromise, until Jetbrains can integrate it.
Easiest way to start using PHP CS Fixer and PHP_CodeSniffer with 0-knowledge
composer require symplify/easy-coding-standard --dev
parameters:
sets:
- 'psr12'
- 'php71'
- 'symplify'
- 'common'
- 'clean-code'
line_ending: "\n"
# 4 spaces
indentation: " "
skip:
Symplify\CodingStandard\Sniffs\Architecture\DuplicatedClassShortNameSniff: null
# Allow snake_case for tests
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff:
- tests/**
# Ignore what is not owned - Laravel's TestCase class does not start with 'Abstract'
Symplify\CodingStandard\Sniffs\Naming\AbstractClassNameSniff:
- tests/TestCase.php
# Ignore what is not owned - Laravel's traits do not end with 'Trait'
Symplify\CodingStandard\Sniffs\Naming\TraitNameSniff:
- tests/**
# Ignore what is not owned - CommentedOutCodeSniff
Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff.Found:
- app/Console/Kernel.php
# Ignore what is not owned - @return \Illuminate\Contracts\Validation\Validator
SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff.ReferenceViaFullyQualifiedName:
- app/Http/Controllers/Auth/RegisterController.php
services:
Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
max_cognitive_complexity: 8
Working example from KnpLabs/DoctrineBehaviors
Example ecs.yaml
parameters:
sets:
- 'psr12'
- 'php70'
- 'php71'
- 'symplify'
- 'common'
- 'clean-code'
skip:
PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: null
Symplify\CodingStandard\Sniffs\ControlStructure\SprintfOverContactSniff: null
Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenStaticFunctionSniff: null
Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff: null
Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenReferenceSniff: null
Symplify\CodingStandard\Sniffs\Architecture\ExplicitExceptionSniff: null
Symplify\CodingStandard\Sniffs\Architecture\DuplicatedClassShortNameSniff: null
# mixed types
SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff: null
# buggy
Symplify\CodingStandard\Fixer\ControlStructure\PregDelimiterFixer: null
PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer:
- "tests/ORM/TimestampableTest.php"
# weird naming
Symplify\CodingStandard\Fixer\Naming\PropertyNameMatchingTypeFixer:
- "src/Model/Geocodable/GeocodablePropertiesTrait.php"
# & bug
- "*Repository.php"
SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff:
- "tests/Fixtures/Entity/SluggableWithoutRegenerateEntity.php"
services:
Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
max_cognitive_complexity: 8
PhpCsFixer\Fixer\ClassNotation\FinalClassFixer: ~
# see single LICENSE.txt file in the root directory
PhpCsFixer\Fixer\Comment\HeaderCommentFixer:
header: ''
PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer:
annotations:
- 'author'
- 'package'
- 'license'
- 'link'
- 'abstract'
# every property should have @var annotation
# SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff: ~
Example from phpdocumentor\reflection-common\easy-coding-standard.neon
includes:
- temp/ecs/config/clean-code.neon
- temp/ecs/config/psr2.neon
- temp/ecs/config/common.neon
parameters:
exclude_checkers:
# from temp/ecs/config/common.neon
- PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
- PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer
- PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer
# from temp/ecs/config/spaces.neon
- PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer
skip:
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff:
- tests/**
EasyCodingStandard can be used as an External Tool
Go to Preferences
> Tools
> External Tools
and click +
to add a new tool.
ecs
(Can be any value)easyCodingStandard
(Can be any value)$ProjectFileDir$/vendor/bin/ecs
(Path to ecs
executable; On Windows path separators must be a \
)check $FilePathRelativeToProjectRoot$
(append --fix
to auto-fix)$ProjectFileDir$
Press Cmd/Ctrl
+ Shift
+ A
(Find Action), search for ecs
, and then hit Enter. It will run ecs
for the current file.
To run ecs
on a directory, right click on a folder in the project browser go to external tools and select ecs
.
You can also create a keyboard shortcut in Preferences > Keymap to run ecs
.
PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
composer require squizlabs/php_codesniffer --dev
Example from phpdocumentor\type-resolver
Example phpcs.xml.dist
<?xml version="1.0"?>
<ruleset name="phpDocumentor">
<description>The coding standard for phpDocumentor.</description>
<file>src</file>
<file>tests/unit</file>
<exclude-pattern>*/tests/unit/Types/ContextFactoryTest.php</exclude-pattern>
<arg value="p"/>
<rule ref="PSR2">
<include-pattern>*\.php</include-pattern>
</rule>
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint.UselessDocComment" />
</rule>
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
<exclude-pattern>*/src/*_.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix">
<exclude-pattern>*/src/*/Abstract*.php</exclude-pattern>
</rule>
<rule ref="Generic.Formatting.SpaceAfterNot">
<properties>
<property name="spacing" value="0" />
</properties>
</rule>
</ruleset>
The PHP Unit Testing framework.
composer require phpunit/phpunit --dev
Example phpunit.xml.dist from Laravel Package Boilerplate, very useful for coverage reports!
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
/build/
to .gitignoreecho /build/ >> .gitignore
Example phpunit.xml from livewire\livewire
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
phpunit.xml from KnpLabs/DoctrineBehaviors (minimalist)
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Knp Doctrine2 Behaviors">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
Follow the link from phpmd.org to download the latest version and save the phpmd.phar
file in an accessible location.
<?xml version="1.0" encoding="UTF-8" ?>
<ruleset
name="ProxyManager rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
<rule ref="rulesets/design.xml">
<!-- eval is needed to generate runtime classes -->
<exclude name="EvalExpression"/>
</rule>
<rule ref="rulesets/naming.xml">
<exclude name="LongVariable"/>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="minimum">40</property>
</properties>
</rule>
</ruleset>
Mess detection rules from nesbot\Carbon
Example phpmd.xml
<?xml version="1.0"?>
<ruleset name="Mess detection rules for Carbon"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Mess detection rules for Carbon
</description>
<rule ref="rulesets/codesize.xml">
<exclude name="CyclomaticComplexity" />
<exclude name="NPathComplexity" />
<exclude name="ExcessiveMethodLength" />
<exclude name="ExcessiveClassLength" />
<exclude name="ExcessivePublicCount" />
<exclude name="TooManyMethods" />
<exclude name="TooManyPublicMethods" />
<exclude name="ExcessiveClassComplexity" />
</rule>
<rule ref="rulesets/cleancode.xml">
<exclude name="BooleanArgumentFlag" />
<exclude name="StaticAccess" />
<exclude name="IfStatementAssignment" />
</rule>
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml">
<exclude name="EvalExpression" />
<exclude name="CouplingBetweenObjects" />
<exclude name="CountInLoopExpression" />
</rule>
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
<properties>
<property name="maximum" value="20" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions" value="ci,id,to,tz" />
</properties>
</rule>
<rule ref="rulesets/unusedcode.xml" />
</ruleset>
1) Download and install the PHP Mess Detector scripts.
To check the PHP Mess Detector installation, switch to the installation directory and run the following command:
phpmd --version
If the tool is available, you will get a message in the following format:
PHPMD version <version>
To have code checked against your own custom coding standard, create it. Store the rules and the ruleset.xml file that points to them in the rulesets root directory.
2) Register the local PHP Mess Detector script in PhpStorm:
a. In the Settings/Preferences dialog Ctrl+Alt+S, navigate to Languages & Frameworks | PHP | Quality Tools.
b. On the Quality Tools page that opens, expand the Mess Detector area and click the Browse button next to the Configuration list.
c. In the PHP Mess Detector dialog that opens, specify the location of the phpmd.bat
or phpmd
PHP Mess Detector executable in the PHP Mess Detector path field. Type the path manually or click the Browse button and select the relevant folder in the dialog that opens.
To check that the specified path to phpmd.bat
or phpmd
ensures interaction between PhpStorm and PHP Mess Detector, that is, the tool can be launched from PhpStorm and PhpStorm will receive problem reports from it, click the Validate button. This validation is equal to running the phpmd --version
command. If validation passes successfully, PhpStorm displays the information on the detected PHP Mess Detector version.
In the Settings/Preferences dialog Ctrl+Alt+S, navigate to Languages & Frameworks | PHP | Quality Tools.
On the Quality Tools page that opens, expand the Mess Detector area and click the ... (Browse button) next to the Configuration list. The PHP Mess Detector dialog opens showing the list of all the configured PHP Mess Detector scripts in the left-hand pane, one of them is of the type Local and others are named after the PHP interpreters with which the scripts are associated. Click the Add button on the toolbar.
In the PHP Mess Detector by Remote Interpreter dialog that opens, choose the remote PHP interpreter to use the associated script from. If the list does not contain a relevant interpreter, click the Browse button and configure a remote interpreter in the CLI Interpreters dialog as described in Configuring Remote PHP Interpreters.
When you click OK, PhpStorm brings you back to the PHP Mess Detector dialog where the new PHP Mess Detector configuration is added to the list and the right-hand pane shows the chosen remote PHP interpreter, the path to the PHP Mess Detector associated with it, and the advanced PHP Mess Detector options.
A static analysis tool for finding errors in PHP applications https://psalm.dev
Install via Composer:
composer require --dev vimeo/psalm
Add a config:
./vendor/bin/psalm --init
Then run Psalm:
./vendor/bin/psalm
<?xml version="1.0"?>
<psalm
autoloader="psalm-autoload.php"
stopOnFirstError="false"
useDocblockTypes="true"
>
<projectFiles>
<directory name="app" />
<directory name="tests" />
</projectFiles>
<issueHandlers>
<RedundantConditionGivenDocblockType errorLevel="info" />
<UnresolvableInclude errorLevel="info" />
<DuplicateClass errorLevel="info" />
<InvalidOperand errorLevel="info" />
<UndefinedConstant errorLevel="info" />
<MissingReturnType errorLevel="info" />
<InvalidReturnType errorLevel="info" />
</issueHandlers>
</psalm>
Instant Upgrades and Instant Refactoring of any PHP 5.3+ code https://getrector.org
composer require rector/rector --dev
parameters:
sets:
- 'code-quality'
- 'php71'
- 'php72'
- 'php73'
php_version_features: '7.2' # your version is 7.3
paths:
- 'src'
- 'tests'
parameters:
paths:
- "src"
- "tests"
sets:
- 'dead-code'
- 'code-quality'
- 'coding-style'
- 'nette-utils-code-quality'
exclude_rectors:
- 'Rector\DeadCode\Rector\Class_\RemoveUnusedDoctrineEntityMethodAndPropertyRector'
- 'Rector\SOLID\Rector\ClassMethod\UseInterfaceOverImplementationInConstructorRector'
exclude_paths:
- 'src/Model/Translatable/TranslatableMethodsTrait.php'
Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness. https://github.com/phan/phan/wiki
composer require phan/phan