Git Product home page Git Product logo

Comments (6)

povils avatar povils commented on August 15, 2024 1

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.

exussum12 avatar exussum12 commented on August 15, 2024

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.

paslandau avatar paslandau commented on August 15, 2024

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:

from phpmnd.

exussum12 avatar exussum12 commented on August 15, 2024

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.

paslandau avatar paslandau commented on August 15, 2024

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.

exussum12 avatar exussum12 commented on August 15, 2024

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)

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.