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 2019 22:52
    jrfnl commented #2387
  • Jan 31 2019 22:41
    valeryan commented #2386
  • Jan 31 2019 22:40
    valeryan commented #2386
  • Jan 31 2019 22:40
    valeryan commented #2386
  • Jan 31 2019 22:17
    gsherwood commented #2387
  • Jan 31 2019 22:14
    gsherwood milestoned #2387
  • Jan 31 2019 22:13
    gsherwood labeled #2386
  • Jan 31 2019 22:13
    gsherwood commented #2386
  • Jan 31 2019 22:05
    gsherwood milestoned #2388
  • Jan 31 2019 22:03
    gsherwood labeled #2394
  • Jan 31 2019 22:02
    gsherwood commented #2394
  • Jan 31 2019 22:02
    gsherwood closed #2394
  • Jan 31 2019 22:02

    gsherwood on master

    Fixed docblocks Because custom… (compare)

  • Jan 31 2019 22:02
    gsherwood milestoned #2394
  • Jan 31 2019 16:50
  • Jan 31 2019 16:00
    SteepDevs starred squizlabs/PHP_CodeSniffer
  • Jan 31 2019 15:22
  • Jan 31 2019 14:39
    sebastiaanluca commented #2304
  • Jan 31 2019 14:38
    sebastiaanluca commented #2304
  • Jan 31 2019 13:09
    rlauenroth starred squizlabs/PHP_CodeSniffer
Bryan Evans
@BryIsTheGuy_twitter
Hmm, still had to specify warning-severity 5 without the <arg> line.
Which I think is supposed to be the default
Oh well, it works. Thanks!
Juliette
@jrfnl
@BryIsTheGuy_twitter You shouldn't need the warning-severity as long as you don't silence warnings with -n. Anyways, glad to hear you got it working.
James Hoegerl
@la-jamesh
How can I enable unused imports?
Greg Sherwood
@gsherwood
@la-jamesh PHPCS doesnt come with a sniff to check for unused imports so you'd need to find and use another coding standard that provides that functionality. I think the Drupal standard has one, but I haven't used it.
Juliette
@jrfnl
If I remember correctly the Slevomat standard has one too.
Jesse Donat
@donatj
Is there any way to set a sniff property as a CLI parameter?
Greg Sherwood
@gsherwood
@donatj Not on the CLI. Sniff properties can only be set via ruleset files
Jesse Donat
@donatj
@gsherwood Hmm, lol, it'd be real nice if that were an option, not have to create multiple rulesets for steps of my makefile
Ivan Peevski
@ipeevski
Is there a rule to detect empty == statement - such as "$var == 0;" (the intended would be "$var = 0;")
Greg Sherwood
@gsherwood
@ipeevski No, nothing in the included set of sniffs.
Glen
@glen-84
@jrfnl Would it make sense to allow assignments in a condition if it's wrapped in parentheses to make it explicit, like if (($post = $this->getRequest()->getPost())) {?
Juliette
@jrfnl

@glen-84 Been thinking a bit about your question. I don't think that's a good idea as it would take away from the principle of the sniff - forbidding assignments in conditions -. I could imagine we can add a separate errorcode for assignments within arbitrary parenthesis - like there is a separate error code for assignments in a while condition, but it would still take away from the intend of the sniff.

For now, you can whitelist a condition in arbitrary parenthesis with the PHPCS 3.2+ annotations, like // phpcs:ignore Ruleset.Cat.Sniffname.Errorcode. Would that work for you ?

Glen
@glen-84
@jrfnl I am aware of the suppression comments, I just thought that this might be a cleaner solution when you "know what you're doing". Anyway, I respect your decision and thank you for your reply.
Juliette
@jrfnl
@glen-84 Not a decision, just my opinion ;-)
Juliette
@jrfnl
@glen-84 Also - using parentheses does not necessarily mean that someone knows what they are doing and PHPCS cannot analyze whether the dev knew what they were doing or "accidentally" used the syntax.
Petr Bugyík
@o5
Hello! Is there sniff for enforcing only one way to define an array type in phpdocs? I mean "Long form" vs "Short form" which is described in table "Several ways to define an array type" http://www.icosaedro.it/phplint/phplint2/doc/reference/docblocks.htm#H12_Types
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?