alexdebril / feed-io

A PHP library to read and write feeds in JSONFeed, RSS or Atom format
https://alexdebril.github.io/feed-io/
MIT License
256 stars 54 forks source link

Deprecate the Factory #388

Closed alexdebril closed 2 years ago

alexdebril commented 2 years ago

As PHP 8.1allows to use Newin the initializers, it's now possible to write FeedIo's constructor like this:

    public function __construct(
        protected ClientInterface $client = new \FeedIo\Adapter\Guzzle\Client(new \GuzzleHttp\Client()),
        protected LoggerInterface $logger = new \Psr\Log\NullLogger(),
        protected ?SpecificationInterface $specification = new Specification(),
    ) {

so in the client code, devs can create it with just:

$feedIo = new FeedIo;

or if we want to specify a logger:

$logger = new \Whatever\Complies\With\Psr\Log($file);
$feedIo = new FeedIo(logger: $logger);

Which is simpler and cleaner than trying to invoke the Factory to build FeedIo with its dependencies. As the main motivation behind the Factory was to provide a simple way to build FeedIo, this is no more relevant with PHP 8.1's new abilities. So it's time to deprecate it.

alexdebril commented 2 years ago

Thanks @bezin !