In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
VsCode plug-in phpcs installation problems encountered in the implementation process and solutions, I believe that many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
We hope to standardize the coding specification of PHP code in project development, lock php-code-sniffer this plugin, and share the problems encountered during installation and implementation as follows
PHP_CodeSniffer
https://github.com/squizlabs/PHP_CodeSniffer/is a code specification tool used to standardize the writing of class names, comments, parameters, etc. in team development, helping team members form a unified coding style.
There are many ways to install, mac under the following command installation, the most convenient
brew install php-code-sniffer
The requested URL/usr/local/Cellar/php-code-sniffer was not found on this server.
The requested URL/usr/local/Cellar/php-code-sniffer/3.4.1/binlsphpcbf phpcscombiner was not found on this server.
installation path
/Users/name/.composer/vendor/squizlabs/php_codesniffer/
lsphpcbf phpcbf.bat phpcs phpcs.bat
Two installation methods, mac recommended to use brew installation
For other installation methods, please refer to github library [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/)
Enable PHP_CodeSniffer in VsCode
Enabling PHP_CodeSniffer in VsCode requires phpcs plugin to be installed.
phpcs and PHP sniffer
Before using this plugin, you must ensure that phpcs is installed on your system,The preferred method is using [composer](https://getcomposer.org/) for both system-wide and project-wide installations.
That is to say, before using phpcs plug-in in VsCode, you need to install phpcs on the system first. The installation method depends on the composer mode, and you can choose to install it from two latitudes: system level and project level.
If you install plug-ins only in vscode, phpcs is not installed at the system level. receive the following error
phpcs: Request workspace/configuration failed with message: Unable to locate phpcs. Please add phpcs to your global path or use composer dependency manager to install it in your project locally.
system-level global installation composer global require squizlabs/php_codesniffer
Changed current directory to /Users/wmm/.composer
Using version ^3.4 for squizlabs/php_codesniffer
./ composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing squizlabs/php_codesniffer (3.4.0): Downloading (100%)
Writing lock file
Generating autoload files
Project-level installation
The following is VScode's introduction to phpcs plug-ins. For more information, see https://marketplace.visualstudio.com/items? itemName=ikappas.phpcs
Project-wide Installation
The `phpcs` linter can be installed in your project using the Composer Dependency Manager for PHP.
1. Install [composer](https://getcomposer.org/doc/00-intro.md "https://getcomposer.org/doc/00-intro.md").
2. Require `phpcs` package by typing the following at the root of your project in a terminal:
composer require --dev squizlabs/php_codesniffer
Before configuration was complete, another plug-in PHP Sniffer was found. There are two things written in the properties
Runs phpcs to lint PHP code.
Runs phpcbf to format fixable PHP code validation errors.
It is obvious that PHP Sniffer is an encapsulation of phpcs. After verification, it was found that this plugin can be used without using PHP_CodeSniffer.
! [VsCode Plugin Tour-phpcs-Tunan Technology]
If you install both PHP Sniffer and phpcs plugins, but PHP_CodeSniffer is not installed, the following error occurs
phpcs: Unable to locate phpcs. Invalid version string encountered! PHP_CodeSniffer typically uses phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend Usage Standards
1 Method comment parameter, return value three items separated by blank lines
! [phpcs.png]
2 Parameters must have comments, also identify spaces, multiple parameters need to be aligned vertically.
The length of each line of code cannot exceed a certain length.
>Line exceeds 85 characters; contains 98 characters
4 Private methods start with an underscore.
>Private method name " " must be prefixed with an underscore
summary
VsCode for plug-in phpcs installation method introduction, in fact, more PHP_CodeSniffer tool installation introduction, plug-in role is to help the project and PHP_CodeSniffer do association. To experience the perfect phpcs experience, you also need PHP intelligent annotation plug-in, automatically provide comments for methods, and then manually adjust the details.
Code Review is one of the important measures to ensure the code quality of the team, and code specification is an important part of Code Review, and code specification must rely on effective tools, phpcs is such a tool, to promote code cleanliness, efficient development, training engineers for code cleanliness and strict constraints on quality delivery.
After reading the above content, do you master the problems encountered in the installation and execution of VsCode plug-in phpcs and the solutions? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.