it doesn't detect errors like missing semicolons or comas in arrays. there might be more.
Describe the bug
- it doesn't report missing semicolons or comas in array.
- missing semicolon on array says "There must not be more than one property declared per statement, instead of it saying it's missing a coma and a semicolon. (referring to
protected $hidden variable
Code sample
<?php
namespace App;
class User
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name'
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password'
'remember_token',
]
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Custom ruleset
No custom ruleset
To reproduce Steps to reproduce the behavior:
- Create a file called
User.phpwith the code sample above... - Run
phpcs User.php --standard=PSR12
PHPCS output here
$ phpcs User.php --standard=PSR12
FILE: C:\Users\dusme\code\sample\User.php
------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------
23 | ERROR | There must not be more than one property declared per statement
------------------------------------------------------------------------------
Time: 123ms; Memory: 6MB
Expected behavior it should say warnings about missing semicolons and comas
Versions (please complete the following information):
- OS: Windows 11 (2H22)
- PHP: 8.1.11
- PHPCS: 3.7.1
- Standard: PSR12
Additional context
I'm using Sublime Text 4 with package SublimeLinter-phpcs, phpcs
globally installed friendsofphp/php-cs-fixer
it doesn't report missing semicolons or comas in array.
PSR12 contains no rules about array formatting, so the PSR12 ruleset - correctly - does not enforce any.
missing semicolon on array says "There must not be more than one property declared per statement, instead of it saying it's missing a coma and a semicolon. (referring to
protected $hidden variable
If you want to find parse errors, please add the Generic.PHP.Syntax sniff or - better yet - use a dedicated PHP linting tool like PHP Parallel Lint.
It is impossible for PHPCS to account for all type of parse errors a user can make and the scan results will not be reliable when the code contains parse errors.
The reason for the There must not be more than one property declared per statement is that PHP supports multi-property declarations and the missing semi-colon gives the sniff the idea that that's what you are declaring.
class Foo {
public $propA = 10, $propB = 'string';
}
globally installed friendsofphp/php-cs-fixer
CS-Fixer is a completely different tool and has no relation to PHPCS. Use the build-in phpcbf command to use the fixer which comes with PHPCS.