First, documentation.
The README.md file contains a section about instantiating and using this programmatically:
use AMWScan\Scanner;
$app = new Scanner();
$report = $app->setPathScan("my/path/to/scan")
->enableBackups()
->setPathBackups("/my/path/backups")
->enableLiteMode()
->setAutoClean()
->run();
However this example is invalid due to the fact that the majority of those class methods are actually static.
It has to be said that the documented approach would definitely be preferable as it is a more common object oriented approach.
All or most of those method calls above actually instantiate the object again from scratch because they tend to end with:
I guess the documentation needs to be something like this but you'd be instantiating the class at least 6 times:
use AMWScan\Scanner;
Scanner::setPathScan("my/path/to/scan");
Scanner::enableBackups();
Scanner::setPathBackups("/my/path/backups");
Scanner::enableLiteMode();
Scanner::setAutoClean();
$app = new Scanner();
However, the bigger problem with this approach is the __construct
method if you're not running via the CLI:
if (!self::isCli()) {
self::setSilentMode();
}
In case the issue isn't obvious, the setSilentMode
method ends in:
So you have a code path in the __construct
method which results in calling the __construct
method therefore there is an infinite loop.
My gut feeling is that the best approach would be to move away from these static methods entirely and make them public class methods and use class properties:
public function setPathScan($pathScan)
{
$this->pathScan = Path::get($pathScan);
return $this;
}
This would result in the documented example actually working - assuming similar changes are applied to all of the methods, though there is at least 52 methods that would need to be changed and I suspect there would be many more changes to accommodate that.
$scanner = new Scanner();
$scanner->setPathScan("path")
->enableBackups()
->setAutoClean();
The simplest solution may be to update the documentation and also change these methods to no longer return themselves. I don't tend to see a lot of that with static method calls so it strikes me as strange but I'm saying that with the ignorance of only having seen a little bit of the Scanner class and not fully understanding the full library.
Any thoughts?