Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 22:52
    jrfnl commented #2387
  • Jan 31 22:41
    valeryan commented #2386
  • Jan 31 22:40
    valeryan commented #2386
  • Jan 31 22:40
    valeryan commented #2386
  • Jan 31 22:17
    gsherwood commented #2387
  • Jan 31 22:14
    gsherwood milestoned #2387
  • Jan 31 22:13
    gsherwood labeled #2386
  • Jan 31 22:13
    gsherwood commented #2386
  • Jan 31 22:05
    gsherwood milestoned #2388
  • Jan 31 22:03
    gsherwood labeled #2394
  • Jan 31 22:02
    gsherwood commented #2394
  • Jan 31 22:02
    gsherwood closed #2394
  • Jan 31 22:02

    gsherwood on master

    Fixed docblocks Because custom… (compare)

  • Jan 31 22:02
    gsherwood milestoned #2394
  • Jan 31 16:50
  • Jan 31 16:00
    SteepDevs starred squizlabs/PHP_CodeSniffer
  • Jan 31 15:22
  • Jan 31 14:39
    sebastiaanluca commented #2304
  • Jan 31 14:38
    sebastiaanluca commented #2304
  • Jan 31 13:09
    rlauenroth starred squizlabs/PHP_CodeSniffer
Greg Sherwood
@gsherwood
@o5 There is no included sniff to enforce array types in docblocks. I've been waiting for the docblock PSR to be completed before attempting to write any more doc-based standards so I have something to build towards.
Petr Bugyík
@o5
@gsherwood thank you for info!
Mponos George
@gmponos

@gsherwood basically for this issue here: squizlabs/PHP_CodeSniffer#2226

but what about this: https://github.com/guzzle/guzzle/pull/2194/files#r232765653

should have mentioned both on chat and not create an issue, I had forgot about the chat..
Greg Sherwood
@gsherwood
@gmponos PSR2 doesn't say anything about empty bodies. You can see a readable version here: https://www.php-fig.org/psr/psr-2/
Alex
@aik099

Hi,

I'm trying to find sniff, that would detect attempt to change function/method parameter value assignment, that isn't passed by reference. Anybody aware of such a sniff?

If not found, then what approach for writing that sniff is better performance-wise, e.g.:

  1. listen for T_FUNCTON token
  2. get parameters of that function, that aren't passed by reference
  3. lookup names of these parameters in function body and T_WHITESPACE (optional) + assignment sniffs after it

?

Example code:

function myFunc($param1, &$param2) {
    echo 'test';
    $param1 = 'bad idea';
}

Thanks.

Greg Sherwood
@gsherwood

@aik099 I'm not aware of a sniff to do this, but you could attempt to check for value assignment using the method you've outlined. The problem you will have is developers using dynamic assignments, like:

function myFunc($param1, &$param2) {
    $var ='param1';
    $$var = 'bad idea';
}

You'll need to decide if you care about that or not. Tracking it is not something I've attempted.

Alex
@aik099
@gsherwood, Thanks, I'll try that. Yeah, I will probably write another sniff to disallow $$variable stuff, because it prevents static code analysis tools from working correctly.
Glen
@glen-84
The File::getMethodParamaters() method now includes a has_body array index in the return value
    TRUE if the method has no body (as with abstract and interface methods) or FALSE otherwise
@gsherwood The method name is spelled incorrectly, and I think those Boolean values are swapped as well.
Juliette
@jrfnl
@glen-84 It actually refers to the wrong method - see squizlabs/PHP_CodeSniffer#2326, though I hadn't noticed the value swopping before, I've updated my PR to fix that too. Thanks!
Glen
@glen-84
:thumbsup:
Glen
@glen-84
@jrfnl Regarding Generic.CodeAnalysis.UnusedFunctionParameter, it's not possible to determine whether the method is overriding a method in the parent class?
Juliette
@jrfnl

