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
16 changes: 8 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
* text=auto eol=lf

/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php-cs-fixer.php export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
.phpstan.neon export-ignore
35 changes: 16 additions & 19 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: "testing"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
qa:
Expand All @@ -20,16 +20,16 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress

- name: Coding Standard
run: composer run-script cs
Expand All @@ -40,11 +40,11 @@ jobs:

strategy:
matrix:
php:
- 8.1
- 8.2
- 8.3
- 8.4
php:
- 8.1
- 8.2
- 8.3
- 8.4

steps:
- name: Checkout
Expand All @@ -63,10 +63,7 @@ jobs:
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress

- name: Tests
run: composer test

- name: Tests coverage
run: composer coverage
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ vendor
composer.lock
coverage
*.cache
.idea
kit
33 changes: 33 additions & 0 deletions .phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
parameters:
ignoreErrors:
-
identifier: "new.static"
-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: src/Factory.php

-
message: "#^Method Middlewares\\\\Utils\\\\FactoryDiscovery\\:\\:getFactory\\(\\) has no return type specified\\.$#"
count: 1
path: src/FactoryDiscovery.php

-
message: "#^Parameter \\#1 \\$class of function class_exists expects string, array\\<string, class\\-string\\>\\|string given\\.$#"
count: 1
path: src/FactoryDiscovery.php

-
message: "#^Property Middlewares\\\\Utils\\\\FactoryDiscovery\\:\\:\\$factory has no type specified\\.$#"
count: 1
path: src/FactoryDiscovery.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/HttpErrorException.php

-
message: "#^Method Middlewares\\\\Utils\\\\RequestHandlerContainer\\:\\:resolve\\(\\) has no return type specified\\.$#"
count: 1
path: src/RequestHandlerContainer.php
11 changes: 11 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: false
inferPrivatePropertyTypeFromConstructor: true
level: 8
paths:
- src
- tests

includes:
- .phpstan-baseline.neon
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019
Copyright (c) 2019-2025

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"require": {
"php": ">=8.1",
"psr/http-message": "^1.0 || ^2.0",
"psr/http-server-middleware": "^1.0",
"psr/http-server-middleware": "^1",
"psr/container": "^1.0 || ^2.0",
"psr/http-factory": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^10.5",
"phpstan/phpstan": "^1.10",
"laminas/laminas-diactoros": "^3.3",
"friendsofphp/php-cs-fixer": "^3.41",
"oscarotero/php-cs-fixer-config": "^2.0",
"squizlabs/php_codesniffer": "^3.8",
"phpunit/phpunit": "^10",
"phpstan/phpstan": "^2",
"laminas/laminas-diactoros": "^3",
"friendsofphp/php-cs-fixer": "^3",
"oscarotero/php-cs-fixer-config": "^2",
"squizlabs/php_codesniffer": "^3",
"slim/psr7": "^1.6",
"guzzlehttp/psr7": "^2.6",
"sunrise/http-message": "^3.0",
Expand All @@ -52,4 +52,4 @@
"coverage": "phpunit --coverage-text",
"coverage-html": "phpunit --coverage-html=coverage"
}
}
}
16 changes: 16 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<ruleset name="Middlewares coding standard">
<description>Middlewares coding standard</description>

<!-- display progress -->
<arg value="p"/>
<arg name="report" value="full"/>
<arg name="colors"/>

<!-- coding standard -->
<rule ref="PSR2"/>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>
</ruleset>
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" beStrictAboutOutputDuringTests="true" colors="true" failOnWarning="true" cacheDirectory=".phpunit.cache">
<coverage/>
<testsuites>
<testsuite name="Skeleton test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions src/CallableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function __invoke(): ResponseInterface

