Skip to content

Commit 29ed5a4

Browse files
committed
update to new php style
1 parent 2d394bd commit 29ed5a4

33 files changed

+125
-359
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# These are supported funding model platforms
2-
3-
custom: ["https://miladrahimi.com/pay.html"]
2+
github: miladrahimi
3+
custom: ["https://miladrahimi.com/pay.html", "https://www.paypal.com/paypalme/realmiladrahimi"]

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
on: [push, pull_request]
3+
jobs:
4+
run:
5+
strategy:
6+
matrix:
7+
include:
8+
- php: '7.4'
9+
- php: '8.0'
10+
- php: '8.1'
11+
- php: '8.2'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Set up PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: "${{ matrix.php }}"
20+
- name: Install dependencies
21+
run: composer self-update && composer install && composer dump-autoload
22+
- name: Run tests and collect coverage
23+
run: vendor/bin/phpunit --coverage-clover coverage.xml .
24+
- name: Upload coverage to Codecov
25+
uses: codecov/codecov-action@v4-beta
26+
env:
27+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.travis.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
"authors": [
1717
{
1818
"name": "Milad Rahimi",
19-
"email": "info@miladrahimi.com",
19+
"email": "i@miladrahimi.com",
2020
"homepage": "https://miladrahimi.com",
2121
"role": "Developer"
2222
}
2323
],
2424
"support": {
25-
"email": "info@miladrahimi.com",
25+
"email": "i@miladrahimi.com",
2626
"source": "https://github.com/miladrahimi/phprouter/issues"
2727
},
2828
"require": {
29-
"php": ">=7.1",
29+
"php": ">=7.4",
3030
"ext-json": "*",
3131
"ext-mbstring": "*",
3232
"laminas/laminas-diactoros": "^2.2",
33-
"miladrahimi/phpcontainer": "^5.3.1"
33+
"miladrahimi/phpcontainer": "^5.3.3"
3434
},
3535
"require-dev": {
3636
"phpunit/phpunit": "^7|^8|^9"

phpunit.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
<phpunit backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true"
2-
convertWarningsToExceptions="true">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
4+
<coverage processUncoveredFiles="true">
5+
<include>
6+
<directory suffix=".php">./src</directory>
7+
</include>
8+
<report>
9+
<clover outputFile="build/logs/clover.xml"/>
10+
</report>
11+
</coverage>
312
<testsuites>
413
<testsuite name="main">
514
<directory>./tests</directory>
615
</testsuite>
716
</testsuites>
8-
<filter>
9-
<whitelist processUncoveredFilesFromWhitelist="true">
10-
<directory suffix=".php">./src</directory>
11-
</whitelist>
12-
</filter>
13-
<logging>
14-
<log type="coverage-clover" target="build/logs/clover.xml"/>
15-
</logging>
17+
<logging/>
1618
</phpunit>

src/Dispatching/Caller.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,12 @@
1010
use Psr\Http\Message\ServerRequestInterface;
1111

1212
/**
13-
* Class Caller
1413
* It calls (runs) middleware and controllers
15-
*
16-
* @package MiladRahimi\PhpRouter\Dispatching
1714
*/
1815
class Caller
1916
{
20-
/**
21-
* @var Container
22-
*/
23-
private $container;
17+
private Container $container;
2418

25-
/**
26-
* Constructor
27-
*
28-
* @param Container $container
29-
*/
3019
public function __construct(Container $container)
3120
{
3221
$this->container = $container;
@@ -75,13 +64,13 @@ public function call($callable)
7564

7665
[$class, $method] = $callable;
7766

78-
if (class_exists($class) == false) {
67+
if (!class_exists($class)) {
7968
throw new InvalidCallableException("Class `$class` not found.");
8069
}
8170

8271
$object = $this->container->instantiate($class);
8372

84-
if (method_exists($object, $method) == false) {
73+
if (!method_exists($object, $method)) {
8574
throw new InvalidCallableException("Method `$class::$method` is not declared.");
8675
}
8776

@@ -104,7 +93,7 @@ public function call($callable)
10493
}
10594
}
10695

107-
if (is_callable($callable) == false) {
96+
if (!is_callable($callable)) {
10897
throw new InvalidCallableException('Invalid callable.');
10998
}
11099

src/Dispatching/Matcher.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,12 @@
88
use Psr\Http\Message\ServerRequestInterface;
99

1010
/**
11-
* Class Matcher
1211
* It finds an appropriate route for HTTP requests
13-
*
14-
* @package MiladRahimi\PhpRouter\Dispatching
1512
*/
1613
class Matcher
1714
{
18-
/**
19-
* @var Repository
20-
*/
21-
private $repository;
15+
private Repository $repository;
2216

23-
/**
24-
* Constructor
25-
*
26-
* @param Repository $repository
27-
*/
2817
public function __construct(Repository $repository)
2918
{
3019
$this->repository = $repository;
@@ -38,7 +27,7 @@ public function __construct(Repository $repository)
3827
* @return Route
3928
* @throws RouteNotFoundException
4029
*/
41-
public function find(ServerRequestInterface $request, array $patterns)
30+
public function find(ServerRequestInterface $request, array $patterns): Route
4231
{
4332
foreach ($this->repository->findByMethod($request->getMethod()) as $route) {
4433
$parameters = [];
@@ -59,7 +48,6 @@ public function find(ServerRequestInterface $request, array $patterns)
5948
*
6049
* @param string[] $parameters
6150
* @return string[]
62-
* @noinspection PhpUnusedParameterInspection
6351
*/
6452
private function pruneRouteParameters(array $parameters): array
6553
{

src/Exceptions/InvalidCallableException.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
use Exception;
66

77
/**
8-
* Class InvalidCallableException
98
* It'd be thrown when a callable (controller or middleware) is not valid
10-
*
11-
* @package MiladRahimi\PhpRouter\Exceptions
129
*/
1310
class InvalidCallableException extends Exception
1411
{

src/Exceptions/RouteNotFoundException.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
use Exception;
66

77
/**
8-
* Class RouteNotFoundException
98
* It'd be thrown when no route that matches the user request
10-
*
11-
* @package MiladRahimi\PhpRouter\Exceptions
129
*/
1310
class RouteNotFoundException extends Exception
1411
{

src/Exceptions/UndefinedRouteException.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
use Exception;
66

77
/**
8-
* Class UndefinedRouteException
98
* It'd be thrown when cannot find a route to generate URL from
10-
*
11-
* @package MiladRahimi\PhpRouter\Exceptions
129
*/
1310
class UndefinedRouteException extends Exception
1411
{

0 commit comments

Comments
 (0)