@glen-84 No, unfortunately not as that would require the specs of the parent class which PHPCS may or may not have information on.
What I mean by that is, that:

  • The parent class may be in a directory not being scanned (vendor).
  • The specs of a PHP native parent class may have changed between PHP versions and the PHP version which PHPCS is being run is not necessarily the same version on which the application should be able to run.
  • The parent class may be scanned after the child class, meaning that the information is not available yet when the child class is scanned.
  • The parent class may be scanned in a different parallel process from the child class.

Does that explain it well enough ?

Glen
@glen-84
@jrfnl Very well explained, thank you. :slight_smile:
Steven Klein
@steven-klein

Hi, I'm having an issue where include patterns seem to be applying differently between my local environment and Travis CI. Has anyone run into that?

Example: the complexity of third party code makes using an include much easier than exclude patters. The following locally only checks directories that start with foo- or files that start with foo-*. But in Travis it's not being respected.

<rule ref="PSR2">
  <include-pattern>*/foo\-*/*</include-pattern>
  <include-pattern>*/foo\-*\.php</include-pattern>
</rule>
Juliette
@jrfnl
@steven-klein Could it be that your organisation or repo has foo- somewhere in the name ? Try adding an echo of the PATH in Travis to see if the path your repo is cloned to could cause the conflict.
Steven Klein
@steven-klein
@jrfnl That was it. Thanks!
Alex
@aik099
Hi. Is there a way to dynamically disable one of errors/warnings in a sniff based on say function name within what an error/warning is reported?
Alex
@aik099
For example I want to ignore “Squiz.Commenting.FunctionXomment.TypeHintMissing” error/warning when a function in question has predefined name.
Alex
@aik099
I've found a hack (or maybe it's officially supported way) to add specific sniff codes as ignored for a specific lines in real time (from "process" method of the sniff like this):
$tokens = $phpcsFile->getTokens();
$phpcsFile->tokenizer->ignoredLines[$tokens[$stackPtr]['line']] = array(
    'CodingStandard.Commenting.FunctionComment.TypeHintMissing' => true,
);
Greg Sherwood
@gsherwood
@aik099 There is no officially supported way of doing this
Alex
@aik099
Any chance the code I’ve shown would continue to work in the future?
Greg Sherwood
@gsherwood
@aik099 I think I changed the way that code worked last year, so it's possible I wont change it again for a while, but I absolutely can't commit to that. If it needs to change to fix a bug or support new features, I'd change it.
Bfg10k
@bfg10k

Hi there, i'm using docker and i'm having a problem integrating a containerized php executable into PhpStorm with PHP CS. The problem is, as I guess you know, that containers should be remplazable and have as less persistance as it's possible but, for PHP CS to work as expected, i need to add the installed_paths so it knows about the symfony standard.

TLDR: I'm using a docker container and do not have a local PHP (neither I want) and the container does not know about the "installed_paths" when it's run.