/**
* Execute the callable.
*
* @param array<int,ServerRequestInterface|RequestHandlerInterface> $arguments
*/
private function execute(array $arguments = []): ResponseInterface
{
Expand Down
6 changes: 5 additions & 1 deletion src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

class Dispatcher implements RequestHandlerInterface
{
/** @var array */
private $stack;

/**
* Static helper to create and dispatch a request.
*
* @param CallableHandler[]|MiddlewareInterface[]|callable[] $stack
*/
public static function run(array $stack, ?ServerRequestInterface $request = null): ResponseInterface
{
Expand All @@ -27,6 +28,9 @@ public static function run(array $stack, ?ServerRequestInterface $request = null
return (new static($stack))->dispatch($request);
}

/**
* @param CallableHandler[]|MiddlewareInterface[]|callable[] $stack
*/
public function __construct(array $stack)
{
$this->stack = $stack;
Expand Down
3 changes: 2 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public static function getServerRequestFactory(): ServerRequestFactoryInterface
}

/**
* @param UriInterface|string $uri
* @param UriInterface|string $uri
* @param array<string, string> $serverParams
*/
public static function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
{
Expand Down
10 changes: 6 additions & 4 deletions src/FactoryDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FactoryDiscovery implements FactoryInterface
'uri' => '\Sunrise\Http\Message\UriFactory',
];

/** @var array<array<string, class-string>|string> */
/** @var array<mixed> */
private $strategies = [
self::DIACTOROS,
self::GUZZLE,
Expand All @@ -63,11 +63,11 @@ class FactoryDiscovery implements FactoryInterface

private $factory;

/** @var array */
/** @var array<string, mixed> */
private $factories = [];

/**
* @param array $strategies
* @param array<mixed> $strategies
*/
public function __construct(...$strategies)
{
Expand All @@ -78,6 +78,8 @@ public function __construct(...$strategies)

/**
* Get the strategies
*
* @return array<mixed>
*/
public function getStrategies(): array
{
Expand Down Expand Up @@ -160,14 +162,14 @@ private function getFactory(string $type)
foreach ($this->strategies as $className) {
if (is_array($className) && isset($className[$type])) {
$className = $className[$type];

if (class_exists($className)) {
return $this->factories[$type] = new $className();
}

continue;
}

/* @phpstan-ignore-next-line */
if (!class_exists($className)) {
continue;
}
Expand Down
8 changes: 6 additions & 2 deletions src/HttpErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ class HttpErrorException extends Exception
599 => 'Network Connect Timeout Error',
];

/** @var array */
/** @var array<string, mixed> */
private $context = [];

/**
* Create and returns a new instance
*
* @param int $code A valid http error code
* @param int $code A valid http error code
* @param array<string,mixed> $context
*/
public static function create(int $code = 500, array $context = [], ?Throwable $previous = null): self
{
Expand All @@ -78,6 +79,9 @@ public static function create(int $code = 500, array $context = [], ?Throwable $
return $exception;
}

/**
* @return array<string,mixed>
*/
public function getContext(): array
{
return $this->context;
Expand Down
11 changes: 9 additions & 2 deletions src/RequestHandlerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*/
class RequestHandlerContainer implements ContainerInterface
{
/** @var array */
/** @var mixed[] */
protected $constructorArguments;

/**
* @param mixed[] $constructorArguments
*/
public function __construct(array $constructorArguments = [])
{
$this->constructorArguments = $constructorArguments;
Expand All @@ -36,7 +39,7 @@ public function has($id): bool
}

/**
* @param string $id
* @param class-string|string $id
* @return RequestHandlerInterface
*/
public function get($id)
Expand All @@ -58,6 +61,10 @@ public function get($id)
}
}

/**
* @param class-string|string $handler
* @return mixed
*/
protected function resolve(string $handler)
{
$handler = $this->split($handler);
Expand Down
5 changes: 3 additions & 2 deletions tests/CallableHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Middlewares\Tests;

use Exception;
use Middlewares\Utils\CallableHandler;
use Middlewares\Utils\Factory;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -53,15 +54,15 @@ public function testOb(): void
echo 'Hello';
ob_start();
echo 'Hello';
throw new \Exception('Error Processing Request');
throw new Exception('Error Processing Request');
});

ob_start();
$level = ob_get_level();

try {
$callable();
} catch (\Exception $e) {
} catch (Exception $e) {
}

self::assertSame($level, ob_get_level());
Expand Down
1 change: 1 addition & 0 deletions tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testMiddlewareException(): void
{
$this->expectException('UnexpectedValueException');

/** @phpstan-ignore-next-line */
$response = Dispatcher::run(['']);
}
}
Loading