Comments (6)
Hey everyone :)
My stand is that it makes more sense to extract a number to constat than put these ugly comments.
But again I don't see a problem why we couldn't provide a mean to ignore these numbers.
Are you want to take an ownership of this feature and implement this?
My suggestion for now:
// phpmnd:ignoreLine (ignore line below)
from phpmnd.
We use phpmnd on older / larger code bases with https://github.com/exussum12/coverageChecker
This solves a lot of legacy issues by only checking the changed code. So going forwards you wouldn't be able to do that, but the existing code would pass its CI.
The specific example you give there is a magic number no matter how you look at it. Why is it 1000 ? That needs to be explained. There will be a reason for it being 1000. Which can be explained much better in code.
$arg = $arg ?? self::MICROSECONDS_TO_SECONDS;
for example
from phpmnd.
I get your point, I should have used a better example.
Actually, it's a buffer size for an import process. There is no "business logic" for that value. There is imho no inherent value in "extracting" that number in constant, e.g.
function import($bufferSize = null){
$bufferSize = $bufferSize ?? 1000;
}
VS
const BUFFER_SIZE = 1000;
function import($bufferSize = null){
$bufferSize = $bufferSize ?? self::BUFFER_SIZE;
}
Does not make the code any better / more readable.
Regardless it's really not about that specific use case.
There will always be "edgecases" and "opinions" in one way or another and giving people the option to "ignore" something for the time being leads to a much higher acceptance rate. That's way most more mature tools support such an option, e.g:
- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file
- https://phpmd.org/documentation/suppress-warnings.html
from phpmnd.
Personally I don't have a use case for this
its the difference between
const DEFAULT_BUFFER_SIZE = 1000;
function import($bufferSize = null){
$bufferSize = $bufferSize ?? self::DEFAULT_BUFFER_SIZE;
}
(which actually should be)
its the difference between
const DEFAULT_BUFFER_SIZE = 1000;
function import($bufferSize = self::DEFAULT_BUFFER_SIZE) {
}
and
function import($bufferSize = null){
/** @phpmnd:disable */
$bufferSize = $bufferSize ?? 1000;
/** @phpmnd:enable */
}
It seems more effort to mark it as not a magic number than to just resolve the magic number.
Most other tools do have it though, I would be interested to see the usage of these ignore statements
from phpmnd.
It seems more effort to mark it as not a magic number than to just resolve the magic number.
Again - here we just disagree what we see as a magic number. Which is completely fine.
But I currently do not have the "choice" to to go with my definition - that's the point.
I would be interested to see the usage of these ignore statements
Example: CodeSniffer with Line length rule (Generic.Files.LineLength)
It's totally reasonable to allow only a certain line length.
But sometimes I'm a couple of characters "above" the limit, e.g.
throw new Exception("Here comes my descriptive explanation why we ended up here ....");
Sure, I could do stuff like
$msg = "Here comes my descriptive explanation why we ended up here ...."
throw new Exception($msg);
But that doesn't make the code any better / more readable. And I'm strictly against changing something with the only purpose to satisfy some style metric.
Further, "changing" code is always risky. It's much easier to add a
// phpcs:disable Generic.Files.LineLength
comment.
And yes - in a perfect world we'd always fix/refactor everything immediately and there would be no discussion about what's "correct - but in the real world there are always tradeoffs, opinions, deadlines, priorities etc. :)
from phpmnd.
Been thinking of this. You can use intval here it looks much than annotations. Then ignore any intval function calls. We could perhaps do that as standard ? Intval and strval could be added as default ignore parameters ?
from phpmnd.
Related Issues (20)
- Syntax error when using class called `Match` in the code HOT 6
- Dependency phpunit/php-timer HOT 4
- PHP 8 HOT 14
- New release needed ! HOT 2
- Cache failure in CI HOT 3
- Extension support for Exceptions possible? HOT 4
- What is "12" in Printer\XML ? HOT 5
- New phpunit schema HOT 2
- Option to disable the highlighter
- Ignore line or array specific key declaration HOT 7
- Support github action output format HOT 1
- Add ncurses dependency or test tput availability HOT 4
- New release HOT 4
- tput binary not found in alpine based images HOT 2
- Version 3.0 still renders version 2.5 HOT 8
- How to define the most strict configuration possible for phpmnd ? HOT 1
- phpunit/php-timer v6 support? HOT 2
- [Question] Which output formats are available? HOT 2
- Latest tag has previous version code HOT 3
- Add support to more output formats HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpmnd.