Giter Club home page Giter Club logo

psr2r-sniffer's People

Contributors

dereuromark avatar ewbarnard avatar hemberger avatar mrrsm avatar rmccue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

psr2r-sniffer's Issues

NoInlineFullyQualifiedClassName vs UnusedUseStatementSniff.php

Lets say that I have the following

<?php
class ClassA {

    public function __construct(PimpleContainer $container){
         /** \MyNamespace\ClassB $classB */
         $classB = $container['class_b'];
    }
}

If I understood correctly the above is not allowed by the NoInlineFullyQualifiedClassName

But also the below is not allowed by the UnusedUseStatement

<?php
use \MyNamespace\ClassB;

class ClassA {

    public function __construct(PimpleContainer $container){
         /** ClassB $classB */
         $classB = $container['class_b'];
    }
}

Question - documenting internals

@dereuromark - I'm considering documenting how this psr2r-sniffer works (internals documentation) in support of bringing people into one aspect of php internals (lexing/tokenizing; examining how PHP source is structured) - https://gist.github.com/ewbarnard/97ba2259f0e05e4331bbaa3394da4084

  • develop vs master - it looks like I'm better off focusing on master rather than develop?
  • docs/ vs wiki - I'd prefer to add to the source tree rather than the github wiki area. Correct?

Of course getting people to think about the POINT of this project is a plus. That's why I'd like to use this as a route to understanding how the Code Sniffer works, and how the sniffs consume tokens.

Support for phpstan generics?

I was wondering if there is any chance that support would be added for PHPStan generics (https://phpstan.org/blog/generics-by-examples). They are very useful for getting precise type validation from static analysis, but the PSR-2-R sniffs aren't happy with them.

The following is an example of a doc block for a function that takes a class string and constructor arguments, and outputs an instance of the class.

/**
 * @template T of object
 * @param class-string<T> $name The name of the class to construct
 * @param mixed ...$args The arguments to pass to the constructor
 * @return T
 */

And here are the resulting PSR-2-R violations.

>> 35:  »   ·*·@template·T·of·object
   36:  »   ·*·@param·class-string<T>·$name·The·name·of·the·class·to·construct
   37:  »   ·*·@param·mixed·...$args·The·arguments·to·pass·to·the·constructor
----------------------------------------------------------------------------------------------------------------------------------------
LINE 36: ERROR   [ ] Invalid typehint `class-string<T>` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 36: ERROR   [x] Possible doc block error: `class-string<T> $name The name of the class to construct` seems to be missing type
                     `string`. (Spryker.Commenting.DocBlockParamAllowDefaultValue.Typehint)
LINE 36: ERROR   [ ] Invalid typehint `class-string<T>` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 36: ERROR   [ ] Invalid typehint `class-string<T>` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
----------------------------------------------------------------------------------------------------------------------------------------
   34:  »   ·*
   35:  »   ·*·@template·T·of·object
>> 36:  »   ·*·@param·class-string<T>·$name·The·name·of·the·class·to·construct
   37:  »   ·*·@param·mixed·...$args·The·arguments·to·pass·to·the·constructor
   38:  »   ·*·@return·T
----------------------------------------------------------------------------------------------------------------------------------------
LINE 38: ERROR   [ ] Invalid typehint `T` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 38: ERROR   [ ] Invalid typehint `T` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 38: ERROR   [ ] Invalid typehint `T` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
----------------------------------------------------------------------------------------------------------------------------------------
   36:  »   ·*·@param·class-string<T>·$name·The·name·of·the·class·to·construct
   37:  »   ·*·@param·mixed·...$args·The·arguments·to·pass·to·the·constructor
>> 38:  »   ·*·@return·T
   39:  »   ·*/

I can certainly just skip these sniffs, but I thought I'd reach out in case there was any interest in supporting this feature. Thanks!

whitespace issues

The following passes but should not:

AppPath::get( 'View/Cell' );
//expected
AppPath::get('View/Cell');
$folderContent = ( new Folder( $folder ) )->read( Folder::SORT_NAME, true );
//expected
$folderContent = (new Folder($folder))->read(Folder::SORT_NAME, true);

<rule ref="PSR2.Methods.FunctionCallSignature"/> is broken for tab and unfortunately cannot be used.

Uncaught Error: Class 'PHP_CodeSniffer\Runner' not found

Hi there :)

I have psr2r-sniffer installed (in a CakePHP 4 project), via composer, running PHP 7.3.29.

When I run the sniffer, I get the following error:

PHP Fatal error:  Uncaught Error: Class 'PHP_CodeSniffer\Runner' not found in /home/sites/olive/htdocs/vendor/fig-r/psr2r-sniffer/PSR2R/Tools/Sniffer.php:73
Stack trace:
#0 /home/sites/olive/htdocs/vendor/fig-r/psr2r-sniffer/bin/sniff.php(23): PSR2R\Tools\Sniffer->sniff()
#1 {main}
  thrown in /home/sites/olive/htdocs/vendor/fig-r/psr2r-sniffer/PSR2R/Tools/Sniffer.php on line 73

I have PHP_CodeSniffer installed through composer as well, and can run vendor/bin/phpcs path-to-file without issues.

What could be wrong here? Thanks in advance!

Uncaught Error: Class 'PHP_CodeSniffer_CLI'

Hi,

I've got Code sniffer installed via composer (dev dependency) but I'm getting this issue. I'm running PHP 7.1

PHP Fatal error:  Uncaught Error: Class 'PHP_CodeSniffer_CLI' not found in /vendor/fig-r/psr2r-sniffer/PSR2R/Tools/Sniffer.php:68
Stack trace:
#0 /vendor/fig-r/psr2r-sniffer/bin/sniff.php(22): PSR2R\Tools\Sniffer->sniff()
#1 {main}
  thrown in /vendor/fig-r/psr2r-sniffer/PSR2R/Tools/Sniffer.php on line 68
[woohuiren@localhost atom-api]$ vendor/bin/sniff
PHP Fatal error:  Uncaught Error: Class 'PHP_CodeSniffer_CLI' not found in /vendor/fig-r/psr2r-sniffer/PSR2R/Tools/Sniffer.php:68
Stack trace:
#0 /vendor/fig-r/psr2r-sniffer/bin/sniff.php(22): PSR2R\Tools\Sniffer->sniff()
#1 {main}
  thrown in /vendor/fig-r/psr2r-sniffer/PSR2R/Tools/Sniffer.php on line 68\

I went to look at the file. Apparently its just use use PHP_CodeSniffer_CLI;. Is there a better way to go about? I could possibly contribute something to allow the use of dev dependency version of PHP code sniffer.

Thanks again

EDIT: I took a look and apparenly #11 fixes this?

Issue with alphabetical order of classes

Weird behaviour occurs in sorting used classes in alphabetical order (see screenshot).
In my opinion a space comes before any letter...
Alphabetical_order_classes

To fix the notice it wants me to place Ad between AdAdvertiser and AdGroupLeadgeneration.

Suspect sniff: PSR2R\Sniffs\Namespaces\UseInAlphabeticalOrderSniff.php
PHP: 7.3.9
IDE: PhpStorm 2020.1.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.