Skip to content

Commit c74e0fc

Browse files
author
Andrei Onita
committed
solved consistency issues
1 parent 004c4d5 commit c74e0fc

20 files changed

Lines changed: 94 additions & 100 deletions

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
This package contains controller like middleware to be used inside a DotKernel or Mezzio application. It provides base classes for action based controllers similar to Laminas controller component. It is more lightweight though, but supports controller plugins.
44

55
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-controller)
6-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.2.0)
6+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.4.0)
77

88
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/issues)
99
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/network)
1010
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/stargazers)
1111
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/blob/3.0/LICENSE.md)
1212

13+
[![Build Static](https://github.com/dotkernel/dot-auth-social/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml)
14+
15+
[![SymfonyInsight](https://insight.symfony.com/projects/c4aac671-40d7-4590-b1fa-b3e46a1e3f43/big.svg)](https://insight.symfony.com/projects/c4aac671-40d7-4590-b1fa-b3e46a1e3f43)
16+
1317
## Installation
1418

1519
Run the following composer command in your project directory

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
"php": "~8.1.0 || ~8.2.0",
2222
"psr/http-message": "^1.0.1",
2323
"laminas/laminas-servicemanager": "^3.11.2",
24-
"dotkernel/dot-event": "^3.2.0"
24+
"dotkernel/dot-event": "^3.2.0",
25+
"mezzio/mezzio-template": "^2.4.0",
26+
"mezzio/mezzio-helpers": "^5.8.0"
2527
},
2628
"require-dev": {
27-
"mezzio/mezzio-template": "^2.4.0",
28-
"mezzio/mezzio-helpers": "^5.8.0",
2929
"phpunit/phpunit": "^10.2",
3030
"vimeo/psalm": "^5.13",
31-
"laminas/laminas-coding-standard": "^2.5"
31+
"laminas/laminas-coding-standard": "^2.5",
32+
"laminas/laminas-diactoros": "^3.0"
3233
},
3334
"autoload": {
3435
"psr-4": {
@@ -52,6 +53,7 @@
5253
"static-analysis": "psalm --shepherd --stats"
5354
},
5455
"config": {
56+
"sort-packages": true,
5557
"allow-plugins": {
5658
"dealerdirect/phpcodesniffer-composer-installer": true
5759
}

src/AbstractActionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function dispatch(): ResponseInterface
4646
return $response;
4747
}
4848

49-
//just go the the next middleware, it will eventually hit a 404 if no one handles the request
49+
//just go the next middleware, it will eventually hit a 404 if no one handles the request
5050
$handler = $this->getHandler();
5151
return $handler->handle($this->request);
5252
}

src/AbstractController.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ abstract class AbstractController implements
2929
{
3030
use DispatchControllerEventsTrait;
3131

32-
/** @var PluginManager */
33-
protected $pluginManager;
32+
protected ?PluginManager $pluginManager = null;
3433

35-
/** @var ServerRequestInterface */
36-
protected $request;
34+
protected ServerRequestInterface $request;
3735

38-
/** @var RequestHandlerInterface */
39-
protected $handler;
36+
protected RequestHandlerInterface $handler;
4037

41-
/** @var bool */
42-
protected $debug = false;
38+
protected bool $debug = false;
4339

4440
/**
4541
* Transform an "action" token into a method name
@@ -78,11 +74,8 @@ public function getHandler(): RequestHandlerInterface
7874
*
7975
* If the plugin is a functor, call it, passing the parameters provided.
8076
* Otherwise, return the plugin instance.
81-
*
82-
* @param array $params
83-
* @return mixed
8477
*/
85-
public function __call(string $method, array $params)
78+
public function __call(string $method, array $params): mixed
8679
{
8780
$plugin = $this->plugin($method);
8881
if (is_callable($plugin)) {
@@ -93,16 +86,13 @@ public function __call(string $method, array $params)
9386

9487
/**
9588
* Get plugin instance
96-
*
97-
* @param string $name Name of plugin to return
98-
* @param array $options Options to pass to plugin constructor (if not already instantiated)
9989
*/
10090
public function plugin(string $name, array $options = []): PluginInterface|callable
10191
{
10292
return $this->getPluginManager()->get($name, $options);
10393
}
10494

105-
public function getPluginManager(): PluginManager
95+
public function getPluginManager(): ?PluginManager
10696
{
10797
if (! $this->pluginManager) {
10898
throw new RuntimeException(
@@ -118,7 +108,7 @@ public function getPluginManager(): PluginManager
118108
return $this->pluginManager;
119109
}
120110

121-
public function setPluginManager(PluginManager $plugins)
111+
public function setPluginManager(PluginManager $plugins): void
122112
{
123113
$this->pluginManager = $plugins;
124114
}
@@ -128,7 +118,7 @@ public function isDebug(): bool
128118
return $this->debug;
129119
}
130120

131-
public function setDebug(bool $debug)
121+
public function setDebug(bool $debug): void
132122
{
133123
$this->debug = $debug;
134124
}

src/ConfigProvider.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
class ConfigProvider
1313
{
14-
/**
15-
* Returns the configuration array
16-
*
17-
* To add a bit of a structure, each section is defined in a separate
18-
* method which returns an array with its configuration.
19-
*/
2014
public function __invoke(): array
2115
{
2216
return [

src/Event/ControllerEvent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
namespace Dot\Controller\Event;
66

7+
use ArrayAccess;
78
use Dot\Event\Event;
89

10+
/**
11+
* @template TTarget of object|string|null
12+
* @template TParams of array|ArrayAccess|object
13+
* @extends Event<TTarget, TParams>
14+
*/
915
class ControllerEvent extends Event
1016
{
1117
public const EVENT_CONTROLLER_BEFORE_DISPATCH = 'event.controller.beforeDispatch';

src/Event/ControllerEventListenerInterface.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
use Laminas\EventManager\ListenerAggregateInterface;
88

9-
/**
10-
* Interface ActionControllerEventListenerInterface
11-
*/
129
interface ControllerEventListenerInterface extends ListenerAggregateInterface
1310
{
1411
public const LISTEN_ALL = 1;
1512

16-
public function onBeforeDispatch(ControllerEvent $e);
13+
public function onBeforeDispatch(ControllerEvent $e): void;
1714

18-
public function onAfterDispatch(ControllerEvent $e);
15+
public function onAfterDispatch(ControllerEvent $e): void;
1916
}

src/Event/ControllerEventListenerTrait.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait ControllerEventListenerTrait
1414
/**
1515
* @param int $priority
1616
*/
17-
public function attach(EventManagerInterface $events, $priority = 1)
17+
public function attach(EventManagerInterface $events, $priority = 1): void
1818
{
1919
$this->listeners[] = $events->attach(
2020
ControllerEvent::EVENT_CONTROLLER_BEFORE_DISPATCH,
@@ -28,13 +28,11 @@ public function attach(EventManagerInterface $events, $priority = 1)
2828
);
2929
}
3030

31-
public function onBeforeDispatch(ControllerEvent $e)
31+
public function onBeforeDispatch(ControllerEvent $e): void
3232
{
33-
//no-op
3433
}
3534

36-
public function onAfterDispatch(ControllerEvent $e)
35+
public function onAfterDispatch(ControllerEvent $e): void
3736
{
38-
//no-op
3937
}
4038
}

src/Event/DispatchControllerEventsTrait.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ trait DispatchControllerEventsTrait
1414
{
1515
use EventManagerAwareTrait;
1616

17-
/**
18-
* @param array $data
19-
* @param null $target
20-
* @return ControllerEvent|ResponseCollection
21-
*/
22-
public function dispatchEvent(string $name, array $data = [], $target = null)
23-
{
17+
public function dispatchEvent(
18+
string $name,
19+
array $data = [],
20+
object|string|null $target = null
21+
): ControllerEvent|ResponseCollection {
2422
if (! $this instanceof AbstractController) {
2523
throw new RuntimeException('Only controllers can dispatch controller events');
2624
}

src/Exception/ExceptionInterface.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace Dot\Controller\Exception;
66

7-
/**
8-
* Interface ExceptionInterface
9-
*/
107
interface ExceptionInterface
118
{
129
}

0 commit comments

Comments
 (0)