{"id":376796,"date":"2023-05-10T09:57:43","date_gmt":"2023-05-10T09:57:43","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=376796"},"modified":"2024-04-17T13:10:18","modified_gmt":"2024-04-17T13:10:18","slug":"how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/","title":{"rendered":"How to configure Basic PHPCS, WPCS &amp; WCCS for WooCommerce projects"},"content":{"rendered":"\n<p>If you&#8217;re developing a WooCommerce project, it&#8217;s important to ensure that your code follows coding standards and best practices. <\/p>\n\n\n\n<p>This not only helps you maintain a consistent codebase, but it also ensures that your code is secure, maintainable, and easy to understand.<\/p>\n\n\n\n<p>To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding Standard (WPCS) and WooCommerce Code Standards (WCCS) to ensure that your code adheres to the recommended coding standards.<\/p>\n\n\n\n<p>In this blog, we will guide you through the process of configuring PHPCS, WPCS, and WCCS for your WooCommerce project and it would also be helpful in case of <a href=\"https:\/\/webkul.com\/woocommerce-development\/\">WooCommerce Development Services<\/a>.<\/p>\n\n\n\n<p>If you require expert assistance or want to develop custom unique functionality,<a href=\"https:\/\/webkul.com\/hire-woocommerce-developers\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u00a0hire WooCommerce Developers<\/a>\u00a0for your project.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install PHPCS<\/h2>\n\n\n\n<p>The first step is to install PHPCS globally on your system using Composer. This will enable you to use PHPCS from the command line. You can do this by running the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">composer global require &quot;squizlabs\/php_codesniffer=*&quot;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2 : Installing WordPress Coding Standards as a dependency<\/h2>\n\n\n\n<p>Standards can be installed with the&nbsp;<a href=\"https:\/\/getcomposer.org\/\">Composer<\/a>&nbsp;dependency manager:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">composer create-project wp-coding-standards\/wpcs --no-dev<\/pre>\n\n\n\n<p>Running this command will:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install WordPress standards into&nbsp;<code>wpcs<\/code>&nbsp;directory.<\/li>\n\n\n\n<li>Install PHP_CodeSniffer.<\/li>\n\n\n\n<li>Register WordPress standards in PHP_CodeSniffer configuration.<\/li>\n\n\n\n<li>Make&nbsp;<code>phpcs<\/code>&nbsp;command available from&nbsp;<code>wpcs\/vendor\/bin<\/code>.<\/li>\n<\/ol>\n\n\n\n<p>For the convenience of using&nbsp;<code>phpcs<\/code>&nbsp;as a global command, you may want to add the path to the&nbsp;<code>wpcs\/vendor\/bin<\/code>&nbsp;directory to a&nbsp;<code>PATH<\/code>&nbsp;environment variable for your operating system<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Set up the Coding Standards<\/h2>\n\n\n\n<p>Once you have installed PHPCS, WPCS, and WCCS, you need to set up the  WooCommerce and  WordPress Coding Standards (WPCS) as a coding standard for PHPCS. You can do this by running the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">phpcs --config-set installed_paths \/path\/to\/wp-coding-standards\/wpcs,\/path\/to\/woocommerce\/woocommerce-coding-standards<\/pre>\n\n\n\n<p>This command sets up the WPCS as a coding standard for PHPCS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Create a PHPCS Configuration File<\/h2>\n\n\n\n<p>The next step is to create a PHPCS configuration file (phpcs.xml or phpcs.xml.dist) in the root of your WooCommerce project. This configuration file sets up the WooCommerce and WordPress coding standards as rules for your project.<\/p>\n\n\n\n<p> Here is an example configuration file that uses the WooCommerce and WordPress Coding Standards:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;ruleset name=&quot;WooCommerce Project&quot;&gt;\n    &lt;description&gt;Custom coding standard for WooCommerce project&lt;\/description&gt;\n    &lt;arg name=&quot;basepath&quot; value=&quot;.&quot;\/&gt;\n    &lt;file&gt;.&lt;\/file&gt;\n    &lt;rule ref=&quot;WordPress-WP-Theme&quot;\/&gt;\n    &lt;rule ref=&quot;WooCommerce&quot;\/&gt;\n&lt;\/ruleset&gt;<\/pre>\n\n\n\n<p>The command &#8220;phpcs -i&#8221; is used to check the installed coding standards in PHP CodeSniffer. PHP CodeSniffer is a tool that helps to enforce coding standards in PHP code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">phpcs -i<\/pre>\n\n\n\n<p>When you run &#8220;phpcs -i&#8221; in the command line, it will display a list of installed coding standards available for use. Each coding standard represents a set of rules and guidelines for writing PHP code.<\/p>\n\n\n\n<p>Here&#8217;s an example output of the &#8220;phpcs -i&#8221; command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">The installed coding standards are MyStandard, PSR1, PSR2, Squiz, Zend.<\/pre>\n\n\n\n<p>This output indicates that you have several coding standards installed, including &#8220;MyStandard,&#8221; &#8220;PSR1,&#8221; &#8220;PSR2,&#8221; &#8220;Squiz,&#8221; and &#8220;Zend.&#8221; These coding standards can be used to check the PHP code against their respective rulesets.<\/p>\n\n\n\n<p>Note that the actual output may vary depending on the specific installation and configuration of PHP CodeSniffer on your system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Here is the extension you can use in your code editor for phpcs<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"954\" height=\"704\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png\" alt=\"phpcs\" class=\"wp-image-379157\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png 954w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11-300x221.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11-250x184.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11-768x567.png 768w\" sizes=\"(max-width: 954px) 100vw, 954px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Integrate PHPCS with Your Text Editor or IDE<\/h2>\n\n\n\n<p>Finally, you can integrate PHPCS with your text editor or IDE to get real-time feedback on coding standards violations as you write code. Most modern text editors and IDEs have plugins or extensions that can be used to integrate PHPCS.<\/p>\n\n\n\n<p>In conclusion, using PHPCS along with the WooCommerce and <a href=\"https:\/\/developer.wordpress.org\/coding-standards\/wordpress-coding-standards\/\">WordPress Coding Standards<\/a> (WPCS) can help you maintain a consistent codebase, ensure that your code is secure, maintainable, and easy to understand.<\/p>\n\n\n\n<p>By following the steps outlined in this blog, you can easily configure PHPCS, WPCS, and WCCS for your WooCommerce project<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to set path in VS  Studio Code Editor  manually <\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open VSCode and navigate to the settings by clicking on the gear icon in the bottom left corner and selecting &#8220;Settings&#8221; from the dropdown menu. Alternatively, you can use the keyboard shortcut <code><strong>Ctrl + ,<\/strong><\/code> (control + comma)  (<code><strong>Cmd + ,<\/strong><\/code> on macOS) to open the settings directly.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"651\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/settingjson-1-1200x651.png\" alt=\"settingjson-1\" class=\"wp-image-383208\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/settingjson-1-1200x651.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/settingjson-1-300x163.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/settingjson-1-250x136.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/settingjson-1-768x417.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/settingjson-1.png 1296w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>    2. In the settings panel, click on the &#8220;Extensions&#8221; icon on the left sidebar and search for &#8220;PHP&#8221; in the search bar. Select the &#8220;PHP&#8221; extension by Microsoft from the search results.<\/p>\n\n\n\n<p>   3. Scroll down until you find the &#8220;PHP \u203a Executable Path&#8221; setting. Click on the &#8220;Edit in settings.json&#8221; link to open the JSON configuration file for the PHP extension.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"634\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/visibleeditjson-1200x634.png\" alt=\"visibleeditjson\" class=\"wp-image-383205\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/visibleeditjson-1200x634.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/visibleeditjson-300x158.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/visibleeditjson-250x132.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/visibleeditjson-768x406.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/visibleeditjson.png 1289w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p> 4. In the <code>settings.json<\/code> file, you can specify the path to the PHP CodeSniffer executable (phpcs). Add the following line to the JSON object:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&quot;php.executablePath&quot;: &quot;\/path\/to\/phpcs&quot;<\/pre>\n\n\n\n<p>5. Replace <code>\/path\/to\/phpcs<\/code> with the actual path to the <code>phpcs<\/code> executable on your system. Make sure to provide the correct path according to your operating system (Windows, macOS, or Linux).<\/p>\n\n\n\n<p>Save the <code>settings.json<\/code> file, and the path to PHP CodeSniffer should now be configured in VSCode.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to generate PHPCS xml file using command terminal <\/h2>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">phpcs --standard= { path of the core phpcs.xml file containing ruleset } --error-severity=1 --warning-severity=2 --report-source --report-xml={path where you want to generate file containing the errors and warning phpcs xml } --ignore-annotations --extensions=php,html {path of the plugin\/module you want to be checked}<\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>This command tells PHPCS to use the &#8220;xml&#8221; coding standard and redirects the output to a file named &#8220;phpcs.xml&#8221;. You can replace &#8220;xml&#8221; with the coding standard of your choice.<\/li>\n\n\n\n<li>After executing the command, PHPCS will scan the PHP files in the current directory and generate an XML report based on the specified coding standard. The report will be saving in the &#8220;phpcs.xml&#8221;  or the name provided for that file.<\/li>\n<\/ol>\n\n\n\n<p>You can then open the generated XML file using a text editor or XML viewer to review the PHPCS results and coding standards violations.<\/p>\n\n\n\n<p>Note: Make sure that you have appropriate permissions in the directory where you want to create the XML file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Types of warning and errors detected through phpcs :<\/h2>\n\n\n\n<p>PHPCS (PHP CodeSniffer) identifies various types of errors and warnings in PHP code based on the defined coding standards. Here are some common error and warning types reported by PHPCS:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Errors:\n<ul class=\"wp-block-list\">\n<li>Coding Standards Violations: PHPCS checks for violations of coding standards, such as indentation, naming conventions, and spacing rules.<\/li>\n\n\n\n<li>Syntax Errors: PHPCS can detect syntax errors in PHP code, such as missing semicolons, mismatched parentheses, or invalid statements.<\/li>\n\n\n\n<li>Undefined Variables: PHPCS will  stop identifying  the use of variables  not defined within the code.<\/li>\n\n\n\n<li>Undefined Functions\/Methods: PHPCS can detect calls to functions or methods that are not defined or not within the codebase.<\/li>\n\n\n\n<li>Deprecated Functions\/Methods: PHPCS can identify the usage of deprecated functions or methods.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Warnings:\n<ul class=\"wp-block-list\">\n<li>Potential Bugs: PHPCS can flag potential bugs in the code, such as unused variables or unreachable code blocks.<\/li>\n\n\n\n<li>Deprecated Features: PHPCS can warn about the usage of deprecated features in PHP versions.<\/li>\n\n\n\n<li>Code Quality Issues: PHPCS can detect code quality issues, such as long lines of code, excessive nesting, or complex expressions.<\/li>\n\n\n\n<li>Performance Considerations: PHPCS can provide warnings about code constructs that may have performance implications, such as inefficient loops or excessive function calls.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p> Different coding standards may have different rules and guidelines, resulting in varying error and warning messages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> We are listing the set of errors  of PHPCS and their solution<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1)Yoda Condition<\/h3>\n\n\n\n<p>Yoda condition, also known as &#8220;Yoda notation,&#8221; is a programming style where the order of operands in a conditional statement is reversed to check for type and value in an equality conditional expression<\/p>\n\n\n\n<p>In a typical conditional statement, the order of operands is as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">if ($variable == 5) {\n    \/\/ Code block\n}<\/pre>\n\n\n\n<p>In Yoda condition style, reversing the order of operands, like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">if (5 === $variable) {\n    \/\/ Code block\n}<\/pre>\n\n\n\n<p>The notable difference is that the constant value or literal is placed on the left side of the comparison operator (e.g., <code>==<\/code>), while the variable being tested is on the right side.<\/p>\n\n\n\n<p>The main benefit of using Yoda condition is to prevent accidental assignment instead of comparison and also checks the type . In some programming languages, a single equals sign (<code>=<\/code>) is used for assignment, while a double equals sign (<code>==<\/code>) or triple equals sign (<code>===<\/code>) is used for comparison and type check. <\/p>\n\n\n\n<p>Accidentally using a single equals sign in a conditional statement can lead to a logic error, as it assigns a value instead of performing a comparison. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2)Nonce Verification<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;error line=&quot;225&quot; column=&quot;39&quot; source=&quot;WordPress.Security.NonceVerification.Missing&quot; severity=&quot;5&quot; fixable=&quot;0&quot;&gt;Processing form data without nonce verification.&lt;\/error&gt;<\/pre>\n\n\n\n<p>The PHPCS (PHP CodeSniffer) issue you mentioned, &#8220;Processing form data without nonce verification,&#8221; refers to a potential security vulnerability in PHP code that handles form submissions. <\/p>\n\n\n\n<p>Nonce verification is a security measure commonly used to protect against Cross-Site Request Forgery (CSRF) attacks.<\/p>\n\n\n\n<p>To solve the issue of processing form data without nonce verification in WordPress, you can follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Generate and Include Nonce in Forms:\n<ul class=\"wp-block-list\">\n<li>When rendering your HTML forms in WordPress, you can make use of the <code>wp_nonce_field()<\/code> function to generate and include a nonce field in the form.<\/li>\n\n\n\n<li>Use the <code>wp_create_nonce()<\/code> function to generate a secure nonce value.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php wp_nonce_field( &#039;my_form_action&#039;, &#039;my_form_nonce&#039; ); ?&gt;<\/pre>\n\n\n\n<p>2 ) Validate Nonce on Form Submission:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can use the <code>wp_verify_nonce()<\/code> function to check if the nonce is valid.<\/li>\n\n\n\n<li>If the nonce is valid, proceed with processing the form data or it rejects the form.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\">if ( isset( $_POST&#091;&#039;my_form_nonce&#039;] ) &amp;&amp; wp_verify_nonce( $_POST&#091;&#039;my_form_nonce&#039;], &#039;my_form_action&#039; ) ) {\n    \/\/ Nonce verification passed, process the form data\n    \/\/ ...\n} else {\n    \/\/ Nonce verification failed, reject the form submission\n    \/\/ ...\n}<\/pre>\n\n\n\n<p>WordPress provides built-in functions that handle the creation and verification of nonces, making it easier to implement nonce verification in your WordPress forms.<\/p>\n\n\n\n<p>Make sure to replace <code>'my_form_action'<\/code> with a unique identifier for your form. This identifier helps ensure that the nonce is specific to your form and cannot be reused by other forms.<\/p>\n\n\n\n<p>By incorporating these steps into your WordPress form processing code, you can ensure that form submissions are validated using nonces, providing protection against CSRF attacks.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Brief introduction of  elements regarding phpcs xml file<\/h2>\n\n\n\n<p>The xml file is written in XML (eXtensible Markup Language) format and contains various configuration settings for PHPCS. Here are some of the common elements and their purposes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>&lt;ruleset&gt;<\/strong><\/code>: This is the root element of the .xml file and contains all other elements. It defines the coding standards and rules to be applied.<\/li>\n\n\n\n<li><code><strong>&lt;rule&gt;<\/strong><\/code>: This element represents an individual coding rule or standard. It can have attributes such as <code>ref<\/code>, which specifies the rule code or identifier, and <code>severity<\/code>, which defines the level of importance for that rule (e.g., error, warning, or notice).<\/li>\n\n\n\n<li><code><strong>&lt;exclude-pattern&gt;<\/strong><\/code>: This element allows you to exclude specific file patterns or directories from being analyzed by PHPCS. It can be useful if you want to skip certain files or directories that are not relevant to the coding standards.<\/li>\n\n\n\n<li><code><strong>&lt;arg&gt;<\/strong><\/code>: This element is used to provide arguments or options for PHPCS. It can be used to customize the behavior of specific rules or to pass additional configuration parameters to PHPCS.<\/li>\n\n\n\n<li><code><strong>&lt;config&gt;<\/strong><\/code>: This element is used to set global configuration options for PHPCS. It can include settings like the PHP version, tab width, and line ending preferences.<\/li>\n\n\n\n<li><code><strong>&lt;file&gt;<\/strong><\/code>: This element is currently allowing you to define specific file or directory paths to be checked by PHPCS. It can be useful if you want to analyze only a subset of files or directories<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;!-- Exclude paths --&gt;\n\t&lt;exclude-pattern&gt;tests\/&lt;\/exclude-pattern&gt;\n\t&lt;exclude-pattern&gt;woo-includes\/woo-functions.php&lt;\/exclude-pattern&gt;\n\t&lt;exclude-pattern&gt;woo-includes\/class-wc-dependencies.php&lt;\/exclude-pattern&gt;\n\t&lt;exclude-pattern&gt;*\/node_modules\/*&lt;\/exclude-pattern&gt;\n\t&lt;exclude-pattern&gt;*\/vendor\/*&lt;\/exclude-pattern&gt;<\/pre>\n\n\n\n<p>PHPCS won&#8217;t Analyze these directory or files you have mentioned here in these tags like node_modules and vendor !  isn&#8217;t it interesting  ?<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;!-- Configs --&gt;\n\t&lt;config name=&quot;minimum_supported_wp_version&quot; value=&quot;5.0&quot; \/&gt;\n\t&lt;config name=&quot;testVersion&quot; value=&quot;6.2&quot; \/&gt;\n\t&lt;config name=&quot;text_domain&quot; value=&quot;wkpos-addon&quot;\/&gt;<\/pre>\n\n\n\n<p>Now, you can see in above code , we have used config tag  for setting PHPCS global configuration options for text domain , wp_version and php version .Now, these options will be setting  globally for PHPCS .<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;!-- WordPress Rules --&gt;\n\t&lt;rule ref=&quot;WordPress-Core&quot;\/&gt;\n\t&lt;rule ref=&quot;WordPress.CodeAnalysis.EmptyStatement&quot;\/&gt;\n\n\t&lt;rule ref=&quot;WordPress-Docs&quot;\/&gt;\n\t&lt;rule ref=&quot;WordPress-Extra&quot;&gt;\n\t\t&lt;exclude name=&quot;WordPress.WP.TimezoneChange.timezone_change_date_default_timezone_set&quot;\/&gt;\n\t\t&lt;exclude name=&quot;Squiz.Commenting.FileComment.SpacingAfterComment&quot; \/&gt;\n\t&lt;\/rule&gt;\n\n\t&lt;rule ref=&quot;WordPressVIPMinimum&quot;\/&gt;\n\t&lt;rule ref=&quot;WordPress-VIP-Go&quot;\/&gt;\n\t&lt;rule ref=&quot;WordPress.WP.I18n&quot;\/&gt;\n\n\t&lt;!-- WooCommerce Rules --&gt;\n\t&lt;rule ref=&quot;WooCommerce&quot;\/&gt;\n\t&lt;rule ref=&quot;WooCommerce-Core&quot;\/&gt;\n\n\t&lt;!-- Covers rule: Use single and double quotes when appropriate.\n\t\t If you&#039;re not evaluating anything in the string, use single quotes. --&gt;\n\t&lt;rule ref=&quot;Squiz.Strings.DoubleQuoteUsage.NotRequired&quot;\/&gt;<\/pre>\n\n\n\n<p>You can see above we have defined certain set of rule that may be related to individual coding rule or standard<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>This Standardization improves code collaboration, readability, and maintainability. By automatically identifying violations, PHPCS saves developers time and effort in manual code reviews in <a href=\"https:\/\/store.webkul.com\/woocommerce-plugins.html\">WooCommerce plugins<\/a>, leading to increased productivity and reduced bugs.<\/p>\n\n\n\n<p>For the purpose ,PHPCS offers extensibility through the creation of custom rules and sniffs. <\/p>\n\n\n\n<p>This allows developers to tailor the tool to their specific project requirements and coding conventions, compared  enhancing code quality and ensuring adherence to project-specific guidelines.<\/p>\n\n\n\n<p> PHPCS is a robust and flexible tool that promotes code quality, consistency, and adherence to coding standards in PHP development.<\/p>\n\n\n\n<p>By integrating it into the development process, developers can enhance collaboration, reduce technical debt, and produce cleaner, more maintainable code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Support<\/h2>\n\n\n\n<p>For any technical assistance kindly\u00a0<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" target=\"_blank\" rel=\"noreferrer noopener\">raise\u00a0a ticket<\/a>\u00a0or\u00a0reach\u00a0us by email at\u00a0support@webkul.com. Thanks for Your Time! Have a Good Day!<\/p>\n\n\n\n<p>Also, discover various solutions to add more features and enhance your online store by visiting the\u00a0<a href=\"https:\/\/store.webkul.com\/woocommerce-plugins.html\" target=\"_blank\" rel=\"noreferrer noopener\">WooCommerce plugins<\/a>.<\/p>\n\n\n\n<p><strong><mark class=\"has-inline-color has-black-color\">Thanks for Your Time! Have a Good Day!<\/mark><\/strong> \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re developing a WooCommerce project, it&#8217;s important to ensure that your code follows coding standards and best practices. This not only helps you maintain a consistent codebase, but it also ensures that your code is secure, maintainable, and easy to understand. To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding <a href=\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":499,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1773],"tags":[14089,14091,1468,1511],"class_list":["post-376796","post","type-post","status-publish","format-standard","hentry","category-woocommerce","tag-phpcs","tag-wccs","tag-woocommerce","tag-woocommerce-plugins"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Webkul Blog - WooCommerce<\/title>\n<meta name=\"description\" content=\"To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding Standards (WPCS) and WooCommerce Code Standards (WCCS) .\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Webkul Blog - WooCommerce\" \/>\n<meta property=\"og:description\" content=\"To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding Standards (WPCS) and WooCommerce Code Standards (WCCS) .\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-10T09:57:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-17T13:10:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png\" \/>\n<meta name=\"author\" content=\"Akash Tiwari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Akash Tiwari\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\"},\"author\":{\"name\":\"Akash Tiwari\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/aff0334749df4bd88d8f598309908b0c\"},\"headline\":\"How to configure Basic PHPCS, WPCS &amp; WCCS for WooCommerce projects\",\"datePublished\":\"2023-05-10T09:57:43+00:00\",\"dateModified\":\"2024-04-17T13:10:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\"},\"wordCount\":1969,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png\",\"keywords\":[\"phpcs\",\"wccs\",\"WooCommerce\",\"woocommerce plugins\"],\"articleSection\":[\"WooCommerce\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\",\"name\":\"Webkul Blog - WooCommerce\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png\",\"datePublished\":\"2023-05-10T09:57:43+00:00\",\"dateModified\":\"2024-04-17T13:10:18+00:00\",\"description\":\"To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding Standards (WPCS) and WooCommerce Code Standards (WCCS) .\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png\",\"width\":954,\"height\":704,\"caption\":\"phpcs11\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to configure Basic PHPCS, WPCS &amp; WCCS for WooCommerce projects\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/aff0334749df4bd88d8f598309908b0c\",\"name\":\"Akash Tiwari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/743f2e3142859044579e2b78186b7793060abeba5b200d44f9e01ead72e91956?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/743f2e3142859044579e2b78186b7793060abeba5b200d44f9e01ead72e91956?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Akash Tiwari\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/akashtiwari-wp643\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Webkul Blog - WooCommerce","description":"To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding Standards (WPCS) and WooCommerce Code Standards (WCCS) .","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/","og_locale":"en_US","og_type":"article","og_title":"Webkul Blog - WooCommerce","og_description":"To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding Standards (WPCS) and WooCommerce Code Standards (WCCS) .","og_url":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-05-10T09:57:43+00:00","article_modified_time":"2024-04-17T13:10:18+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png","type":"","width":"","height":""}],"author":"Akash Tiwari","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Akash Tiwari","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/"},"author":{"name":"Akash Tiwari","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/aff0334749df4bd88d8f598309908b0c"},"headline":"How to configure Basic PHPCS, WPCS &amp; WCCS for WooCommerce projects","datePublished":"2023-05-10T09:57:43+00:00","dateModified":"2024-04-17T13:10:18+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/"},"wordCount":1969,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png","keywords":["phpcs","wccs","WooCommerce","woocommerce plugins"],"articleSection":["WooCommerce"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/","url":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/","name":"Webkul Blog - WooCommerce","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png","datePublished":"2023-05-10T09:57:43+00:00","dateModified":"2024-04-17T13:10:18+00:00","description":"To achieve this, you can use PHP_CodeSniffer (PHPCS) along with the WordPress Coding Standards (WPCS) and WooCommerce Code Standards (WCCS) .","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/phpcs11.png","width":954,"height":704,"caption":"phpcs11"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-configure-phpcs-wpcs-wccs-for-woocommerce-projects\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to configure Basic PHPCS, WPCS &amp; WCCS for WooCommerce projects"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/aff0334749df4bd88d8f598309908b0c","name":"Akash Tiwari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/743f2e3142859044579e2b78186b7793060abeba5b200d44f9e01ead72e91956?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/743f2e3142859044579e2b78186b7793060abeba5b200d44f9e01ead72e91956?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Akash Tiwari"},"url":"https:\/\/webkul.com\/blog\/author\/akashtiwari-wp643\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/376796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/499"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=376796"}],"version-history":[{"count":46,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/376796\/revisions"}],"predecessor-version":[{"id":434683,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/376796\/revisions\/434683"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=376796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=376796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=376796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}