Skip to content

Commit

Permalink
Merge pull request #56 from samsonasik/apply-php74
Browse files Browse the repository at this point in the history
Apply PHP 7.4 syntax and typed property
  • Loading branch information
Ocramius authored Jul 22, 2022
2 parents be2280b + 4580c45 commit fec8d43
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 47 deletions.
16 changes: 4 additions & 12 deletions src/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,15 +532,11 @@ public function setExpirationSeconds($ttl, $vars = null)
$container = $this;

// Filter out any items not in our container
$expires = array_filter($vars, function ($value) use ($container) {
return $container->offsetExists($value);
});
$expires = array_filter($vars, static fn($value) => $container->offsetExists($value));

// Map item keys => timestamp
$expires = array_flip($expires);
$expires = array_map(function () use ($ts) {
return $ts;
}, $expires);
$expires = array_map(static fn() => $ts, $expires);

// Create metadata array to merge in
$data = ['EXPIRE_KEYS' => $expires];
Expand Down Expand Up @@ -583,15 +579,11 @@ public function setExpirationHops($hops, $vars = null)
$container = $this;

// FilterInterface out any items not in our container
$expires = array_filter($vars, function ($value) use ($container) {
return $container->offsetExists($value);
});
$expires = array_filter($vars, static fn($value) => $container->offsetExists($value));

// Map item keys => timestamp
$expires = array_flip($expires);
$expires = array_map(function () use ($hops, $ts) {
return ['hops' => $hops, 'ts' => $ts];
}, $expires);
$expires = array_map(static fn() => ['hops' => $hops, 'ts' => $ts], $expires);

// Create metadata array to merge in
$data = ['EXPIRE_HOPS_KEYS' => $expires];
Expand Down
2 changes: 1 addition & 1 deletion src/Config/SessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SessionConfig extends StandardConfig
protected $phpErrorMessage = false;

/** @var int Default number of seconds to make session sticky, when rememberMe() is called */
protected $rememberMeSeconds = 1209600; // 2 weeks
protected $rememberMeSeconds = 1_209_600; // 2 weeks

/**
* Name of the save handler currently in use. This will either be a PHP
Expand Down
4 changes: 1 addition & 3 deletions src/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,7 @@ public function isValid()
$event->setTarget($this);
$event->setParams($this);

$falseResult = function ($test) {
return false === $test;
};
$falseResult = static fn($test) => false === $test;

$responses = $validator->triggerEventUntil($falseResult, $event);

Expand Down
16 changes: 6 additions & 10 deletions test/Config/SessionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ public function testUrlRewriterTagsAltersIniSetting(): void

public function testRememberMeSecondsDefaultsToTwoWeeks(): void
{
self::assertEquals(1209600, $this->config->getRememberMeSeconds());
self::assertEquals(1_209_600, $this->config->getRememberMeSeconds());
}

public function testRememberMeSecondsIsMutable(): void
Expand Down Expand Up @@ -1021,18 +1021,16 @@ public function testProvidingNonSessionHandlerToSetPhpSaveHandlerResultsInExcept
public function testProvidingValidKnownSessionHandlerToSetPhpSaveHandlerResultsInNoErrors(): void
{
/** @return string */
$this->config::$phpinfo = function () {
$this->config::$phpinfo = static function () {
echo "Registered save handlers => user files unittest";
};

/** @return bool|string */
$this->config::$sessionModuleName = function (?string $module = null) {
$this->config::$sessionModuleName = static function (?string $module = null) {
static $moduleName;

if ($module !== null) {
$moduleName = $module;
}

return $moduleName;
};

Expand All @@ -1042,18 +1040,16 @@ public function testProvidingValidKnownSessionHandlerToSetPhpSaveHandlerResultsI

public function testCanProvidePathWhenUsingRedisSaveHandler(): void
{
$this->config::$phpinfo = function () {
$this->config::$phpinfo = static function () {
echo "Registered save handlers => user files redis";
};

/** @return bool|string */
$this->config::$sessionModuleName = function (?string $module = null) {
$this->config::$sessionModuleName = static function (?string $module = null) {
static $moduleName;

if ($module !== null) {
$moduleName = $module;
}

return $moduleName;
};

Expand All @@ -1069,7 +1065,7 @@ public function testNotCallLocateRegisteredSaveHandlersMethodIfSessionHandlerInt
{
$spy = new stdClass();
$spy->seen = false;
$this->config::$phpinfo = function () use ($spy): void {
$this->config::$phpinfo = static function () use ($spy): void {
$spy->seen = true;
};

Expand Down
2 changes: 1 addition & 1 deletion test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class ConfigProviderTest extends TestCase
{
/** @var array<string, mixed> */
private $config;
private array $config;

protected function setUp(): void
{
Expand Down
4 changes: 1 addition & 3 deletions test/SaveHandler/AbstractDbTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ abstract class AbstractDbTableGatewayTest extends TestCase

/**
* Test data container.
*
* @var array
*/
private $testArray;
private array $testArray;

/**
* @return Adapter
Expand Down
4 changes: 1 addition & 3 deletions test/SaveHandler/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ public function testDestroyReturnsTrueWhenSessionIsDeleted(): void
function ($args) {
$this->getItem('242', Argument::any())
->will(
function ($args) {
return $args[1];
}
fn($args) => $args[1]
);
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions test/Service/SessionConfigFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*/
class SessionConfigFactoryTest extends TestCase
{
/** @var ServiceManager */
private $services;
private ServiceManager $services;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/Service/SessionManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class SessionManagerFactoryTest extends TestCase
use EventListenerIntrospectionTrait;
use ReflectionPropertyTrait;

/** @var ServiceManager */
private $services;
private ServiceManager $services;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/Service/StorageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
*/
class StorageFactoryTest extends TestCase
{
/** @var ServiceManager */
private $services;
private ServiceManager $services;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/SessionArrayStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
class SessionArrayStorageTest extends TestCase
{
/** @var SessionArrayStorage */
private $storage;
private SessionArrayStorage $storage;

protected function setUp(): void
{
Expand Down
6 changes: 2 additions & 4 deletions test/SessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,7 @@ public function testIdShouldNotBeMutableAfterSessionStarted(): void
{
$this->manager = new SessionManager();
$this->expectException(
RuntimeException::class,
'Session has already been started);
$this->expectExceptionMessage(to change the session ID call regenerateId()'
RuntimeException::class
);
$this->manager->start();
$origId = $this->manager->getId();
Expand Down Expand Up @@ -751,7 +749,7 @@ public function testSessionValidationDoesNotHaltOnNoopListener(): void
{
$this->manager = new SessionManager();
$validatorCalled = false;
$validator = function () use (&$validatorCalled) {
$validator = static function () use (&$validatorCalled) {
$validatorCalled = true;
};

Expand Down
3 changes: 1 addition & 2 deletions test/Validator/ValidatorChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

class ValidatorChainTest extends TestCase
{
/** @var ValidatorChain */
private $validatorChain;
private ValidatorChain $validatorChain;

protected function setUp(): void
{
Expand Down

0 comments on commit fec8d43

Please sign in to comment.