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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.1, 8.2, 8.3, 8.4]
php_version: [8.3, 8.4, 8.5]
composer_flags: ['', '--prefer-lowest']

steps:
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"description": "A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code",
"license": "MIT",
"require": {
"php": ">=8.1",
"php": ">=8.3",
"php-di/php-di": "^7.1.1",
"rareloop/router": "^6.0.3",
"rareloop/router": "^6.1.0",
"psr/container": "^2.0.2",
"psr/http-message": "^2",
"psr/http-server-middleware": "^1.0.2",
"timber/timber": "^2.3.3",
"monolog/monolog": "^3.9",
"illuminate/collections": "^10.49",
"statamic/stringy": "^3.1.3",
"laminas/laminas-diactoros": "^3.6.0",
"laminas/laminas-diactoros": "^3.8.0",
"rareloop/psr7-server-request-extension": "^2.2.0",
"spatie/macroable": "^1.0.1",
"spatie/macroable": "^2.1.0",
"mindplay/middleman": "^4.0.4",
"psr/log": "^2.0.0",
"symfony/var-dumper": "^6.4.26",
Expand Down
31 changes: 11 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Rareloop Router Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Rareloop Router Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ public function register($provider)

public function getProvider($provider)
{
$providerClass = is_string($provider) ? $provider : get_class($provider);
$providerClass = is_string($provider) ? $provider : $provider::class;

return (new Collection($this->loadedProviders))->first(function ($provider) use ($providerClass) {
return get_class($provider) === $providerClass;
return $provider::class === $providerClass;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Dcrypt/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static function build(string $input, string $password, int $cost, ?strin
*/
private static function cost(int $cost): int
{
return $cost % \pow(2, 32);
return $cost % 2 ** 32;
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Dcrypt/OpensslBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,7 @@ private static function mode(): string

$cipher = \strtolower(static::CIPHER);

if (isset($legacy[$cipher])) {
return $legacy[$cipher];
}

return $cipher;
return $legacy[$cipher] ?? $cipher;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Dcrypt/Spritz.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Spritz extends Rc4
* @param string $key Key to use for encryption
* @return string
*/
#[\Override]
public static function crypt(string $str, string $key): string
{
$s = self::initializeState($key);
Expand Down
5 changes: 1 addition & 4 deletions src/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

class Encrypter implements EncrypterContract
{
protected $key;

public function __construct($key)
public function __construct(protected $key)
{
$this->key = $key;
}

public function encrypt($data)
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public function render(ServerRequestInterface $request, Exception $e): ResponseI

protected function shouldNotReport(Exception $e)
{
return in_array(get_class($e), $this->dontReport);
return in_array($e::class, $this->dontReport);
}
}
5 changes: 1 addition & 4 deletions src/Http/Lumberjack.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

class Lumberjack
{
private $app;

protected $bootstrappers = [
LoadConfiguration::class,
RegisterExceptionHandler::class,
Expand All @@ -25,9 +23,8 @@ class Lumberjack
RegisterRequestHandler::class,
];

public function __construct(Application $app)
public function __construct(private Application $app)
{
$this->app = $app;
}

public function bootstrap()
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Router extends RareRouter
* @param callable|string $callback
* @return \Rareloop\Router\Route
*/
#[\Override]
public function map(array $verbs, string $uri, $callback): Route
{
if ($this->isControllerString($callback)) {
Expand All @@ -34,7 +35,7 @@ public function map(array $verbs, string $uri, $callback): Route
*/
private function isControllerString($callback) : bool
{
return is_string($callback) && strpos($callback, '@') !== false;
return is_string($callback) && str_contains($callback, '@');
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Page extends Post
*
* @return string
*/
#[\Override]
public static function getPostType()
{
return 'page';
Expand Down
3 changes: 2 additions & 1 deletion src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(mixed $wpPost = null, $preventTimberInit = false)
}
}

#[\Override]
public function __call($name, $arguments)
{
if (static::hasMacro($name)) {
Expand All @@ -46,7 +47,7 @@ public static function __callStatic($name, $arguments)
return call_user_func_array([$builder, $name], $arguments);
}

trigger_error('Call to undefined method ' . __CLASS__ . '::' . $name . '()', E_USER_ERROR);
trigger_error('Call to undefined method ' . self::class . '::' . $name . '()', E_USER_ERROR);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Providers/SessionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public function boot()
setcookie(
$this->session->getName(),
$this->session->getId(),
time() + ($cookieOptions['lifetime'] * 60),
$cookieOptions['path'],
$cookieOptions['domain'],
$cookieOptions['secure'],
$cookieOptions['httpOnly']
[
'expires' => time() + ($cookieOptions['lifetime'] * 60),
'path' => $cookieOptions['path'],
'domain' => $cookieOptions['domain'],
'secure' => $cookieOptions['secure'],
'httponly' => $cookieOptions['httpOnly']
]
);

$cookieSet = true;
Expand Down
6 changes: 1 addition & 5 deletions src/ScopedQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@

class ScopedQueryBuilder
{
protected $postClass;

protected $queryBuilder;

public function __construct($postClass)
public function __construct(protected $postClass)
{
$this->postClass = $postClass;

$this->queryBuilder = Helpers::app(QueryBuilderContract::class);

$this->queryBuilder
Expand Down
2 changes: 2 additions & 0 deletions src/Session/EncryptedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public function __construct(
parent::__construct($name, $handler, $id);
}

#[\Override]
protected function prepareForStorage($data)
{
return $this->encrypter->encrypt($data);
}

#[\Override]
protected function prepareForUnserialize($data)
{
if ($data === '') {
Expand Down
7 changes: 1 addition & 6 deletions src/Session/FileSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

class FileSessionHandler implements SessionHandlerInterface
{
protected $path;
protected $prefix;

public function __construct($path, $prefix = 'lumberjack_session_')
public function __construct(protected $path, protected $prefix = 'lumberjack_session_')
{
$this->path = $path;
$this->prefix = $prefix;
}

#[\ReturnTypeWillChange]
Expand Down
16 changes: 3 additions & 13 deletions tests/Unit/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,15 @@ public function calling_detectWhenRequestHasNotBeenHandled_adds_actions()

class BootstrapperBootstrapTester
{
public $callback;

public function __construct($callback)
public function __construct(public $callback)
{
$this->callback = $callback;
}
}

abstract class TestBootstrapperBase
{
private BootstrapperBootstrapTester $tester;

public function __construct(BootstrapperBootstrapTester $tester)
public function __construct(private BootstrapperBootstrapTester $tester)
{
$this->tester = $tester;
}

public function bootstrap(Application $app)
Expand Down Expand Up @@ -654,13 +648,9 @@ public function __construct(TestInterface $test)
class RequiresAdditionalConstructorParams
{
public $param;
public $param1;
public $param2;

public function __construct(TestInterface $test, $param1, $param2)
public function __construct(TestInterface $test, public $param1, public $param2)
{
$this->param = $test;
$this->param1 = $param1;
$this->param2 = $param2;
}
}
4 changes: 2 additions & 2 deletions tests/Unit/Dcrypt/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function testHmacAlgoFailure()

public function testFail()
{
$input = str_repeat('A', rand(0, 10000));
$key = str_repeat('A', rand(10, 100));
$input = str_repeat('A', random_int(0, 10000));
$key = str_repeat('A', random_int(10, 100));
$cost = 1;

$output = Hash::make($input, $key, $cost);
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Dcrypt/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class StrTest extends \PHPUnit\Framework\TestCase
public function testEquals()
{
// Test with hash_equals
$this->assertTrue(Str::equal('2222', '2222', true));
$this->assertFalse(Str::equal('2222', '3333', true));
$this->assertTrue(Str::equal('2222', '2222'));
$this->assertFalse(Str::equal('2222', '3333'));

// Test without hash_equals
$this->assertTrue(Str::equal('2222', '2222', false));
$this->assertFalse(Str::equal('2222', '3333', false));
$this->assertTrue(Str::equal('2222', '2222'));
$this->assertFalse(Str::equal('2222', '3333'));
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Dcrypt/TestSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function swaprandbyte($inp)
// @codeCoverageIgnoreStart
$len = strlen($inp);
$inp = str_split($inp);
$off = rand(0, $len - 1);
$off = random_int(0, $len - 1);
$byte = $inp[$off];
$rbyte = \random_bytes(1);
if ($byte === $rbyte) {
Expand Down
7 changes: 1 addition & 6 deletions tests/Unit/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,7 @@ class TestExceptionHandler extends Handler

class RequiresConstructorParams
{
public $param1;
public $param2;

public function __construct($param1, $param2)
public function __construct(public $param1, public $param2)
{
$this->param1 = $param1;
$this->param2 = $param2;
}
}
7 changes: 1 addition & 6 deletions tests/Unit/Http/MiddlewareAliasStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ class MASTestClass

class MASTestClassWithConstructorParams
{
public $param1;
public $param2;

public function __construct($param1, $param2)
public function __construct(public $param1, public $param2)
{
$this->param1 = $param1;
$this->param2 = $param2;
}
}
1 change: 1 addition & 0 deletions tests/Unit/PostQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static function setCreateBuilderResponse($builder)
static::$injectedBuilder = $builder;
}

#[\Override]
public static function builder(): ScopedQueryBuilder
{
return static::$injectedBuilder;
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/PostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
class PostTest extends TestCase
{
public $dummyData;
use BrainMonkeyPHPUnitIntegration;

/** @test */
Expand Down Expand Up @@ -239,6 +240,7 @@ class PostWithPrivateData extends Post

class RegisterablePostType extends Post
{
#[\Override]
public static function getPostType(): string
{
return 'registerable_post_type';
Expand Down Expand Up @@ -289,6 +291,7 @@ protected static function getPostTypeConfig(): array

class UnregisterablePostTypeWithoutConfig extends Post
{
#[\Override]
public static function getPostType(): string
{
return 'post_type';
Expand Down
Loading