Installing Required Tools on CentOS
Before configuring code inspection in PhpStorm, ensure your CentOS system has the necessary dependencies installed. Start by installing PHP and essential extensions using YUM:
sudo yum install php php-cli php-fpm php-mysql php-xml php-json
Verify PHP installation with php -v. For Java support (required by PhpStorm), install OpenJDK 11 or higher:
sudo yum install openjdk-11-jdk
java -version # Confirm installation
Configuring PhpStorm Basics
After downloading PhpStorm from JetBrains’ website and extracting it to a directory (e.g., /opt/phpstorm), configure the PHP interpreter:
which php).Setting Up Code Inspection Tools
PhpStorm supports multiple tools for enforcing code standards and static analysis. Below are key configurations for popular tools:
PHP Code Sniffer checks code against coding standards like PSR2. Install it globally via Composer:
composer global require "squizlabs/php_codesniffer=*"
Configure PhpStorm to use phpcs:
phpcs executable (typically at ~/.composer/vendor/bin/phpcs).PHPMD detects unused variables, suboptimal code, and other complexity issues. Install it globally:
composer global require "phpmd/phpmd=*"
Configure PhpStorm:
phpmd executable (typically at ~/.composer/vendor/bin/phpmd).For deeper static analysis (e.g., type safety, undefined classes), install PHPStan or Psalm:
composer global require "phpstan/phpstan" # For PHPStan
composer global require "psalm/psalm" # For Psalm
Configure in PhpStorm (Languages & Frameworks → PHP → Code Sniffer) by selecting the tool’s executable and validating the path.
Enabling Real-Time and Manual Inspections
PhpStorm runs inspections by default as you type, highlighting issues with red/yellow underlines. To run manual inspections:
Adjusting Inspection Rules
Customize inspection severity (errors, warnings, hints) via Settings → Editor → Inspections → PHP. Expand categories (e.g., “PHP Syntax”, “Code Smell”) to enable/disable specific rules or change their severity level.
By following these steps, you can set up robust code inspection in PhpStorm on CentOS, ensuring your PHP code adheres to standards and is free from common issues.