Skip to content

Commit

Permalink
Updated to PHP7.4
Browse files Browse the repository at this point in the history
- Removed dependency on tale-dev-tool
- Added property typing
  • Loading branch information
TorbenKoehn committed Mar 11, 2020
1 parent 08d6f36 commit 62484e7
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 34 deletions.
15 changes: 3 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@

language: php

git:
depth: 5

php:
- 7.2
- 7.3

- 7.4
install:
- travis_retry composer clear-cache
- travis_retry composer self-update
- travis_retry composer install

script:
- vendor/bin/tale-dev check --report --coverage-php-version=7.2

addons:
code_climate:
repo_token: b046f38e1a113e8ea7ec3e3173db1754b87b7858599f16f7f8d0f3f7a0ea6a3c
- composer lint
- composer test
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
"description": "A PSR-14 implementation",
"license": "MIT",
"homepage": "https://talesoft.codes",
"scripts": {
"test": "phpunit",
"test:coverage-html": "phpunit --coverage-html=coverage",
"lint": "phpcs",
"lint:fix": "phpcbf"
},
"authors": [
{
"name": "Torben Köhn",
"email": "torben@talesoft.codes"
}
],
"require": {
"php": ">=7.1.0",
"php": ">=7.4.0",
"psr/http-message": "^1.0",
"psr/http-factory": "^1.0",
"psr/event-dispatcher": "^1.0"
Expand All @@ -25,6 +31,7 @@
"files": ["src/functions.php"]
},
"require-dev": {
"talesoft/tale-dev-tool": "dev-master"
"phpunit/phpunit": "^8.4",
"squizlabs/php_codesniffer": "^3.5"
}
}
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="PSR-2">
<rule ref="PSR2"/>
<file>./src</file>
<file>./tests</file>
</ruleset>
21 changes: 21 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.4/phpunit.xsd"
colors="true"
bootstrap="./vendor/autoload.php"
forceCoversAnnotation="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true">
<testsuites>
<testsuite name="Talesoft - Tale Event">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
5 changes: 1 addition & 4 deletions src/Event/AbstractStoppableEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

abstract class AbstractStoppableEvent implements StoppableEventInterface
{
/**
* @var bool
*/
private $propagationStopped;
private bool $propagationStopped;

public function __construct(bool $propagationStopped = false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Event/ListenerProvider/ChainListenerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class ChainListenerProvider implements ListenerProviderInterface
/**
* @var iterable<ListenerProviderInterface>
*/
private $providers;
private iterable $providers;

/**
* ChainListenerProvider constructor.
Expand Down
2 changes: 1 addition & 1 deletion src/Event/ListenerProvider/ClassMapListenerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class ClassMapListenerProvider implements ListenerProviderInterface
/**
* @var callable[][]
*/
private $classMap;
private array $classMap;

public function __construct(array $classMap)
{
Expand Down
17 changes: 7 additions & 10 deletions src/Event/ListenerProvider/ReflectionListenerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

final class ReflectionListenerProvider implements ListenerProviderInterface, ListenerRegistryInterface
{
/**
* @var SplObjectStorage
*/
private $listeners;
private SplObjectStorage $listeners;

public function __construct(iterable $listeners = [])
{
Expand All @@ -26,21 +23,21 @@ public function __construct(iterable $listeners = [])
public function addListener(Closure $handler): void
{
try {
$refl = new \ReflectionFunction($handler);
$reflection = new \ReflectionFunction($handler);
} catch (\Exception $ex) {
throw new InvalidListenerException('Failed to reflect closure', $ex);
throw new InvalidListenerException('Failed to reflect closure. See inner exception for details.', $ex);
}
$parameters = $refl->getParameters();

$parameters = $reflection->getParameters();
if (count($parameters) !== 1) {
throw new InvalidListenerException('Closure needs to have exactly one parameter');
throw new InvalidListenerException('Closure needs to have exactly one parameter.');
}

$class = $parameters[0]->getClass();
if (!$class) {
throw new InvalidListenerException('Closure parameter needs a type-hint on a valid class');
throw new InvalidListenerException('Closure parameter needs a type-hint on a valid class.');
}


$this->listeners->attach($handler, $class->getName());
}

Expand Down
8 changes: 4 additions & 4 deletions src/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

final class EventDispatcher implements EventDispatcherInterface
{
/**
* @var ListenerProviderInterface
*/
private $listenerProvider;
private ListenerProviderInterface $listenerProvider;

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

/**
* {@inheritDoc}
*/
public function dispatch(object $event)
{
$listeners = $this->listenerProvider->getListenersForEvent($event);
Expand Down

0 comments on commit 62484e7

Please sign in to comment.