Skip to content

changes for php8.2 #719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 7 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push, pull_request]
run-name: ${{ github.actor }} is testing Package
on: [ push, pull_request ]

jobs:
build-test:
@@ -13,17 +13,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
php-version:
- 7.4
- 8.0
phpunit-version:
- 8.5.32
dependencies:
- lowest
- highest
os: [ ubuntu-latest, windows-latest ]
php-version: [ 8.2 ]
phpunit-version: [ 11 ] # Consider updating this
dependencies: [ lowest, highest ]
name: PHPUnit Tests
steps:
- name: Configure git to avoid issues with line endings
@@ -35,7 +28,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v5, phpunit:${{ matrix.phpunit-versions }}
tools: composer:v2, phpunit:${{ matrix.phpunit-version }}
coverage: xdebug
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_VALUES }}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -27,11 +27,11 @@
}
],
"require": {
"php": ">=7.4",
"php": "^8.2",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^8",
"phpunit/phpunit": "^11",
"mockery/mockery": "^1",
"phpstan/phpstan": "^1",
"phpstan/phpstan-phpunit": "^1",
25 changes: 12 additions & 13 deletions helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Pecee\Http\Input\InputHandler;
use Pecee\Http\Url as UrlAlias;
use Pecee\SimpleRouter\SimpleRouter as Router;
use Pecee\Http\Url;
use Pecee\Http\Response;
@@ -18,26 +20,26 @@
* If no arguments is specified, it will return the url for the current loaded route.
*
* @param string|null $name
* @param string|array|null $parameters
* @param array|string|null $parameters
* @param array|null $getParams
* @return \Pecee\Http\Url
* @throws \InvalidArgumentException
* @return UrlAlias
* @throws InvalidArgumentException
*/
function url(?string $name = null, $parameters = null, ?array $getParams = null): Url
function url(?string $name = null, array|string $parameters = null, ?array $getParams = null): Url
{
return Router::getUrl($name, $parameters, $getParams);
}

/**
* @return \Pecee\Http\Response
* @return Response
*/
function response(): Response
{
return Router::response();
}

/**
* @return \Pecee\Http\Request
* @return Request
*/
function request(): Request
{
@@ -47,11 +49,11 @@ function request(): Request
/**
* Get input class
* @param string|null $index Parameter index name
* @param string|mixed|null $defaultValue Default return value
* @param mixed|null $defaultValue Default return value
* @param array ...$methods Default methods
* @return \Pecee\Http\Input\InputHandler|array|string|null
* @return array|string|InputHandler|null
*/
function input($index = null, $defaultValue = null, ...$methods)
function input(string $index = null, mixed $defaultValue = null, ...$methods): array|string|InputHandler|null
{
if ($index !== null) {
return request()->getInputHandler()->value($index, $defaultValue, ...$methods);
@@ -80,9 +82,6 @@ function redirect(string $url, ?int $code = null): void
function csrf_token(): ?string
{
$baseVerifier = Router::router()->getCsrfVerifier();
if ($baseVerifier !== null) {
return $baseVerifier->getTokenProvider()->getToken();
}
return $baseVerifier?->getTokenProvider()->getToken();

return null;
}
33 changes: 11 additions & 22 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="SimpleRouter Test Suite">
<directory>tests/Pecee/SimpleRouter/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true"
processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" bootstrap="tests/bootstrap.php" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="SimpleRouter Test Suite">
<directory>tests/Pecee/SimpleRouter/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
24 changes: 24 additions & 0 deletions phpunit.xml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="SimpleRouter Test Suite">
<directory>tests/Pecee/SimpleRouter/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true"
processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
14 changes: 7 additions & 7 deletions src/Pecee/Controllers/IResourceController.php
Original file line number Diff line number Diff line change
@@ -8,41 +8,41 @@ interface IResourceController
/**
* @return mixed
*/
public function index();
public function index(): mixed;

/**
* @param mixed $id
* @return mixed
*/
public function show($id);
public function show(mixed $id): mixed;

/**
* @return mixed
*/
public function store();
public function store(): mixed;

/**
* @return mixed
*/
public function create();
public function create(): mixed;

/**
* View
* @param mixed $id
* @return mixed
*/
public function edit($id);
public function edit(mixed $id): mixed;

/**
* @param mixed $id
* @return mixed
*/
public function update($id);
public function update(mixed $id): mixed;

/**
* @param mixed $id
* @return mixed
*/
public function destroy($id);
public function destroy(mixed $id): mixed;

}
4 changes: 2 additions & 2 deletions src/Pecee/Http/Input/IInputItem.php
Original file line number Diff line number Diff line change
@@ -16,12 +16,12 @@ public function setName(string $name): self;
/**
* @return mixed
*/
public function getValue();
public function getValue(): mixed;

/**
* @param mixed $value
*/
public function setValue($value): self;
public function setValue(mixed $value): self;

public function __toString(): string;

23 changes: 11 additions & 12 deletions src/Pecee/Http/Input/InputFile.php
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public function __construct(string $index)
}

/**
* Create from array
* Create from an array
*
* @param array $values
* @throws InvalidArgumentException
@@ -65,7 +65,6 @@ public static function createFromArray(array $values): self
}

/* Easy way of ensuring that all indexes-are set and not filling the screen with isset() */

$values += [
'tmp_name' => null,
'type' => null,
@@ -104,7 +103,7 @@ public function setIndex(string $index): IInputItem
}

/**
* @return int
* @return int|null
*/
public function getSize(): ?int
{
@@ -116,7 +115,7 @@ public function getSize(): ?int
* @param int $size
* @return static
*/
public function setSize(int $size): IInputItem
public function setSize(int $size): self
{
$this->size = $size;

@@ -145,7 +144,7 @@ public function getType(): string
* @param string $type
* @return static
*/
public function setType(string $type): IInputItem
public function setType(string $type): self
{
$this->type = $type;

@@ -165,7 +164,7 @@ public function getExtension(): string
/**
* Get human friendly name
*
* @return string
* @return string|null
*/
public function getName(): ?string
{
@@ -174,7 +173,7 @@ public function getName(): ?string

/**
* Set human friendly name.
* Useful for adding validation etc.
* Useful for adding validation, etc.
*
* @param string $name
* @return static
@@ -192,7 +191,7 @@ public function setName(string $name): IInputItem
* @param string $name
* @return static
*/
public function setFilename(string $name): IInputItem
public function setFilename(string $name): self
{
$this->filename = $name;

@@ -202,7 +201,7 @@ public function setFilename(string $name): IInputItem
/**
* Get filename
*
* @return string mixed
* @return string|null mixed
*/
public function getFilename(): ?string
{
@@ -256,7 +255,7 @@ public function getError(): ?int
* @param int|null $error
* @return static
*/
public function setError(?int $error): IInputItem
public function setError(?int $error): self
{
$this->errors = (int)$error;

@@ -276,7 +275,7 @@ public function getTmpName(): string
* @param string $name
* @return static
*/
public function setTmpName(string $name): IInputItem
public function setTmpName(string $name): self
{
$this->tmpName = $name;

@@ -297,7 +296,7 @@ public function getValue(): string
* @param mixed $value
* @return static
*/
public function setValue($value): IInputItem
public function setValue(mixed $value): IInputItem
{
$this->filename = $value;

Loading