Giter Site home page Giter Site logo

codor's People

Contributors

bmitch avatar d35k avatar kevin-schmitt avatar szepeviktor avatar villfa 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

codor's Issues

Class length sniff

Classes should be no more than X lines.

  • Any way to subtract comments from line count?
  • Any way to make X configurable?

Refactor IndentationLevelSniff

This class isn't as clean as I'd like it:

    public $indentationLimit = 2;

This doesn't really make sense because indentation limit is actually 1 but we use 2 in the class.

The function name inspectScope doesn't really explain what it is doing. This function also has more than 1 levels of indentation.

Sniff to limit number of parameters

From Clean Code:

The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification -- and then shouldn't be used anyway.

Classes for Tokens and Token collections.

Think it would be good to have these classes:

  • Wrapper around the Token array data to make it more OO to obtain information about a token.
  • Perhaps a wrapper around an array of tokens to make it easy to iterate through all found tokens in a sniff.

Remove any levels of indentation > 1

  • /**
    * Inspect the tokens in the scope of the provided $token.
    * @codingStandardsIgnoreStart
    * @param array $token Token Data.
    * @param array $tokens Tokens.
    * @return void
    */
    protected function inspectScope(array $token, array $tokens)
    {
    $start = $token['scope_opener'];
    $end = $token['scope_closer'];
    $this->relativeScopeLevel = $tokens[$start]['level'];
    for ($index=$start; $index <= $end; $index++) {
    $nestedToken = $tokens[$index];
    if ($nestedToken['type'] === "T_SWITCH") {
    return;
    }
    $this->adjustMaxIndentationFound($nestedToken);
    }
    }
    // @codingStandardsIgnoreEnd

  • /**
    * Processes the tokens that this sniff is interested in.
    * @codingStandardsIgnoreStart
    * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
    * @param integer $stackPtr The position in the stack where
    * the token was found.
    * @return void
    */
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
    $tokens = $phpcsFile->getTokens();
    $returnTokenIndex = $stackPtr;
    $returnValueToken = '';
    $numberOfTokens = count($tokens);
    for ($index = $returnTokenIndex; $index < $numberOfTokens; $index++) {
    if ($tokens[$index]['type'] === 'T_SEMICOLON') {
    $returnValueToken = $tokens[$index - 1];
    break;
    }
    }
    // @codingStandardsIgnoreEnd
    if ($returnValueToken['type'] === 'T_NULL') {
    $error = "Return null value found.";
    $phpcsFile->addError($error, $stackPtr);
    }
    }

Once fixed can remove the @codingStandardsIgnoreStart in the method doc block.

Doesn't work with Atom Linter-PHPCS?

I tried setting it up to use with Atom's Linter-Phpcs package, but PHPCS just stops running. I don't see any errors or warnings where I should. If I remove the custom config from the Linter-PHPCS configuration, it resumes working normally.

Any suggestions on what I might try to debug this?

Thanks! :)

Sniff for method flag parameters

warns if a boolean method parameter is used in an if statement with the method. Could indicate the method has more than one responsibility.

Sniff for anonymous functions

Sometimes you don't want to have anonymous functions. Example is you may not want them in your routes.php file for Laravel.

This sniff will probably be one you only run against a handful of files.

ignore try-catch block as indentation

Currently any loop or conditional in a try-catch block is reported. The only workaround is to put it in a function, but that doesn't always make sense. It's basically doubling the amount of functions if you need a try-catch block.

try {
    if ($this->eventShouldBeCollected($event)) {
        $this->collectEvent($event);
    }

    $this->fire($event);
} catch (\Exception) {
    // log event errors
}

also in the catch part:

try {
    $this->response = $this->guzzle->request(...);
    // etc..
} catch (\GuzzleHttp\Exception\ClientException $e) {
    if ($e->getResponse()->getStatusCode() == 404) {
        throw VacancyIsClosed::forId($vacancyId);
    }
}

Enhance readme

  • Add code examples for each sniff. Done
  • Show how to run individual sniffs or exclude individual sniffs.
  • For each sniff show how to customize if applicable.
  • Explain why, benefits of why you'd want each sniff.

Sniff to prevent if/loops within any controller methods?

Not sure if this is a good idea or not but I guess users can always disable if they don't want to use it.

If the file ends in Controller.php then no methods within should contain any logic. Logic should be delegated to other classes.

  • If file ends in controller.
  • If file contains if, else, or any loop keyword it fails.

Sniff to remove unwanted blank lines.

  • Blank lines at start/end of function/method
  • Blank lines before/after function/method
  • Blank lines after class declaration.
  • Blank lines around namespaces/use statement.

Fix final class sniff

Need to init variables when starting

        $this->classIsMarkedFinal = false;
        $this->protectedMethods = [];
        $this->protectedVariables = [];

Line numbers reported are also broken.

Changes to CodeSniffRunner

This class and the test classes could be cleaned up:

  • To get the error count and warning count you have to run the sniff twice. Should only have to do it once.
  • Can we get the error and warning message so that can be tested?

The code where it runs a sniff looks messy. Can this be cleaned up?

        $errorCount = $codeSnifferRunner->detectErrorCountInFileForSniff(
            __DIR__.'/Assets/FunctionLengthSniff/FunctionLengthSniff.inc',
            'Codor.Files.FunctionLength'
        );

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.