Skip to content
Open
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
24 changes: 24 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "Static Analysis by PHPStan"

on:
pull_request:
push:
branches:
- "master"
jobs:
phpstan-analysis:
name: phpstan static code analysis
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"

- run: |
composer install # install your apps dependencies
composer require staabm/annotate-pull-request-from-checkstyle # install cs2pr
vendor/bin/phpstan analyse --error-format=checkstyle | vendor/bin/cs2pr
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"require-dev": {
"laminas/laminas-diactoros": "^2",
"phpunit/phpunit": "^9",
"laminas/laminas-coding-standard": "~1.0.0"
"laminas/laminas-coding-standard": "~1.0.0",
"phpstan/phpstan": "^0.12.29",
"phpstan/phpstan-phpunit": "^0.12.11"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: max
paths:
- src
6 changes: 2 additions & 4 deletions src/Backbeard/ClosureActionScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

class ClosureActionScope
{
/** @var ServerRequestInterface */
private $request;
/** @var ResponseFactoryInterface */
private $responseFactory;
private ServerRequestInterface $request;
private ResponseFactoryInterface $responseFactory;

public function __construct(ServerRequestInterface $request, ResponseFactoryInterface $responseFactory)
{
Expand Down
20 changes: 7 additions & 13 deletions src/Backbeard/DispatchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,28 @@

namespace Backbeard;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ResponseInterface;
use LogicException;

class DispatchResult implements DispatchResultInterface
{
private $dispatched;
private $response;
private bool $dispatched;
private ?ResponseInterface $response = null;

public function __construct($dispatched, $response = null)
public function __construct(bool $dispatched, ResponseInterface $response = null)
{
$this->dispatched = $dispatched;
$this->response = $response;
}

/**
* @return bool
*/
public function isDispatched()
public function isDispatched() : bool
{
return $this->dispatched;
}

/**
* @return Response;
*/
public function getResponse()
public function getResponse() : ResponseInterface
{
if ($this->response instanceof Response) {
if ($this->response instanceof ResponseInterface) {
return $this->response;
}
throw new LogicException("Don't call when dispatch return false");
Expand Down
12 changes: 4 additions & 8 deletions src/Backbeard/DispatchResultInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

namespace Backbeard;

use Psr\Http\Message\ResponseInterface;

interface DispatchResultInterface
{
/**
* @return bool
*/
public function isDispatched();
public function isDispatched() : bool;

/**
* @return \Psr\Http\Message\ResponseInterface
*/
public function getResponse();
public function getResponse() : ResponseInterface;
}
28 changes: 8 additions & 20 deletions src/Backbeard/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,15 @@

class Dispatcher implements DispatcherInterface
{
/**
* @var Generator
*/
private $routing;
private Generator $routing;

/**
* @var ViewInterface
*/
protected $view;
protected ViewInterface $view;

/**
* @var StringRouterInterface
*/
protected $stringRouter;
protected StringRouterInterface $stringRouter;

/**
* @var ArrayRouterInterface
*/
protected $arrayRouter;
protected ArrayRouterInterface $arrayRouter;

/**
* @var ResponseFactoryInterface
*/
private $responseFactory;
private ResponseFactoryInterface $responseFactory;

public function __construct(Generator $routing, ViewInterface $view, StringRouterInterface $stringRouter, ArrayRouterInterface $arrayRouter = null, ResponseFactoryInterface $responseFactory)
{
Expand Down Expand Up @@ -119,6 +104,9 @@ protected function dispatchRouting($route, ServerRequestInterface $request) : ?R
return $routingResult;
}

/**
* @return null|array<string, string>
*/
protected function dispatchRoutingByType($route, ServerRequestInterface $request) : ?array
{
switch (gettype($route)) {
Expand Down
9 changes: 6 additions & 3 deletions src/Backbeard/Router/ArrayRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

namespace Backbeard\Router;

use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ServerRequestInterface;

class ArrayRouter implements ArrayRouterInterface
{
private $stringRouter;
private StringRouterInterface $stringRouter;

public function __construct(StringRouterInterface $stringRouter)
{
$this->stringRouter = $stringRouter;
}

public function match(array $route, Request $request) : ?array
/**
* @inheritDoc
*/
public function match(array $route, ServerRequestInterface $request) : ?array
{
$httpMethod = key($route);
$stringRoute = current($route);
Expand Down
4 changes: 4 additions & 0 deletions src/Backbeard/Router/ArrayRouterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@

interface ArrayRouterInterface
{
/**
* @param array<string, mixed> $route
* @return null|array<string, string>
*/
public function match(array $route, Request $request) : ?array;
}
7 changes: 5 additions & 2 deletions src/Backbeard/Router/StringRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@

class StringRouter implements StringRouterInterface
{
private $routeParser;
private RouteParser $routeParser;

public function __construct(RouteParser $routeParser)
{
$this->routeParser = $routeParser;
}

public function match($route, $uri) : ?array
/**
* @inheritDoc
*/
public function match(string $route, string $uri) : ?array
{
$routeData = $this->routeParser->parse($route);
list($regex, $params) = $this->buildRegexForRoute(current($routeData));
Expand Down
5 changes: 4 additions & 1 deletion src/Backbeard/Router/StringRouterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

interface StringRouterInterface
{
public function match($route, $uri) : ?array;
/**
* @return null|array<string, string>
*/
public function match(string $route, string $uri) : ?array;
}
18 changes: 4 additions & 14 deletions src/Backbeard/RoutingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,14 @@
*/
class RoutingResult
{
/**
* @var bool
*/
protected $matched;
protected bool $matched;

/**
* Match parameters.
*
* @var array
*/
protected $params = [];
protected array $params = [];

/**
* Matched route name.
*
* @var string
*/
protected $matchedRouteName;
protected ?string $matchedRouteName = null;

/**
* Create a RouteMatch with given parameters.
Expand All @@ -53,7 +43,7 @@ public function setMatchedRouteName(string $name) : void
/**
* Get name of matched route.
*/
public function getMatchedRouteName() : string
public function getMatchedRouteName() : ?string
{
return $this->matchedRouteName;
}
Expand Down
9 changes: 8 additions & 1 deletion src/Backbeard/ValidationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@

class ValidationError implements ActionContinueInterface
{
private $messages;
/** @var iterable<string> */
private iterable $messages;

/**
* @param iterable<string> $messages
*/
public function __construct(iterable $messages)
{
$this->messages = $messages;
}

/**
* @return iterable<string>
*/
public function getMessages() : iterable
{
return $this->messages;
Expand Down
4 changes: 2 additions & 2 deletions src/Backbeard/View/Templating/SfpStreamView.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class SfpStreamView implements ViewInterface
{
use TemplatingViewTrait;

private $streamView;
private $responseFactory;
private StreamView $streamView;
private ResponseFactoryInterface $responseFactory;

public function __construct(StreamView $streamView, ResponseFactoryInterface $responseFactory)
{
Expand Down
13 changes: 7 additions & 6 deletions src/Backbeard/View/Templating/TemplatePathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@

class TemplatePathResolver implements TemplatePathResolverInterface
{
private $suffix = '.phtml';
private string $suffix = '.phtml';

/**
* @return string
*/
public function resolve(RoutingResult $routingResult)
public function resolve(RoutingResult $routingResult) : string
{
$name = $routingResult->getMatchedRouteName();
if ($name === null) {
throw new \LogicException('route not matched');
}

if (strpos(strrev($name), '/') === 0) {
return $name.'index'.$this->suffix;
} else {
return $name.$this->suffix;
}
}

public function setSuffix($suffix)
public function setSuffix(string $suffix) : void
{
$this->suffix = $suffix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

interface TemplatePathResolverInterface
{
public function resolve(RoutingResult $routingResult);
public function resolve(RoutingResult $routingResult) : string ;
}
13 changes: 5 additions & 8 deletions src/Backbeard/View/Templating/TemplatingViewTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@

trait TemplatingViewTrait
{
/**
* @var TemplatePathResolverInterface
*/
private $templatePathResolver;
private ?TemplatePathResolverInterface $templatePathResolver = null;

/**
* @return TemplatePathResolverInterface
*/
public function getTemplatePathResolver()
public function getTemplatePathResolver() : TemplatePathResolverInterface
{
if (! $this->templatePathResolver) {
$this->templatePathResolver = new TemplatePathResolver();
}
return $this->templatePathResolver;
}

/**
* @param array<string, mixed> $vars
*/
public function marshalViewModel(RoutingResult $routingResult, array $vars) : ViewModelInterface
{
$template = $this->getTemplatePathResolver()->resolve($routingResult);
Expand Down
Loading