Skip to content

Commit

Permalink
Add rector [batch] (#69)
Browse files Browse the repository at this point in the history
* Add rector files yiisoft/yii-dev-tool#232

* Add rector/rector dependecy

* [rector] Apply fixes

* Apply fixes from StyleCI

* Use predefined rector action

* Drop PHP 7.4

* Add changelog line, improve readme

* Add import

Co-authored-by: rector-bot <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Rustam <[email protected]>
Co-authored-by: Alexey Rogachev <[email protected]>
  • Loading branch information
5 people authored Oct 23, 2022
1 parent 5c34773 commit 10d8ed2
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1']
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1']
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Yii Event Dispatcher Change Log

## 1.0.2 under development
## 1.1.0 under development

- Enh #64: Improve exception message on adding listener to collection (vjik)
- Enh #64: Improve exception message on adding listener to collection (@vjik)
- Chg #69: Raise the minimum `PHP` version to `8.0` (@xepozz, @rustamwin)

## 1.0.1 July 28, 2021

- New #63: Allow adding a single listener to multiple event class names at once in `ListenerCollection::add()` (vjik)
- Bug #62: Support listeners for events defined with union types (vjik)
- New #63: Allow adding a single listener to multiple event class names at once in `ListenerCollection::add()` (@vjik)
- Bug #62: Support listeners for events defined with union types (@vjik)

## 1.0.0 February 16, 2021

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ to events dispatched.
- Encourages designing event hierarchy.
- Can combine multiple event listener providers.

## Requirements

- PHP 8.0 or higher.

## Installation

The package could be installed with composer:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
"source": "https://github.com/yiisoft/event-dispatcher"
},
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"psr/event-dispatcher": "1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18"
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);
};
5 changes: 1 addition & 4 deletions src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*/
final class Dispatcher implements EventDispatcherInterface
{
private ListenerProviderInterface $listenerProvider;

public function __construct(ListenerProviderInterface $listenerProvider)
public function __construct(private ListenerProviderInterface $listenerProvider)
{
$this->listenerProvider = $listenerProvider;
}

public function dispatch(object $event): object
Expand Down
2 changes: 0 additions & 2 deletions src/Provider/CompositeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public function getListenersForEvent(object $event): iterable

/**
* Adds provider as a source for event listeners.
*
* @param ListenerProviderInterface $provider
*/
public function attach(ListenerProviderInterface $provider): void
{
Expand Down
2 changes: 0 additions & 2 deletions src/Provider/ListenerCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function getForEvents(string ...$eventClassNames): iterable
* @param string ...$eventClassNames
*
* @throws InvalidArgumentException If callable is invalid.
*
* @return self
*/
public function add(callable $listener, string ...$eventClassNames): self
{
Expand Down
9 changes: 2 additions & 7 deletions src/Provider/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Psr\EventDispatcher\ListenerProviderInterface;

use function get_class;

/**
* Provider is a listener provider that registers event listeners for interfaces used in callable type-hints
* and gives out a list of handlers by event interface provided for further use with Dispatcher.
Expand All @@ -23,16 +21,13 @@
*/
final class Provider implements ListenerProviderInterface
{
private ListenerCollection $listeners;

public function __construct(ListenerCollection $listeners)
public function __construct(private ListenerCollection $listeners)
{
$this->listeners = $listeners;
}

public function getListenersForEvent(object $event): iterable
{
yield from $this->listeners->getForEvents(get_class($event));
yield from $this->listeners->getForEvents($event::class);
/** @psalm-suppress MixedArgument */
yield from $this->listeners->getForEvents(...array_values(class_parents($event)));
/** @psalm-suppress MixedArgument */
Expand Down
6 changes: 2 additions & 4 deletions tests/common/Dispatcher/CompositeDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\EventDispatcher\Tests\Dispatcher;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\EventDispatcher\StoppableEventInterface;
Expand Down Expand Up @@ -60,10 +61,7 @@ public function testPropagationStops(): void
$this->assertSame($stoppableEvent, $result);
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|\Psr\EventDispatcher\EventDispatcherInterface
*/
private function createTransparentDispatcher()
private function createTransparentDispatcher(): MockObject|EventDispatcherInterface
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher
Expand Down

0 comments on commit 10d8ed2

Please sign in to comment.