diff --git a/config/autoload/global.php b/config/autoload/global.php index 31d507b..8a2665c 100644 --- a/config/autoload/global.php +++ b/config/autoload/global.php @@ -6,4 +6,4 @@ 'view_manager' => [ 'base_path' => '/', ], -]; \ No newline at end of file +]; diff --git a/config/autoload/mezzio-tooling-factories.global.php b/config/autoload/mezzio-tooling-factories.global.php index 9a4b9ab..5002773 100644 --- a/config/autoload/mezzio-tooling-factories.global.php +++ b/config/autoload/mezzio-tooling-factories.global.php @@ -10,6 +10,4 @@ declare(strict_types=1); -return [ - -]; +return []; diff --git a/src/App/src/ConfigProvider.php b/src/App/src/ConfigProvider.php index 3da5d70..ca2846c 100644 --- a/src/App/src/ConfigProvider.php +++ b/src/App/src/ConfigProvider.php @@ -27,7 +27,7 @@ public function getDependencies(): array { return [ 'invokables' => [ - Handler\PingHandler::class => Handler\PingHandler::class, + Handler\PingHandler::class => Handler\PingHandler::class, Container\HttpClientFactoryFactory::class => Container\HttpClientFactoryFactory::class, ], 'factories' => [ diff --git a/src/App/src/Container/AboutHandlerFactory.php b/src/App/src/Container/AboutHandlerFactory.php index aea957e..e2a819b 100644 --- a/src/App/src/Container/AboutHandlerFactory.php +++ b/src/App/src/Container/AboutHandlerFactory.php @@ -10,7 +10,7 @@ class AboutHandlerFactory { - public function __invoke(ContainerInterface $container) : AboutHandler + public function __invoke(ContainerInterface $container): AboutHandler { return new AboutHandler($container->get(TemplateRendererInterface::class)); } diff --git a/src/App/src/Container/CommunityHandlerFactory.php b/src/App/src/Container/CommunityHandlerFactory.php index a8ca9c5..c4a2fcd 100644 --- a/src/App/src/Container/CommunityHandlerFactory.php +++ b/src/App/src/Container/CommunityHandlerFactory.php @@ -10,7 +10,7 @@ class CommunityHandlerFactory { - public function __invoke(ContainerInterface $container) : CommunityHandler + public function __invoke(ContainerInterface $container): CommunityHandler { return new CommunityHandler($container->get(TemplateRendererInterface::class)); } diff --git a/src/App/src/Container/DocsHandlerFactory.php b/src/App/src/Container/DocsHandlerFactory.php index 9344aa9..0a9913c 100644 --- a/src/App/src/Container/DocsHandlerFactory.php +++ b/src/App/src/Container/DocsHandlerFactory.php @@ -10,7 +10,7 @@ class DocsHandlerFactory { - public function __invoke(ContainerInterface $container) : DocsHandler + public function __invoke(ContainerInterface $container): DocsHandler { return new DocsHandler($container->get(TemplateRendererInterface::class)); } diff --git a/src/App/src/Container/GithubRepoDataMiddlewareFactory.php b/src/App/src/Container/GithubRepoDataMiddlewareFactory.php index 438f241..1a8da19 100644 --- a/src/App/src/Container/GithubRepoDataMiddlewareFactory.php +++ b/src/App/src/Container/GithubRepoDataMiddlewareFactory.php @@ -10,7 +10,7 @@ class GithubRepoDataMiddlewareFactory { - public function __invoke(ContainerInterface $container) : GithubRepoDataMiddleware + public function __invoke(ContainerInterface $container): GithubRepoDataMiddleware { return new GithubRepoDataMiddleware( $container->get(HttpClientFactoryFactory::class), diff --git a/src/App/src/Container/HttpClientFactoryFactory.php b/src/App/src/Container/HttpClientFactoryFactory.php index f60e37f..95e4d44 100644 --- a/src/App/src/Container/HttpClientFactoryFactory.php +++ b/src/App/src/Container/HttpClientFactoryFactory.php @@ -5,8 +5,10 @@ namespace App\Container; use GuzzleHttp\Client; -use GuzzleHttp\HandlerStack; use GuzzleHttp\Handler\StreamHandler; +use GuzzleHttp\HandlerStack; + +use function array_merge; final class HttpClientFactoryFactory { @@ -15,7 +17,7 @@ public function __invoke(): callable return static function (?array $config = null, bool $stream = true): Client { if ($stream) { $handler = HandlerStack::create(new StreamHandler()); - $config = $config ? array_merge($config, ['handler' => $handler]) : ['handler' => $handler]; + $config = $config ? array_merge($config, ['handler' => $handler]) : ['handler' => $handler]; } return empty($config) ? new Client() : new Client($config); }; diff --git a/src/App/src/GithubRequestSpecProvider.php b/src/App/src/GithubRequestSpecProvider.php index a7fc70d..bce13eb 100644 --- a/src/App/src/GithubRequestSpecProvider.php +++ b/src/App/src/GithubRequestSpecProvider.php @@ -10,7 +10,6 @@ public function __invoke(): array { return [ Endpoint::Repo->value => $this->getRepoRequestConfig(), - ]; } diff --git a/src/App/src/Handler/AboutHandler.php b/src/App/src/Handler/AboutHandler.php index 6b51e2b..67dfc42 100644 --- a/src/App/src/Handler/AboutHandler.php +++ b/src/App/src/Handler/AboutHandler.php @@ -4,17 +4,15 @@ namespace App\Handler; +use Laminas\Diactoros\Response\HtmlResponse; +use Mezzio\Template\TemplateRendererInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; -use Laminas\Diactoros\Response\HtmlResponse; -use Mezzio\Template\TemplateRendererInterface; class AboutHandler implements RequestHandlerInterface { - /** - * @var TemplateRendererInterface - */ + /** @var TemplateRendererInterface */ private $renderer; public function __construct(TemplateRendererInterface $renderer) @@ -22,7 +20,7 @@ public function __construct(TemplateRendererInterface $renderer) $this->renderer = $renderer; } - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { // Do some work... // Render and return a response: diff --git a/src/App/src/Handler/CommunityHandler.php b/src/App/src/Handler/CommunityHandler.php index dd430ea..205e684 100644 --- a/src/App/src/Handler/CommunityHandler.php +++ b/src/App/src/Handler/CommunityHandler.php @@ -4,17 +4,15 @@ namespace App\Handler; +use Laminas\Diactoros\Response\HtmlResponse; +use Mezzio\Template\TemplateRendererInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; -use Laminas\Diactoros\Response\HtmlResponse; -use Mezzio\Template\TemplateRendererInterface; class CommunityHandler implements RequestHandlerInterface { - /** - * @var TemplateRendererInterface - */ + /** @var TemplateRendererInterface */ private $renderer; public function __construct(TemplateRendererInterface $renderer) @@ -22,7 +20,7 @@ public function __construct(TemplateRendererInterface $renderer) $this->renderer = $renderer; } - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { // Do some work... // Render and return a response: diff --git a/src/App/src/Handler/ProjectsHandler.php b/src/App/src/Handler/ProjectsHandler.php index ebc2854..b41ff6b 100644 --- a/src/App/src/Handler/ProjectsHandler.php +++ b/src/App/src/Handler/ProjectsHandler.php @@ -4,17 +4,15 @@ namespace App\Handler; +use Laminas\Diactoros\Response\HtmlResponse; +use Mezzio\Template\TemplateRendererInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; -use Laminas\Diactoros\Response\HtmlResponse; -use Mezzio\Template\TemplateRendererInterface; class ProjectsHandler implements RequestHandlerInterface { - /** - * @var TemplateRendererInterface $renderer - */ + /** @var TemplateRendererInterface $renderer */ private $renderer; public function __construct(TemplateRendererInterface $renderer) @@ -22,7 +20,7 @@ public function __construct(TemplateRendererInterface $renderer) $this->renderer = $renderer; } - public function handle(ServerRequestInterface $request) : ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { $githubRepoData = $request->getAttribute('github-repo-data'); return new HtmlResponse($this->renderer->render( diff --git a/src/App/src/Iterator/GithubRepoResponseFilterIterator.php b/src/App/src/Iterator/GithubRepoResponseFilterIterator.php index d6f1348..74009f0 100644 --- a/src/App/src/Iterator/GithubRepoResponseFilterIterator.php +++ b/src/App/src/Iterator/GithubRepoResponseFilterIterator.php @@ -8,6 +8,7 @@ use FilterIterator; use Iterator; +use function in_array; use function str_contains; final class GithubRepoResponseFilterIterator extends FilterIterator @@ -23,6 +24,14 @@ public function accept(): bool { $provider = new GithubRequestSpecProvider(); $current = $this->getInnerIterator()->current(); - return ! str_contains($current['name'], $this->nameNeedle) && ! in_array($current['name'], $provider->getExcludedRepos(), true); + return ! str_contains( + $current['name'], + $this->nameNeedle + ) + && ! in_array( + $current['name'], + $provider->getExcludedRepos(), + true + ); } } diff --git a/src/App/src/Middleware/GithubRepoDataMiddleware.php b/src/App/src/Middleware/GithubRepoDataMiddleware.php index cdbeaf0..1ecf59f 100644 --- a/src/App/src/Middleware/GithubRepoDataMiddleware.php +++ b/src/App/src/Middleware/GithubRepoDataMiddleware.php @@ -7,15 +7,20 @@ use App\Endpoint; use App\Iterator\GithubRepoResponseFilterIterator; use ArrayIterator; +use GuzzleHttp\Client; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use function array_merge; +use function json_decode; + +use const JSON_THROW_ON_ERROR; class GithubRepoDataMiddleware implements MiddlewareInterface { + /** @var callable $clientFactory */ private $clientFactory; public function __construct( @@ -25,17 +30,18 @@ public function __construct( $this->clientFactory = $clientFactory; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $clientConfig = array_merge($this->config[Endpoint::Repo->value], ['headers' => $this->config['headers']]); - $client = (($this->clientFactory)())($clientConfig); - $response = $client->get(Endpoint::Repo->value); - $data = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR); - $filter = new GithubRepoResponseFilterIterator(new ArrayIterator($data)); + /** @var Client $client */ + $client = (($this->clientFactory)())($clientConfig); + $response = $client->get(Endpoint::Repo->value); + $data = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR); + $filter = new GithubRepoResponseFilterIterator(new ArrayIterator($data)); foreach ($filter as $item) { $filteredData[] = $item; } - $request = $request->withAttribute('github-repo-data', $filteredData); + $request = $request->withAttribute('github-repo-data', $filteredData); return $handler->handle($request); } } diff --git a/test/AppTest/Handler/HomePageHandlerFactoryTest.php b/test/AppTest/Handler/HomeHandlerFactoryTest.php similarity index 69% rename from test/AppTest/Handler/HomePageHandlerFactoryTest.php rename to test/AppTest/Handler/HomeHandlerFactoryTest.php index 40cd9d9..75ac175 100644 --- a/test/AppTest/Handler/HomePageHandlerFactoryTest.php +++ b/test/AppTest/Handler/HomeHandlerFactoryTest.php @@ -4,24 +4,24 @@ namespace AppTest\Handler; -use App\Handler\HomePageHandler; -use App\Handler\HomePageHandlerFactory; +use App\Container\HomeHandlerFactory; +use App\Handler\HomeHandler; use AppTest\InMemoryContainer; use Mezzio\Router\RouterInterface; use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\TestCase; -final class HomePageHandlerFactoryTest extends TestCase +final class HomeHandlerFactoryTest extends TestCase { public function testFactoryWithoutTemplate(): void { $container = new InMemoryContainer(); $container->setService(RouterInterface::class, $this->createMock(RouterInterface::class)); - $factory = new HomePageHandlerFactory(); + $factory = new HomeHandlerFactory(); $homePage = $factory($container); - self::assertInstanceOf(HomePageHandler::class, $homePage); + self::assertInstanceOf(HomeHandler::class, $homePage); } public function testFactoryWithTemplate(): void @@ -30,9 +30,9 @@ public function testFactoryWithTemplate(): void $container->setService(RouterInterface::class, $this->createMock(RouterInterface::class)); $container->setService(TemplateRendererInterface::class, $this->createMock(TemplateRendererInterface::class)); - $factory = new HomePageHandlerFactory(); + $factory = new HomeHandlerFactory(); $homePage = $factory($container); - self::assertInstanceOf(HomePageHandler::class, $homePage); + self::assertInstanceOf(HomeHandler::class, $homePage); } } diff --git a/test/AppTest/Handler/HomePageHandlerTest.php b/test/AppTest/Handler/HomeHandlerTest.php similarity index 55% rename from test/AppTest/Handler/HomePageHandlerTest.php rename to test/AppTest/Handler/HomeHandlerTest.php index 494e6f5..5715ae1 100644 --- a/test/AppTest/Handler/HomePageHandlerTest.php +++ b/test/AppTest/Handler/HomeHandlerTest.php @@ -4,39 +4,35 @@ namespace AppTest\Handler; -use App\Handler\HomePageHandler; +use App\Handler\HomeHandler; use Laminas\Diactoros\Response\HtmlResponse; use Laminas\Diactoros\Response\JsonResponse; -use Mezzio\Router\RouterInterface; use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; -final class HomePageHandlerTest extends TestCase +final class HomeHandlerTest extends TestCase { - /** @var ContainerInterface&MockObject */ - protected $container; + /** @var ServerRequestInterface&MockObject */ + protected $request; - /** @var RouterInterface&MockObject */ - protected $router; + /** @var TemplateRendererInterface&MockObject */ + protected $renderer; protected function setUp(): void { - $this->container = $this->createMock(ContainerInterface::class); - $this->router = $this->createMock(RouterInterface::class); + $this->request = $this->createMock(ServerRequestInterface::class); + $this->renderer = $this->createMock(TemplateRendererInterface::class); } public function testReturnsJsonResponseWhenNoTemplateRendererProvided(): void { - $homePage = new HomePageHandler( - $this->container::class, - $this->router, + $homePage = new HomeHandler( null ); $response = $homePage->handle( - $this->createMock(ServerRequestInterface::class) + $this->request ); self::assertInstanceOf(JsonResponse::class, $response); @@ -44,21 +40,20 @@ public function testReturnsJsonResponseWhenNoTemplateRendererProvided(): void public function testReturnsHtmlResponseWhenTemplateRendererProvided(): void { + /** @var TemplateRendererInterface&MockObject $renderer */ $renderer = $this->createMock(TemplateRendererInterface::class); $renderer ->expects($this->once()) ->method('render') - ->with('app::home-page', $this->isType('array')) + ->with('app::home', $this->isType('array')) ->willReturn(''); - $homePage = new HomePageHandler( - $this->container::class, - $this->router, + $homePage = new HomeHandler( $renderer ); $response = $homePage->handle( - $this->createMock(ServerRequestInterface::class) + $this->request ); self::assertInstanceOf(HtmlResponse::class, $response);