Questions tagged [phpcs]

A component of Php Code Sniffer Package, phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard.

Useful links:

203 questions
3
votes
1 answer

PHPCS rule for type hinting

Is there a rule to check all functions for type hinting? /** * Set the part name. * * @param string $name The part name. */ public function setName(string $name) : void { $this->name = $name; } So for example it has to have a type in…
Pascal
  • 2,175
  • 4
  • 39
  • 57
3
votes
1 answer

How to use php-cs-fixer with vim for laravel?

I have installed php-cs-fixer & using with vim plugin https://github.com/stephpy/vim-php-cs-fixer. I am using custom config file from https://github.com/laravel/framework/blob/5.4/.php_cs. But I am having this issue where extra space after @param…
Ganesh
  • 3,128
  • 2
  • 17
  • 27
3
votes
2 answers

Configure CodeSniffer on PhpStorm using Docker

I am developing a project using PhpStorm and I am using Php 7.1 with Docker. I would like to integrate PHP code sniffer in PhpStorm. In PhpStorm I go to Settings|Languages&Frameworks|PHP|CodeSniffer and I try to add a new configuration, I provide as…
marcosh
  • 8,780
  • 5
  • 44
  • 74
3
votes
0 answers

How to properly use phpcs for checking all php files on project directory

I want to perform a check for all php files in my project directory to see if they are compatible with PHP 7. I installed PHPCompatibility as a phpcs standard and I realised that variations such as .class.php, .lib.php .inc.php were skipped using…
natali
  • 125
  • 2
  • 9
3
votes
1 answer

PhpCS exclude sniffs not working

I am running Php 7.0 on my machine but I need to check code that executes in both 7.0 and 5.6. As such, I get a load of Squiz.Commenting.FunctionComment.ScalarTypeHintMissing errors when using the -s flag. I have installed PhpCS via composer for…
myol
  • 8,857
  • 19
  • 82
  • 143
3
votes
2 answers

SublimeLinter: modules phpcs and phpmd not working

in Sublime Text 3 I have installed via the Package Manager following packages: SublimeLinter SublimeLinter-phpmd SublimeLinter-phpcs and few others.. The problem is that neither phpmd or phpcs are working. When opening a php file in ST3 and then…
Alex
  • 4,607
  • 9
  • 61
  • 99
2
votes
0 answers

Is there a CLI tool organizing my PHP imports?

I am already using phpcs/phpcbf for sniffing my code. Unfortunately, I cannot find a tool or a rule for PHPCS which can automatically organize my imports. I know something like this exists for IDE's like PhpStorm, but I want it to make use of it…
Matthias Günter
  • 617
  • 8
  • 24
2
votes
0 answers

How to deal with PHPDoc blocks and print width PHPCS/PHPMD rules?

I'm developing a Laravel application, and I use PHPCS, PHPMD and Prettier. I have a Facade to deal with the invitation system of the app, and the PHPDoc (at the time of writing) looks like this: /** * ... * @method array getValidationRules() …
glaucomorais
  • 317
  • 3
  • 9
2
votes
1 answer

Is there any Customizable Sniff Properties for classes/traits/interfaces?

is there any Customizable Sniff Properties for classes/traits/interfaces to do the followings; not allow a blank line before the first content One blank line after the last content I am expecting a rule for something like this. example Valid…
Safry
  • 191
  • 1
  • 9
2
votes
3 answers

Git Pre-Commit hook for PHPCS is giving me error in Windows for Laravel

I have installed PHPCS from composer.json "require-dev": { "phpstan/phpstan": "^0.12.93", "squizlabs/php_codesniffer": "^3.6" }, I am using laravel 8 so I have added below code for pre-commit file in .git/hooks/pre-commit file: #!/bin/sh #…
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
2
votes
0 answers

Stop curly braces from being dropped onto a new line (enclosure functions)

I have an example code below: $class->doA("something", function () {}) ->doB("something else", function () {}); When I run formatter PHPCS changes my code from above to: $class->doA("something", function () { }) ->doB("something else",…
user10986113
2
votes
1 answer

vscode php development setup php intelephense and phpcs

I want to setup my development environment using vscode. However, I am confused on that would be the difference between intelephense and phpcs. I have the code in Github from my company and it has the .phpcs.xml.dist. I believe this file is for…
2
votes
0 answers

phpcs - How to allow same line braces when promoting constructors in PHP 8

This is my first question on StackOverflow. I'm very happy for that! I would like to know if there's some phpcs configuration that can override the same line braces rule. For example, when using PHP 8 new constructor promotion feature, in some…
thiagobraga
  • 1,519
  • 2
  • 15
  • 29
2
votes
1 answer

How to configure php_codesniffer to force the PHP 7.4 property type declaration?

I'd like to configure my phpcs ruleset so it would force the PHP 7.4 added type declaration for class properties. Currently I'm using the PSR-12 standard ruleset and I want to add there a sniff, which will scan this code: /** @var string…
Jiří Kolda
  • 53
  • 1
  • 8
2
votes
1 answer

vscode-phpcs extension does not work in the editor, but in version control, can I fix it?

I've been trying to get vscode-phpcs extension from ikappas running in VSCode in my project for about 4 days. After ages of back and forth. I noticed, that the extension is scanned open files in the version control. This will also find there the…
jefiedler
  • 21
  • 2