PS: When I talk about installed Paths I mean the ones that refer to the avaliable standards.
Bfg10k
@bfg10k
Anyone can shred some light?
Kevin Nowaczyk
@Beakerboy
@bfg10k
When I created a new standard, I just passed the path to the standard in the command line like `phpcs —standard=/dev/Standard/
Kevin Nowaczyk
@Beakerboy
Hey everyone...I developed a new tokenizer type for PHPCS and I’m trying to test it in isolation. Since the constructor in the parent Tokenizer class does way more than construct, I needed to override this in a new Test class. My test class extends my new tokenizer and replaces __construct() with one that just saves the provided $string to a protected class member. Unfortunately, when I try to run everything I get an error that
“Use of undefined constant T_OPEN_CURLY_BRACKET - assumed 'T_OPEN_CURLY_BRACKET' (this will throw an Error in a future version of PHP)”
So this constant is defined in Util\Tokens. I added a use PHP_CodeSniffer\Util\Tokens; to my test case. What else do I need to do to get my test to see these constants?
Kevin Nowaczyk
@Beakerboy
I should say that adding a require() for this particular file in my phpunit bootstrap file did work. However, I feel the auto-loader should have been able to do it on its own...no?
Will Otterburn
@IkeLutra
Is there a sniff that detects when use statements aren't in alphabetical order?
Brian Smith
@justageek
in sublime text 3 with php cs and the Drupal standard, I cannot get the unused use statement to ever work, anyone know if there is some config option that must be specified?
Amir hossein Hossein Zadeh Karimi
@AmirHosseinKarimi
Hi, I'm try to add a rule to php-cbf for add a space character after end of php tags which the line will end with no other character.
Is there someone to help me?
mercurykd
@mercurykd

Hi, is it possible to extend phpcs rules(ruleset.xml) with phpcsfixer rules like yoda_style?

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->notPath('')
->in(DIR)
;

$config = [
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => true,
];

return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules($config)
->setFinder($finder)
;

harrisdt15f
@harrisdt15f
Hello everyone which rule to be use for qualifier to use as import
image.png
I am trying to avoid this kind of warning occurs. please tell me which rule to cover it.
Greg Sherwood
@gsherwood
@harrisdt15f That's not a built-in PHPCS rule. I don't know which coding standard you are using, but you'll probably need to ask whoever maintains it.
harrisdt15f
@harrisdt15f
hello everyone I got this error need help please

root@faaab3cb17ad:/var/www/xuanwutenant/vendor/bin# ./phpcs --standard=/var/www/xuanwutenant/phpcs.xml /var/www/xuanwutenant/app/Http/Controllers/FrontendApi/FrontendAuthController.php
PHP Fatal error: Uncaught ReflectionException: Function SjczTDG4TDK0Tweg() does not exist in /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php:37
Stack trace:

#0 /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php(37): ReflectionFunction->construct('SjczTDG4TDK0Twe...')

#1 /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/src/Ruleset.php(1196): PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DeprecatedFunctionsSniff->
construct()

#2 /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/src/Ruleset.php(217): PHP_CodeSniffer\Ruleset->populateTokenListeners()

#3 /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/src/Runner.php(332): PHP_CodeSniffer\Ruleset->__construct(Object(PHP_CodeSniffer\Config))

#4 /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/src/Runner.php(70): PHP_CodeSniffer\Runner->init()

#5 /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSn in /var/www/xuanwutenant/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php on line 37

Greg Sherwood
@gsherwood
@harrisdt15f That sniff gets a list of all defined functions, then uses the reflection API to see if the functions marked "internal" are deprecated. I don't know why a function called SjczTDG4TDK0Tweg would be marked as an internal function by PHP, so I'm not sure how to help. Anything special you are doing that might cause this?
Kwadz
@Kwadz

Hello guys, on the Drupal forum, we are wondering if we should keep the Fully Qualified Class Name in phpDoc comment blocks.

So, in case of Unqualified Class Name used with use statement, do you know if PHP_CodeSniffer would complain about the "unused use statement" rule?

Alex
@aik099
Hi @Kwadz , no it won't complain. It doesn't check for that at all.
Kwadz
@Kwadz
Thanks!
TaylorSasser
@TaylorSasser
Hello, Is it possible to have phpcs flag class properties with no type? Is it also possible to phpcbf add in a property type based off what is set inside of the constructor?
Greg Sherwood
@gsherwood
@TaylorSasser You can use the PSR2.Classes.PropertyDeclaration sniff to enforce that member vars have visibility declared (or just use the PSR2 standard) but PHPCBF will not add visibility automatically for you. If visibility is not provided the member var is obviously public so it could be auto-fixed, but I prefer for PHPCBF to only make formatting fixes (or move code around) and not add new code for you. Missing visibility doesn't necessarily mean the developer wants the member var to be public - they may have just forgotten to set it - so it feels like a code review thing.
zainwah24
@zainwah24
Hi, is there a chat room for web developers.