diff --git a/.gitignore b/.gitignore
index 37a78ec..8e8c373 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
-/vendor
.DS_Store
-composer.lock
+/.php_cs.cache
+/.phpunit.result.cache
+/composer.lock
+/vendor/
diff --git a/.phan/config.php b/.phan/config.php
deleted file mode 100644
index 3a9ab92..0000000
--- a/.phan/config.php
+++ /dev/null
@@ -1,19 +0,0 @@
- [
- 'src',
- 'vendor/container-interop/container-interop',
- 'vendor/emonkak/http-exception',
- 'vendor/emonkak/router',
- 'vendor/http-interop/http-middleware',
- 'vendor/psr/http-message',
- 'vendor/psr/log',
- ],
-
- 'exclude_analysis_directory_list' => [
- 'vendor/',
- ],
-
- 'analyze_signature_compatibility' => false,
-];
diff --git a/.php_cs.dist b/.php_cs.dist
new file mode 100644
index 0000000..6883227
--- /dev/null
+++ b/.php_cs.dist
@@ -0,0 +1,25 @@
+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
diff --git a/.travis.yml b/.travis.yml
index ee486ce..0c4845d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,10 @@
language: php
php:
- - 7.0
- 7.1
- 7.2
+ - 7.3
+ - 7.4
cache:
directories:
@@ -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
diff --git a/composer.json b/composer.json
index ea612d6..4f3f0af 100644
--- a/composer.json
+++ b/composer.json
@@ -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",
@@ -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": {
diff --git a/phpbench.json b/phpbench.json
deleted file mode 100644
index 355f124..0000000
--- a/phpbench.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "bootstrap": "vendor/autoload.php"
-}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index c98b18f..b48a411 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -4,7 +4,7 @@
-
+
./tests/
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..46206b5
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/src/Application.php b/src/Application.php
index e51488e..edeb646 100644
--- a/src/Application.php
+++ b/src/Application.php
@@ -1,5 +1,7 @@
middlewares);
@@ -25,7 +23,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}
/**
- * @param MiddlewareInterface $middleware
* @return $this
*/
public function pipe(MiddlewareInterface $middleware): Application
diff --git a/src/ErrorLogger.php b/src/ErrorLogger.php
index 400396d..72c9cea 100644
--- a/src/ErrorLogger.php
+++ b/src/ErrorLogger.php
@@ -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
{
@@ -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
{
@@ -51,10 +48,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
}
- /**
- * @param HttpExceptionInterface $exception
- * @return string
- */
protected function getLogLevel(HttpExceptionInterface $exception): string
{
$statusCode = $exception->getStatusCode();
@@ -67,9 +60,6 @@ protected function getLogLevel(HttpExceptionInterface $exception): string
}
}
- /**
- * @return string
- */
protected function getDefaultLogLevel(): string
{
return LogLevel::ERROR;
diff --git a/src/Pipeline.php b/src/Pipeline.php
index ac6bb97..1d30a98 100644
--- a/src/Pipeline.php
+++ b/src/Pipeline.php
@@ -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;
/**
@@ -33,7 +34,7 @@ public function __construct(array $middlewares)
}
/**
- * {@inheritDoc}
+ * {@inheritdoc}
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
diff --git a/src/PostDispatcher.php b/src/PostDispatcher.php
index f0f0001..a08e8b6 100644
--- a/src/PostDispatcher.php
+++ b/src/PostDispatcher.php
@@ -17,9 +17,6 @@ class PostDispatcher implements MiddlewareInterface
*/
private $container;
- /**
- * @param ContainerInterface $container
- */
public function __construct(
ContainerInterface $container
) {
@@ -27,14 +24,14 @@ public function __construct(
}
/**
- * {@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);
diff --git a/src/PreDispatcher.php b/src/PreDispatcher.php
index 5f1344f..ea6b91d 100644
--- a/src/PreDispatcher.php
+++ b/src/PreDispatcher.php
@@ -25,10 +25,6 @@ class PreDispatcher implements MiddlewareInterface
*/
private $router;
- /**
- * @param ResponseFactoryInterface $responseFactory
- * @param RouterInterface $router
- */
public function __construct(
ResponseFactoryInterface $responseFactory,
RouterInterface $router
@@ -38,7 +34,7 @@ public function __construct(
}
/**
- * {@inheritDoc}
+ * {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
@@ -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])) {
diff --git a/src/PredicateDecorator.php b/src/PredicateDecorator.php
index bee483c..5312320 100644
--- a/src/PredicateDecorator.php
+++ b/src/PredicateDecorator.php
@@ -21,10 +21,6 @@ class PredicateDecorator implements MiddlewareInterface
*/
private $predicate;
- /**
- * @param MiddlewareInterface $middleware
- * @param callable $predicate
- */
public function __construct(MiddlewareInterface $middleware, callable $predicate)
{
$this->middleware = $middleware;
@@ -32,7 +28,7 @@ public function __construct(MiddlewareInterface $middleware, callable $predicate
}
/**
- * {@inheritDoc}
+ * {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php
index 03ffdef..767c6b2 100644
--- a/tests/ApplicationTest.php
+++ b/tests/ApplicationTest.php
@@ -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
{
diff --git a/tests/ErrorLoggerTest.php b/tests/ErrorLoggerTest.php
index ff78f85..abb193a 100644
--- a/tests/ErrorLoggerTest.php
+++ b/tests/ErrorLoggerTest.php
@@ -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
{
diff --git a/tests/PipelineTest.php b/tests/PipelineTest.php
index ab4c462..7f35e0c 100644
--- a/tests/PipelineTest.php
+++ b/tests/PipelineTest.php
@@ -11,7 +11,7 @@
use Psr\Http\Server\MiddlewareInterface;
/**
- * @covers Emonkak\HttpMiddleware\Pipeline
+ * @covers \Emonkak\HttpMiddleware\Pipeline
*/
class PipelineTest extends TestCase
{
@@ -60,7 +60,7 @@ public function testProcess()
}
/**
- * @expectedException Emonkak\HttpException\NotFoundHttpException
+ * @expectedException \Emonkak\HttpException\NotFoundHttpException
*/
public function testProcessThrowsHttpExceptionInterface()
{
diff --git a/tests/PostDispatcherTest.php b/tests/PostDispatcherTest.php
index 19c501c..94c9b7d 100644
--- a/tests/PostDispatcherTest.php
+++ b/tests/PostDispatcherTest.php
@@ -12,7 +12,7 @@
use Psr\Http\Server\RequestHandlerInterface;
/**
- * @covers Emonkak\HttpMiddleware\PostDispatcher
+ * @covers \Emonkak\HttpMiddleware\PostDispatcher
*/
class PostDispatcherTest extends TestCase
{
diff --git a/tests/PreDispatcherTest.php b/tests/PreDispatcherTest.php
index e8fd3a0..3f07c5a 100644
--- a/tests/PreDispatcherTest.php
+++ b/tests/PreDispatcherTest.php
@@ -7,7 +7,6 @@
use Emonkak\HttpMiddleware\PreDispatcher;
use Emonkak\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
-use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
@@ -15,12 +14,12 @@
use Psr\Http\Server\RequestHandlerInterface;
/**
- * @covers Emonkak\HttpMiddleware\PreDispatcher
+ * @covers \Emonkak\HttpMiddleware\PreDispatcher
*/
class PreDispatcherTest extends TestCase
{
/**
- * @expectedException Emonkak\HttpException\NotFoundHttpException
+ * @expectedException \Emonkak\HttpException\NotFoundHttpException
*/
public function testNotMatched()
{
@@ -87,7 +86,7 @@ public function testHeadRequest()
->with($path)
->willReturn([
['HEAD' => DispatcherTestMiddleware::class],
- ['foo_id' => '123', 'bar_id' => '456']
+ ['foo_id' => '123', 'bar_id' => '456'],
]);
$dispatcher = new PreDispatcher($responseFactory, $router);
@@ -130,7 +129,7 @@ public function testHeadRequestWithFallback()
->with($path)
->willReturn([
['GET' => DispatcherTestMiddleware::class],
- ['foo_id' => '123', 'bar_id' => '456']
+ ['foo_id' => '123', 'bar_id' => '456'],
]);
$dispatcher = new PreDispatcher($responseFactory, $router);
@@ -155,7 +154,7 @@ public function testOptionsRequest()
$response
->expects($this->once())
->method('withHeader')
- ->with($this->identicalTo('Allow'), $this->identicalTo('GET, HEAD, OPTIONS'))
+ ->with($this->identicalTo('Allow'), $this->identicalTo('GET, HEAD, OPTIONS'))
->will($this->returnSelf());
$responseFactory = $this->createMock(ResponseFactoryInterface::class);
@@ -172,7 +171,7 @@ public function testOptionsRequest()
->with($path)
->willReturn([
['GET' => DispatcherTestMiddleware::class],
- ['foo_id' => '123', 'bar_id' => '456']
+ ['foo_id' => '123', 'bar_id' => '456'],
]);
$dispatcher = new PreDispatcher($responseFactory, $router);
@@ -181,7 +180,7 @@ public function testOptionsRequest()
}
/**
- * @expectedException Emonkak\HttpException\MethodNotAllowedHttpException
+ * @expectedException \Emonkak\HttpException\MethodNotAllowedHttpException
*/
public function testMethodNotAllowed()
{
@@ -208,7 +207,7 @@ public function testMethodNotAllowed()
->with($path)
->willReturn([
['GET' => DispatcherTestMiddleware::class],
- ['foo_id' => 123, 'bar_id' => 456]
+ ['foo_id' => 123, 'bar_id' => 456],
]);
$dispatcher = new PreDispatcher($responseFactory, $router);
diff --git a/tests/PredicateDecoratorTest.php b/tests/PredicateDecoratorTest.php
index 1e8c530..5158f36 100644
--- a/tests/PredicateDecoratorTest.php
+++ b/tests/PredicateDecoratorTest.php
@@ -12,7 +12,7 @@
use Psr\Http\Server\RequestHandlerInterface;
/**
- * @covers Emonkak\HttpMiddleware\PredicateDecorator
+ * @covers \Emonkak\HttpMiddleware\PredicateDecorator
*/
class PredicateDecoratorTest extends TestCase
{