Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor
.DS_Store
composer.lock
/.php_cs.cache
/.phpunit.result.cache
/composer.lock
/vendor/
19 changes: 0 additions & 19 deletions .phan/config.php

This file was deleted.

25 changes: 25 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => false,
'concat_space' => ['spacing' => 'one'],
'function_declaration' => ['closure_function_spacing' => 'none'],
'increment_style' => false,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_separation' => false,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
'yoda_style' => false,
])
->setFinder($finder);

// __END__
// vim: filetype=php
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

cache:
directories:
Expand All @@ -15,9 +16,11 @@ install:

script:
- mkdir -p build/logs
- php ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- ./vendor/bin/psalm --no-progress
- ./vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no
- ./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml

after_script:
- travis_retry php ./vendor/bin/coveralls
- travis_retry php ./vendor/bin/php-coveralls

sudo: false
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
],
"require": {
"emonkak/http-exception": "^2.0",
"emonkak/router": "^0.1",
"php": ">=7.0",
"emonkak/router": "^1.0",
"php": ">=7.1",
"psr/container": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
Expand All @@ -20,8 +20,10 @@
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"satooshi/php-coveralls": "^1.0"
"phpunit/phpunit": "^7.0",
"php-coveralls/php-coveralls": "^2.0",
"friendsofphp/php-cs-fixer": "^2.16",
"vimeo/psalm": "^3.11"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 0 additions & 3 deletions phpbench.json

This file was deleted.

2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite>
<testsuite name="tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
Expand Down
13 changes: 13 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
</projectFiles>
</psalm>
7 changes: 2 additions & 5 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Emonkak\HttpMiddleware;

use Psr\Http\Message\ResponseInterface;
Expand All @@ -14,18 +16,13 @@ class Application implements RequestHandlerInterface
*/
private $middlewares = [];

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$pipeline = new Pipeline($this->middlewares);
return $pipeline->handle($request);
}

/**
* @param MiddlewareInterface $middleware
* @return $this
*/
public function pipe(MiddlewareInterface $middleware): Application
Expand Down
14 changes: 2 additions & 12 deletions src/ErrorLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

class ErrorLogger implements MiddlewareInterface
{
Expand All @@ -19,16 +19,13 @@ class ErrorLogger implements MiddlewareInterface
*/
private $logger;

/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand All @@ -51,10 +48,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
}

/**
* @param HttpExceptionInterface $exception
* @return string
*/
protected function getLogLevel(HttpExceptionInterface $exception): string
{
$statusCode = $exception->getStatusCode();
Expand All @@ -67,9 +60,6 @@ protected function getLogLevel(HttpExceptionInterface $exception): string
}
}

/**
* @return string
*/
protected function getDefaultLogLevel(): string
{
return LogLevel::ERROR;
Expand Down
3 changes: 2 additions & 1 deletion src/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Emonkak\HttpException\NotFoundHttpException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

/**
Expand All @@ -33,7 +34,7 @@ public function __construct(array $middlewares)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
Expand Down
7 changes: 2 additions & 5 deletions src/PostDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@ class PostDispatcher implements MiddlewareInterface
*/
private $container;

/**
* @param ContainerInterface $container
*/
public function __construct(
ContainerInterface $container
) {
$this->container = $container;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$handlerReference = $request->getAttribute('__handler_reference');

if (is_array($handlerReference)) {
list ($class, $method) = $handlerReference;
list($class, $method) = $handlerReference;

$instance = $this->container->get($class);

Expand Down
8 changes: 2 additions & 6 deletions src/PreDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class PreDispatcher implements MiddlewareInterface
*/
private $router;

/**
* @param ResponseFactoryInterface $responseFactory
* @param RouterInterface $router
*/
public function __construct(
ResponseFactoryInterface $responseFactory,
RouterInterface $router
Expand All @@ -38,7 +34,7 @@ public function __construct(
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand All @@ -49,7 +45,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
throw new NotFoundHttpException('No route matches.');
}

list ($handlers, $params) = $match;
list($handlers, $params) = $match;
$method = strtoupper($request->getMethod());

if (isset($handlers[$method])) {
Expand Down
6 changes: 1 addition & 5 deletions src/PredicateDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ class PredicateDecorator implements MiddlewareInterface
*/
private $predicate;

/**
* @param MiddlewareInterface $middleware
* @param callable $predicate
*/
public function __construct(MiddlewareInterface $middleware, callable $predicate)
{
$this->middleware = $middleware;
$this->predicate = $predicate;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand Down
5 changes: 1 addition & 4 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

namespace Emonkak\HttpMiddleware\Tests;

use Emonkak\HttpException\HttpException;
use Emonkak\HttpException\InternalServerErrorHttpException;
use Emonkak\HttpMiddleware\Application;
use Emonkak\HttpMiddleware\Pipeline;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UriInterface;
use Psr\Http\Server\MiddlewareInterface;

/**
* @covers Emonkak\HttpMiddleware\Application
* @covers \Emonkak\HttpMiddleware\Application
*/
class ApplicationTest extends TestCase
{
Expand Down
5 changes: 2 additions & 3 deletions tests/ErrorLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Emonkak\HttpException\HttpException;
use Emonkak\HttpMiddleware\ErrorLogger;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

/**
* @covers Emonkak\HttpMiddleware\ErrorLogger
* @covers \Emonkak\HttpMiddleware\ErrorLogger
*/
class ErrorLoggerTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/PipelineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Psr\Http\Server\MiddlewareInterface;

/**
* @covers Emonkak\HttpMiddleware\Pipeline
* @covers \Emonkak\HttpMiddleware\Pipeline
*/
class PipelineTest extends TestCase
{
Expand Down Expand Up @@ -60,7 +60,7 @@ public function testProcess()
}

/**
* @expectedException Emonkak\HttpException\NotFoundHttpException
* @expectedException \Emonkak\HttpException\NotFoundHttpException
*/
public function testProcessThrowsHttpExceptionInterface()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PostDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Psr\Http\Server\RequestHandlerInterface;

/**
* @covers Emonkak\HttpMiddleware\PostDispatcher
* @covers \Emonkak\HttpMiddleware\PostDispatcher
*/
class PostDispatcherTest extends TestCase
{
Expand Down
Loading