Brew install php cs fixer

Install command:

brew install php-cs-fixer

Also known as: php-cs-fixer@3

Tool to automatically fix PHP coding standards issues

https://cs.symfony.com/

License: MIT

Formula JSON API: /api/formula/php-cs-fixer.json

Bottle JSON API: /api/bottle/php-cs-fixer.json

Formula code: php-cs-fixer.rb on GitHub

Bottle (binary package) installation support provided.

Current versions:

Other versions:

php-cs-fixer@2 2.19.3 Tool to automatically fix PHP coding standards issues

Depends on:

php 8.1.11 General-purpose scripting language

Analytics (macOS):

Installs (30 days)
php-cs-fixer 2,742
Installs on Request (30 days)
php-cs-fixer 2,738
Build Errors (30 days)
php-cs-fixer 0
Installs (90 days)
php-cs-fixer 9,939
Installs on Request (90 days)
php-cs-fixer 9,923
Installs (365 days)
php-cs-fixer 30,462
Installs on Request (365 days)
php-cs-fixer 30,373

Analytics (Linux):

Installs (30 days)
php-cs-fixer 28
Installs on Request (30 days)
php-cs-fixer 28
Build Errors (30 days)
php-cs-fixer 0
Installs (90 days)
php-cs-fixer 115
Installs on Request (90 days)
php-cs-fixer 115
Installs (365 days)
php-cs-fixer 645
Installs on Request (365 days)
php-cs-fixer 644

Install command:

brew install php-cs-fixer@2

Tool to automatically fix PHP coding standards issues

https://cs.symfony.com/

License: MIT

Formula JSON API: /api/formula/

Bottle JSON API: /api/bottle/

Formula code: on GitHub

Bottle (binary package) installation support provided.

Current versions:

Revision: 1

Keg-only

Depends on:

8.0.24 General-purpose scripting language

Analytics (macOS):

Installs (30 days)
php-cs-fixer@2 27
Installs on Request (30 days)
php-cs-fixer@2 27
Build Errors (30 days)
php-cs-fixer@2 0
Installs (90 days)
php-cs-fixer@2 99
Installs on Request (90 days)
php-cs-fixer@2 99
Installs (365 days)
php-cs-fixer@2 783
Installs on Request (365 days)
php-cs-fixer@2 780

Analytics (Linux):

Installs (30 days)
php-cs-fixer@2 1
Installs on Request (30 days)
php-cs-fixer@2 1
Build Errors (30 days)
php-cs-fixer@2 0
Installs (90 days)
php-cs-fixer@2 2
Installs on Request (90 days)
php-cs-fixer@2 2
Installs (365 days)
php-cs-fixer@2 8
Installs on Request (365 days)
php-cs-fixer@2 8

To set up php linting, you’ll want to install this PHP CodeSniffer repo and configure with this WordPress Coding Standards repo: . There are a number of ways to do this, whether direct download, Composer, Homebrew, Pear, etc. The following is what works for me on MacOS using Homebrew:

In a terminal window on your Mac, start by updating your Homebrew.

brew doctor

Then install the Code Sniffer:

brew install php-code-sniffer

After that is done, you should be able to check that things installed correctly.

phpcs -i

will show you the Standards that you have installed. You will probably see something like:

The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend

Once we see the installed standards, we can then download the WordPress Coding Standards. I usually just clone the repo to a directory in the root of my computer, but you can put it anywhere you like, assuming you’ll remember the path.

git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git ~/wpcs

After that is downloaded, you’ll need to tell phpcs where to find the new coding standards. Assuming you downloaded the repo to the folder above, you can enter:

phpcs --config-set installed_paths ~/wpcs

Otherwise, you will need to point to whereever you intalled your WordPress Coding Standards.

Now that you've told phpcs where to find the xml files for WordPress Coding Standards, you can check to see that they are properly found:

phpcs -i

and now you should see:

The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, WordPress, WordPress-Extra, WordPress-Docs and WordPress-Core

composer global require "squizlabs/php_codesniffer=*"
phpcs --version

To lint the php files in a folder

phpcbf --extensions=php --standard=WordPress -v ./my-plugin-folder

My VSCode Settings

{
    "phpcs.enable": true,
    "phpcs.standard": "WordPress",
    "phpcbf.onsave": true,
    "phpcbf.standard": "WordPress",
    "window.zoomLevel": 1,
    "workbench.colorTheme": "Default Light+",
    "editor.fontSize": 13,
    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "[php]": {
        "editor.defaultFormatter": "persoderlind.vscode-phpcbf"
    },
    "javascript.updateImportsOnFileMove.enabled": "always",
    "[javascriptreact]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "git.autofetch": true,
    "editor.insertSpaces": false,
    "editor.formatOnPaste": true,
    "editor.tabSize": 4,
    "editor.detectIndentation": false,
    "editor.quickSuggestions": true,
    "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "phpcs.executablePath": "/Users/pbarthma/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs",
    "phpcbf.executablePath": "/Users/pbarthma/.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf",
    "phpcs.showSources": true,
    "git.confirmSync": false,
    "remote.SSH.showLoginTerminal": true,
    "editor.defaultFormatter": "valeryanm.vscode-phpsab",
    "editor.codeActionsOnSave": null,
    "phpsab.standard": "valeryanm.vscode-phpsab",
    "phpsab.allowedAutoRulesets": [
    
        ".phpcs.xml",
        ".phpcs.xml.dist",
        "phpcs.xml",
        "phpcs.xml.dist",
        "phpcs.ruleset.xml",
        "ruleset.xml"
    ],
}

