bmitch / codor Goto Github PK
View Code? Open in Web Editor NEWCustom PHPCS sniffs to find Code Smells
License: Other
Custom PHPCS sniffs to find Code Smells
License: Other
Might help detect functions that do more than one thing.
Classes should be no more than X lines.
Just a warning to suggest to the developer to see if an object could be returned instead.
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.
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.
Don't think there is a point to having protected since final classes cannot be extended.
make sure there are X lines between the end of a function and the next functions doc block
Think it would be good to have these classes:
Could wrap the array of tokens inside a collection and each token could be a value object.
The warning could suggest to use composition over inheritance.
@Exadra37 feel free to take this one if you wish ๐
Maybe could make this more generic. Could have a config file where you list functions and how many parameters you expect them to be called with.
Codor/src/Codor/Sniffs/Files/IndentationLevelSniff.php
Lines 59 to 79 in c1447a2
Codor/src/Codor/Sniffs/Files/ReturnNullSniff.php
Lines 20 to 48 in c1447a2
Once fixed can remove the @codingStandardsIgnoreStart
in the method doc block.
Limit the number of member variables for a class.
How many to limit?
Extracted from #71
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! :)
This package's service is occasionally down which fails the builds. Will make it always fail and can just refer to the build log to see if it failed.
Because it is ignoring functions with no body. Should not do this.
vendor/bin/phpcs --standard=src/Codor/ruleset.xml src
Instead of using new
should be using DI. Should this be sniffed out?
Looks like some of the indents are tabs. Should all be spaces.
Make sure the error or warning message received is updated with the custom value in the test.
warns if a boolean method parameter is used in an if statement with the method. Could indicate the method has more than one responsibility.
Instead of returning null you can:
Checks if if
statement has too many conditions.
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.
Not sure if possible but if so would be good to test.
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);
}
}
Might need to extract this to 2 sniffs.
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.
controller
.if
, else
, or any loop keyword it fails.Need to init variables when starting
$this->classIsMarkedFinal = false;
$this->protectedMethods = [];
$this->protectedVariables = [];
Line numbers reported are also broken.
For example, could the max number of lines a function be a configurable value?
This class and the test classes could be cleaned up:
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'
);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.