Skip to content

Commit

Permalink
Implement HandlerInterface to PSR-15 wrappers (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin authored May 23, 2024
1 parent aabad47 commit 32fb82c
Show file tree
Hide file tree
Showing 28 changed files with 46 additions and 60 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

All notable changes to `Slytherin` will be documented in this file.

## [0.9.8](https://github.com/rougin/slytherin/compare/v0.9.7...v0.9.8) - Unreleased
## [0.9.8](https://github.com/rougin/slytherin/compare/v0.9.7...v0.9.8) - 2024-05-23

### Added
- `phpcsfixer.php` as custom rules for the `friendsofphp/php-cs-fixer` package
- Test cases for the complete code coverage after running `friendsofphp/php-cs-fixer`
- `@deprecated` notices for specified classes from previous versions
- `HandlerInterface` for all wrapper variants of `PSR-15` middlewares

### Changed
- `Router::__construct` supports adding `RouteInterface` in the array
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ parameters:
- tests
excludePaths:
analyse:
- src/Middleware/Handlers
- src/Middleware/Interop.php
- src/Middleware/Handlers
- src/Middleware/Interop.php
22 changes: 10 additions & 12 deletions phpstyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$paths[] = realpath(__DIR__ . '/tests');
// --------------------------------------

// Specify the rules for code formatting ---------
// Specify the rules for code formatting ---
$rules = array('@PSR12' => true);

$cscp = 'control_structure_continuation_position';
Expand All @@ -18,11 +18,8 @@
$braces['anonymous_classes_opening_brace'] = 'next_line_unless_newline_at_signature_end';
$braces['allow_single_line_empty_anonymous_classes'] = false;
$braces['allow_single_line_anonymous_functions'] = false;
$rules['braces_position'] = $braces;

$visibility = array('elements' => array());
$visibility['elements'] = array('method', 'property');
$rules['visibility_required'] = $visibility;
$rules['braces_position'] = $braces;

$rules['phpdoc_var_annotation_correct_order'] = true;

Expand All @@ -34,9 +31,11 @@

$rules['trim_array_spaces'] = true;

$order = ['case_sensitive' => true];
$order['null_adjustment'] = 'always_last';
$rules['phpdoc_types_order'] = $order;
$visibility = array('elements' => array());
$visibility['elements'] = array('method', 'property');
$rules['visibility_required'] = $visibility;

$rules['phpdoc_types_order'] = ['null_adjustment' => 'always_last'];

$rules['new_with_parentheses'] = ['named_class' => false];

Expand All @@ -46,12 +45,11 @@

$groups = [];
$groups[] = ['deprecated', 'link', 'see', 'since'];
$groups[] = ['property', 'property-read', 'property-write'];
$groups[] = ['method'];
$groups[] = ['author', 'copyright', 'license'];
$groups[] = ['category', 'package', 'subpackage'];
$groups[] = ['property', 'property-read', 'property-write'];
$groups[] = ['param'];
$groups[] = ['return'];
$groups[] = ['return', 'throws'];
$rules['phpdoc_separation'] = ['groups' => $groups];

$align = ['align' => 'vertical'];
Expand All @@ -61,7 +59,7 @@
$rules['statement_indentation'] = false;

$rules['align_multiline_comment'] = true;
// -----------------------------------------------
// -----------------------------------------

$finder = new \PhpCsFixer\Finder;

Expand Down
1 change: 0 additions & 1 deletion src/Container/AurynContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function add($id, $concrete = null)
* @param string $id
*
* @return mixed
*
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \Psr\Container\ContainerExceptionInterface
*/
Expand Down
1 change: 0 additions & 1 deletion src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function alias($id, $original)
* @param string $id
*
* @return mixed
*
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \Psr\Container\ContainerExceptionInterface
*/
Expand Down
1 change: 0 additions & 1 deletion src/Container/ReflectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __construct(PsrContainer $container = null)
* @param string $id
*
* @return mixed
*
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \Psr\Container\ContainerExceptionInterface
*
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/WhoopsErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function display()
*
* Sets a handler.
*
* @param \Whoops\Handler\HandlerInterface|callable $handler
* @param callable|\Whoops\Handler\HandlerInterface $handler
*
* @return void
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Http/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public function hasHeader($name)
* @param string|string[] $value
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withAddedHeader($name, $value)
Expand Down Expand Up @@ -168,7 +167,6 @@ public function withAddedHeader($name, $value)
* @param \Psr\Http\Message\StreamInterface $body
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withBody(StreamInterface $body)
Expand All @@ -187,7 +185,6 @@ public function withBody(StreamInterface $body)
* @param string|string[] $value
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withHeader($name, $value)
Expand Down
1 change: 0 additions & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function getUri()
* @param string $method
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withMethod($method)
Expand Down
1 change: 0 additions & 1 deletion src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function getStatusCode()
* @param string $reason
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withStatus($code, $reason = '')
Expand Down
2 changes: 0 additions & 2 deletions src/Http/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public function withCookieParams(array $cookies)
* @param array<string, mixed>|object|null $data
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withParsedBody($data)
Expand Down Expand Up @@ -247,7 +246,6 @@ public function withQueryParams(array $query)
* @param array<string, \Psr\Http\Message\UploadedFileInterface[]> $uploaded
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withUploadedFiles(array $uploaded)
Expand Down
6 changes: 0 additions & 6 deletions src/Http/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function eof()
* Returns the remaining contents in a string
*
* @return string
*
* @throws \RuntimeException
*/
public function getContents()
Expand Down Expand Up @@ -215,7 +214,6 @@ public function isWritable()
* @param int<0, max> $length
*
* @return string
*
* @throws \RuntimeException
*/
public function read($length)
Expand All @@ -241,7 +239,6 @@ public function read($length)
* Seek to the beginning of the stream.
*
* @return void
*
* @throws \RuntimeException
*/
public function rewind()
Expand All @@ -256,7 +253,6 @@ public function rewind()
* @param integer $whence
*
* @return void
*
* @throws \RuntimeException
*/
public function seek($offset, $whence = SEEK_SET)
Expand All @@ -277,7 +273,6 @@ public function seek($offset, $whence = SEEK_SET)
* Returns the current position of the file read/write pointer.
*
* @return integer
*
* @throws \RuntimeException
*/
public function tell()
Expand All @@ -302,7 +297,6 @@ public function tell()
* @param string $string
*
* @return integer
*
* @throws \RuntimeException
*/
public function write($string)
Expand Down
2 changes: 0 additions & 2 deletions src/Http/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public function getSize()
* Retrieves a stream representing the uploaded file.
*
* @return \Psr\Http\Message\StreamInterface
*
* @throws \RuntimeException
*/
public function getStream()
Expand All @@ -134,7 +133,6 @@ public function getStream()
* @param string $target
*
* @return void
*
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
Expand Down
5 changes: 0 additions & 5 deletions src/Http/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public function withFragment($fragment)
* @param string $host
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withHost($host)
Expand All @@ -228,7 +227,6 @@ public function withHost($host)
* @param string $path
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withPath($path)
Expand All @@ -248,7 +246,6 @@ public function withPath($path)
* @param integer|null $port
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withPort($port)
Expand All @@ -268,7 +265,6 @@ public function withPort($port)
* @param string $query
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withQuery($query)
Expand All @@ -288,7 +284,6 @@ public function withQuery($query)
* @param string $scheme
*
* @return static
*
* @throws \InvalidArgumentException
*/
public function withScheme($scheme)
Expand Down
14 changes: 12 additions & 2 deletions src/Middleware/Handlers/Handler030.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @codeCoverageIgnore
*/
class Handler030 implements DelegateInterface
class Handler030 implements DelegateInterface, HandlerInterface
{
/**
* @var \Rougin\Slytherin\Middleware\HandlerInterface
Expand Down Expand Up @@ -48,8 +48,18 @@ public function __invoke(ServerRequestInterface $request)
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function process(RequestInterface $request)
public function handle(RequestInterface $request)
{
return $this->handler->handle($request);
}

/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function process(RequestInterface $request)
{
return $this->handle($request);
}
}
14 changes: 12 additions & 2 deletions src/Middleware/Handlers/Handler041.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @codeCoverageIgnore
*/
class Handler041 implements DelegateInterface
class Handler041 implements DelegateInterface, HandlerInterface
{
/**
* @var \Rougin\Slytherin\Middleware\HandlerInterface
Expand Down Expand Up @@ -47,8 +47,18 @@ public function __invoke(ServerRequestInterface $request)
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function process(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request)
{
return $this->handler->handle($request);
}

/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function process(ServerRequestInterface $request)
{
return $this->handle($request);
}
}
2 changes: 1 addition & 1 deletion src/Middleware/Handlers/Handler050.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @codeCoverageIgnore
*/
class Handler050 implements RequestHandlerInterface
class Handler050 implements RequestHandlerInterface, HandlerInterface
{
/**
* @var \Rougin\Slytherin\Middleware\HandlerInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/Handlers/Handler100.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @codeCoverageIgnore
*/
class Handler100 implements RequestHandlerInterface
class Handler100 implements RequestHandlerInterface, HandlerInterface
{
/**
* @var \Rougin\Slytherin\Middleware\HandlerInterface
Expand Down
3 changes: 0 additions & 3 deletions src/Routing/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function __construct(RouterInterface $router = null)
* @param string $uri
*
* @return \Rougin\Slytherin\Routing\RouteInterface
*
* @throws \BadMethodCallException
*/
public function dispatch($method, $uri)
Expand Down Expand Up @@ -85,7 +84,6 @@ public function dispatch($method, $uri)
* @param \Rougin\Slytherin\Routing\RouterInterface $router
*
* @return self
*
* @throws \UnexpectedValueException
*/
public function setRouter(RouterInterface $router)
Expand All @@ -101,7 +99,6 @@ public function setRouter(RouterInterface $router)
* @param string $method
*
* @return boolean
*
* @throws \BadMethodCallException
*/
protected function validMethod($method)
Expand Down
2 changes: 0 additions & 2 deletions src/Routing/DispatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface DispatcherInterface
* @param string $uri
*
* @return \Rougin\Slytherin\Routing\RouteInterface
*
* @throws \BadMethodCallException
*/
public function dispatch($method, $uri);
Expand All @@ -31,7 +30,6 @@ public function dispatch($method, $uri);
* @param \Rougin\Slytherin\Routing\RouterInterface $router
*
* @return self
*
* @throws \UnexpectedValueException
*/
public function setRouter(RouterInterface $router);
Expand Down
Loading

0 comments on commit 32fb82c

Please sign in to comment.