PHP code example of hxv / phpstan-event-dispatcher-exceptions

1. Go to this page and download the library: Download hxv/phpstan-event-dispatcher-exceptions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hxv / phpstan-event-dispatcher-exceptions example snippets


/**
 * @throws RuntimeException
 */
class SomeEvent
{
}

try {
    $eventDispatcher->dispatch(new SomeEvent());
} catch (RuntimeException $exception) { // no more error!
    // handle exception
}
// new exceptions needs to be handled or annotated at function level - you will not miss them

class SomeEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [SomeEvent::class => 'handleEvent'];
    }

    /**
     * @throws RuntimeException <-- this is fine
     * @throws LogicException <-- this is not (unless LogicException is unchecked)
     */
    public function handleEvent(): void
    {
    }
}