szepeviktor / composer-envato

Composer plugin for Envato 💚 Install WordPress themes and plugins from ThemeForest‎‎ and CodeCanyon
https://packagist.org/packages/szepeviktor/composer-envato
MIT License
32 stars 3 forks source link

Ensure the config is valid before subscribing to events #16

Closed mcaskill closed 1 year ago

mcaskill commented 1 year ago

Prevents an error in EnvatoPlugin:

Call to a member function getDownloadUrl() on null

This error is the result of the EnvatoApi not being set up when the config is invalid but events still being subscribed to.

szepeviktor commented 1 year ago

Thank you. The fix is correct.

mcaskill commented 1 year ago

🤦 The fix is not correct; the getSubscribedEvents() method is static. Sorry about that. I'll push a better correction soon.

mcaskill commented 1 year ago

I can either move the config validity check to handlePreDownloadEvent():

public function handlePreDownloadEvent(PreFileDownloadEvent $event): void
{
    if ($event->getType() !== 'package' || ! $this->config->isValid()) {
        return;
    }

Or change the $config property to be static.

szepeviktor commented 1 year ago

Oh noooooooooooooooooooooooooooooooooooooooooooooooooooooooo!

I leave it 100% up to you. This PR is not yet released :)

szepeviktor commented 1 year ago

Please run composer run analyze before that PR.