My SublimeText 3 PHPCS Settings

{
    // Plugin settings

    // Turn the debug output on/off
    "show_debug": false,

    // Which file types (file extensions), do you want the plugin to
    // execute for
    "extensions_to_execute": ["php"],

    // Do we need to blacklist any sub extensions from extensions_to_execute
    // An example would be ["twig.php"]
    "extensions_to_blacklist": [],

    // Execute the sniffer on file save
    "phpcs_execute_on_save": true,

    // Show the error list after save.
    "phpcs_show_errors_on_save": true,

    // Show the errors in the gutter
    "phpcs_show_gutter_marks": true,

    // Show outline for errors
    "phpcs_outline_for_errors": true,

    // Show the errors in the status bar
    "phpcs_show_errors_in_status": true,

    // Show the errors in the quick panel so you can then goto line
    "phpcs_show_quick_panel": true,

    // The path to the php executable.
    // Needed for windows, or anyone who doesn't/can't make phars
    // executable. Avoid setting this if at all possible
    "phpcs_php_prefix_path": "",

    // Options include:
    // - Sniffer
    // - Fixer
    // - MessDetector
    // - CodeBeautifier
    //
    // This will prepend the application with the path to php
    // Needed for windows, or anyone who doesn't/can't make phars
    // executable. Avoid setting this if at all possible
    "phpcs_commands_to_php_prefix": [],

    // What color to stylise the icon
    // https://www.sublimetext.com/docs/3/api_reference.html#sublime.View
    // add_regions
    "phpcs_icon_scope_color": "comment",


    // PHP_CodeSniffer settings

    // Do you want to run the phpcs checker?
    "phpcs_sniffer_run": true,

    // Execute the sniffer on file save
    "phpcs_command_on_save": true,

    // It seems python/sublime cannot always find the phpcs application
    // If empty, then use PATH version of phpcs, else use the set value
    "phpcs_executable_path": "/usr/local/bin/phpcs",

    // Additional arguments you can specify into the application
    //
    // Example:
    // {
    //     "--standard": "PEAR",
    //     "-n"
    // }
    "phpcs_additional_args": {
        "--standard": "WordPress",
        "-n": ""
    },

    // PHP-CS-Fixer settings

    // Fix the issues on save
    "php_cs_fixer_on_save": false,

    // Show the quick panel
    "php_cs_fixer_show_quick_panel": false,

    // Path to where you have the php-cs-fixer installed
    "php_cs_fixer_executable_path": "",

    // Additional arguments you can specify into the application
    "php_cs_fixer_additional_args": {

    },

    // phpcbf settings

    // Fix the issues on save
    "phpcbf_on_save": true,

    // Show the quick panel
    "phpcbf_show_quick_panel": false,

    // Path to where you have the phpcbf installed
    "phpcbf_executable_path": "/usr/local/bin/phpcbf",

    // Additional arguments you can specify into the application
    //
    // Example:
    // {
    //     "--level": "all"
    // }
    "phpcbf_additional_args": {
        "--standard": "WordPress",
        "-n": ""
    },

    // PHP Linter settings

    // Are we going to run php -l over the file?
    "phpcs_linter_run": true,

    // Execute the linter on file save
    "phpcs_linter_command_on_save": true,

    // It seems python/sublime cannot always find the php application
    // If empty, then use PATH version of php, else use the set value
    "phpcs_php_path": "/usr/bin/php",

    // What is the regex for the linter? Has to provide a named match for 'message' and 'line'
    "phpcs_linter_regex": "(?P.*) on line (?P\\d+)",
}

SublimeText 3 Preferences Settings

{
	"color_scheme": "Packages/Theme - Cobalt2/cobalt2.tmTheme",
	"extensions_to_blacklist":
	[
	],
	"extensions_to_execute":
	[
		"php"
	],
	"font_size": 16,
	"ignored_packages":
	[
		"Vintage"
	],
	"phpcbf_additional_args":
	{
		"--standard": "WordPress",
		"-n": ""
	},
	"phpcbf_executable_path": "/usr/local/bin/phpcbf",
	"phpcbf_on_save": true,
	"phpcbf_show_quick_panel": true,
	"phpcs_additional_args":
	{
		"--standard": "WordPress",
		"-n": ""
	},
	"phpcs_command_on_save": true,
	"phpcs_commands_to_php_prefix":
	[
	],
	"phpcs_executable_path": "/usr/local/bin/phpcs",
	"phpcs_execute_on_save": true,
	"phpcs_icon_scope_color": "comment",
	"phpcs_outline_for_errors": false,
	"phpcs_php_prefix_path": "",
	"phpcs_show_errors_in_status": true,
	"phpcs_show_errors_on_save": false,
	"phpcs_show_gutter_marks": true,
	"phpcs_show_quick_panel": true,
	"phpcs_sniffer_run": true,
	"show_debug": true,
	"theme": "Default.sublime-theme"
}

SublimeText 3 Package Control Settings

{
	"bootstrapped": true,
	"in_process_packages":
	[
	],
	"installed_packages":
	[
		"DocBlockr",
		"Package Control",
		"PHP Codebeautifier",
		"Phpcs",
		"SublimeLinter-contrib-php-cs-fixer",
		"SublimeLinter-phpcs",
		"Theme - Cobalt2"
	]
}