Conversation
- Updated Phpunit to 9.6
- Implicitly marking parameter $app_context as nullable is deprecated
Removed version specification from the project description.
Added the RouteCompiler class
- Radix Tree creation by url tokens instead of characters
Improved: Radix Index backwards lookup.
mocked with PHPUnit >= 12 Because of their decision to not allow methods named "method" to be mocked (throw Exception), we must introduce a big breaking change. sebastianbergmann/phpunit#5415
Reorganized namespaces from `Klein\Tests` to `Matecat\Tests\Klein` for consistency. Introduced new benchmarks and optimized route validation methods for improved performance and clarity. Removed unused files and applied coding standards across classes.
Fixed 20 PHPStan errors across the codebase to improve type safety and code
quality. All changes maintain backward compatibility and existing functionality.
Changes by file:
* HeaderDataCollection.php:
- Add PHPDoc type hint for constructor array parameter
* Klein.php:
- Fix $requestMethod parameter type in filterMatchingRoutes() (string instead of string|array)
- Refactor boolean expression to avoid "always true" warning by separating
method matching logic from route URI assignment
* Route.php:
- Remove nullable type from $regex property (never assigned null)
- Change @type to @var annotations for PHPStan compatibility
- Initialize $regexMatchingParams array property with default empty array
- Remove unnecessary null coalescing operators on $namespace property
- Add PHPStan suppressions for defensive runtime checks (is_array validation
and nested array exception)
* RouteRegexCompiler.php:
- Fix private constant access by using self:: instead of static::
* RadixRouteIndex.php:
- Add complete PHPDoc type hints for constructor parameters
- Update property types to support recursive array references in radix tree
- Fix preg_split offset access with proper false handling
- Add PHPStan suppressions for recursive array structure and type inference
edge cases in loop logic
Result: PHPStan analysis now passes with zero errors.
…e safety
Add strict_types declaration to all 34 PHP files under src/Klein/.
Fix all resulting TypeError failures and resolve all PHPStan errors.
strict_types — added to 33 files (Route.php already had it):
AbstractResponse, AbstractRouteFactory, App, DataCollection,
HeaderDataCollection, ResponseCookieDataCollection, RouteCollection,
ServerDataCollection, all Exceptions/*, HttpMethod, HttpStatus,
Klein, Request, Response, ResponseCookie, RouteFactory,
RouteRegexCompiler, ServiceProvider, IndexInterface,
RadixRouteIndex, Validator
Type coercion fixes exposed by strict_types:
- HeaderDataCollection: cast array key to string before explode()
- ResponseCookieDataCollection: use $value->getName() as key
instead of relying on implicit int-to-string coercion
- ServiceProvider::markdown(): cast $arg to string before
htmlentities()
- ServiceProvider::validateParam(): explicitly cast mixed param()
return to ?string before passing to validate()
PHPStan fixes (0 errors remaining):
- HeaderDataCollection: add @param array type hint
- Klein::filterMatchingRoutes(): narrow $requestMethod to string
- Klein catch-all filter: separate setRouteMatchedAgainstUri()
from boolean expression (was "always true" right-hand side)
- Route::$regex: remove unused nullable type
- Route::$regexMatchingParams/$routeMatched: change @type to @var
for PHPStan, add default value
- Route: remove unnecessary ?? on non-nullable $namespace
- Route::validateMethod(): rewrite using HttpMethod::tryFrom()
instead of duplicated 9-arm match blocks; validate array
elements with is_string() guard (annotated @var mixed)
- RouteRegexCompiler::getPathFor(): self:: instead of static::
for private constant
- RadixRouteIndex: add PHPDoc types for constructor params and
property; handle preg_split false return; suppress recursive
array reference and loop-inference edge cases
Code quality (incidental, already in working tree):
- Rename snake_case properties to camelCase: protocol_version,
is_name_prepared, number_of_skips, route_factory,
error_callbacks, http_error_callbacks, after_filter_callbacks,
output_buffer_level, http_messages
- Klein: use InvalidCallableException instead of raw
InvalidArgumentException for uncallable callbacks
- InvalidCallableException: add constructor with message prefix,
use proper imports
- RouteFactory/DataCollection: remove stray blank lines after
opening brace
- Klein: add visibility to class constants
- Klein::with(): require_once instead of require
- Request: expand @param $files to full array shape
- MockRequestFactory: add parameter types and return type
- RequestTest: use realistic associative arrays and file
structures in test data
Tests: 298 passed, 790 assertions. PHPStan: 0 errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Version 3.2.0
Features