Skip to content

Commit

Permalink
update to new php style
Browse files Browse the repository at this point in the history
  • Loading branch information
miladrahimi committed Nov 30, 2023
1 parent 2d394bd commit 29ed5a4
Show file tree
Hide file tree
Showing 33 changed files with 125 additions and 359 deletions.
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# These are supported funding model platforms

custom: ["https://miladrahimi.com/pay.html"]
github: miladrahimi
custom: ["https://miladrahimi.com/pay.html", "https://www.paypal.com/paypalme/realmiladrahimi"]
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI
on: [push, pull_request]
jobs:
run:
strategy:
matrix:
include:
- php: '7.4'
- php: '8.0'
- php: '8.1'
- php: '8.2'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
- name: Install dependencies
run: composer self-update && composer install && composer dump-autoload
- name: Run tests and collect coverage
run: vendor/bin/phpunit --coverage-clover coverage.xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4-beta
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
"authors": [
{
"name": "Milad Rahimi",
"email": "info@miladrahimi.com",
"email": "i@miladrahimi.com",
"homepage": "https://miladrahimi.com",
"role": "Developer"
}
],
"support": {
"email": "info@miladrahimi.com",
"email": "i@miladrahimi.com",
"source": "https://github.com/miladrahimi/phprouter/issues"
},
"require": {
"php": ">=7.1",
"php": ">=7.4",
"ext-json": "*",
"ext-mbstring": "*",
"laminas/laminas-diactoros": "^2.2",
"miladrahimi/phpcontainer": "^5.3.1"
"miladrahimi/phpcontainer": "^5.3.3"
},
"require-dev": {
"phpunit/phpunit": "^7|^8|^9"
Expand Down
22 changes: 12 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<phpunit backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="main">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<logging/>
</phpunit>
19 changes: 4 additions & 15 deletions src/Dispatching/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,12 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Class Caller
* It calls (runs) middleware and controllers
*
* @package MiladRahimi\PhpRouter\Dispatching
*/
class Caller
{
/**
* @var Container
*/
private $container;
private Container $container;

/**
* Constructor
*
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
Expand Down Expand Up @@ -75,13 +64,13 @@ public function call($callable)

[$class, $method] = $callable;

if (class_exists($class) == false) {
if (!class_exists($class)) {
throw new InvalidCallableException("Class `$class` not found.");
}

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

if (method_exists($object, $method) == false) {
if (!method_exists($object, $method)) {
throw new InvalidCallableException("Method `$class::$method` is not declared.");
}

Expand All @@ -104,7 +93,7 @@ public function call($callable)
}
}

if (is_callable($callable) == false) {
if (!is_callable($callable)) {
throw new InvalidCallableException('Invalid callable.');
}

Expand Down
16 changes: 2 additions & 14 deletions src/Dispatching/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Class Matcher
* It finds an appropriate route for HTTP requests
*
* @package MiladRahimi\PhpRouter\Dispatching
*/
class Matcher
{
/**
* @var Repository
*/
private $repository;
private Repository $repository;

/**
* Constructor
*
* @param Repository $repository
*/
public function __construct(Repository $repository)
{
$this->repository = $repository;
Expand All @@ -38,7 +27,7 @@ public function __construct(Repository $repository)
* @return Route
* @throws RouteNotFoundException
*/
public function find(ServerRequestInterface $request, array $patterns)
public function find(ServerRequestInterface $request, array $patterns): Route
{
foreach ($this->repository->findByMethod($request->getMethod()) as $route) {
$parameters = [];
Expand All @@ -59,7 +48,6 @@ public function find(ServerRequestInterface $request, array $patterns)
*
* @param string[] $parameters
* @return string[]
* @noinspection PhpUnusedParameterInspection
*/
private function pruneRouteParameters(array $parameters): array
{
Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/InvalidCallableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use Exception;

/**
* Class InvalidCallableException
* It'd be thrown when a callable (controller or middleware) is not valid
*
* @package MiladRahimi\PhpRouter\Exceptions
*/
class InvalidCallableException extends Exception
{
Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/RouteNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use Exception;

/**
* Class RouteNotFoundException
* It'd be thrown when no route that matches the user request
*
* @package MiladRahimi\PhpRouter\Exceptions
*/
class RouteNotFoundException extends Exception
{
Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/UndefinedRouteException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use Exception;

/**
* Class UndefinedRouteException
* It'd be thrown when cannot find a route to generate URL from
*
* @package MiladRahimi\PhpRouter\Exceptions
*/
class UndefinedRouteException extends Exception
{
Expand Down
3 changes: 0 additions & 3 deletions src/Publisher/HttpPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use Psr\Http\Message\ResponseInterface;

/**
* Class HttpPublisher
* It publishes responses provided by controllers and middleware as HTTP responses
*
* @package MiladRahimi\PhpRouter\Services
*/
class HttpPublisher implements Publisher
{
Expand Down
3 changes: 0 additions & 3 deletions src/Publisher/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
namespace MiladRahimi\PhpRouter\Publisher;

/**
* Interface Publisher
* It publishes responses provided by controllers and middleware
*
* @package MiladRahimi\PhpRouter\Services
*/
interface Publisher
{
Expand Down
39 changes: 6 additions & 33 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,27 @@
use Laminas\Diactoros\ServerRequestFactory;

/**
* Class Router
* It defines the application routes and dispatches them (runs the application).
*
* @package MiladRahimi\PhpRouter
*/
class Router
{
/**
* @var Container
*/
private $container;
private Container $container;

/**
* @var Storekeeper
*/
private $storekeeper;
private Storekeeper $storekeeper;

/**
* @var Matcher
*/
private $matcher;
private Matcher $matcher;

/**
* @var Caller
*/
private $caller;
private Caller $caller;

/**
* @var Publisher
*/
private $publisher;
private Publisher $publisher;

/**
* List of defined parameter patterns with `pattern()` method
*
* @var string[]
*/
private $patterns = [];
private array $patterns = [];

/**
* Constructor
*
* @param Container $container
* @param Storekeeper $storekeeper
* @param Matcher $matcher
* @param Caller $caller
* @param Publisher $publisher
*/
public function __construct(
Container $container,
Storekeeper $storekeeper,
Expand Down
3 changes: 0 additions & 3 deletions src/Routing/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
namespace MiladRahimi\PhpRouter\Routing;

/**
* Class Attributes
* It is an Enum that holds route attributes
*
* @package MiladRahimi\PhpRouter\Routing
*/
class Attributes
{
Expand Down
5 changes: 1 addition & 4 deletions src/Routing/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use Closure;

/**
* Class Repository
* It is a repository for the defined routes
*
* @package MiladRahimi\PhpRouter\Routing
*/
class Repository
{
Expand All @@ -17,7 +14,7 @@ class Repository
*
* @var Route[]
*/
private $routes = [];
private array $routes = [];

/**
* Save a new route
Expand Down
Loading

0 comments on commit 29ed5a4

Please sign in to comment.