GithubHelp home page GithubHelp logo

Comments (2)

marcocesarato avatar marcocesarato commented on September 24, 2024 1

Hi @chrisdeeming, this library has been rewritten many times so some logic comes from previous versions (initially it was a single script file just to give an idea) and programmatic usage was not maintained with the same priority as using the CLI.

Anyway, originally the idea was to use it like a singleton instance and if you check the line below, it theoretically prevents the infinite loop you intend using fluent setters with return new self();.

if (!self::isInitialized()) {

self::$inited = true;

The below pattern usage is permitted from php.

$report = $app->setPathScan("my/path/to/scan")
              ->enableBackups()
              ->setPathBackups("/my/path/backups")
              ->enableLiteMode()
              ->setAutoClean()
              ->run();

and also the following

Scanner::setPathScan("my/path/to/scan");
Scanner::enableBackups();
Scanner::setPathBackups("/my/path/backups");
Scanner::enableLiteMode();
Scanner::setAutoClean();

so you can use both.

Some methods are static because they are used by other classes that don't have the class instance.

So the anwser is yes, this is a "bad practice" and the class should be rewritten to use a real singleton instance (with a getInstance() method and newInstance() or something like that) and convert all static properties and static methods to non-static and then change the setters from return new self(); to return $this;. After this should be changed all methods called statically from the others classes and change it with the getInstance() method.

About the following lines:

self::setSilentMode();

return new self();

for sure it is a big problem and I can fix it and I will release it in the next version.

from php-antimalware-scanner.

chrisdeeming avatar chrisdeeming commented on September 24, 2024 1

Thank you for the detailed reply and quick fix for the infinite loop issue @marcocesarato.

My IDE, PhpStorm, seems to struggle with arrow accessors on static methods and a combination with the other issues I was experiencing led me to believe that it wasn't working.

I think I've identified a couple of other bugs which I will mention in separate issues.

from php-antimalware-scanner.

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.