mikecbrant/php-ultimate-sessions

View on GitHub
src/UltimateSessions/UltimateSessionLoader.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php
 
namespace MikeBrant\UltimateSessions;
 
use Psr\Log\LoggerInterface;
 
/**
* Class UltimateSessionLoader
*
* A simple static interface provided to allow for one-line instantiation of
* the UltimateSession library using recommended settings, with a few minimal
* configuration options.
*
* @package MikeBrant\UltimateSessions
*/
abstract class UltimateSessionLoader
{
/**
* Single static method in this class provided to allow setup of
* UltimateSession library using recommended settings along with a few
* key configuration options.
*
* @param bool $useEncryption
* @param LoggerInterface|null $logger
* @return UltimateSessionManager
* @throws \InvalidArgumentException
*/
public static function initialize(
The method initialize has a boolean flag argument $useEncryption, which is a certain sign of a Single Responsibility Principle violation.
$useEncryption = false,
LoggerInterface $logger = null
) {
if(!is_bool($useEncryption)) {
Missing class import via use statement (line '33', column '23').
throw new \InvalidArgumentException('Value must be boolean.');
}
$handler = new UltimateSessionHandler(
Avoid using static access to class 'MikeBrant\UltimateSessions\UltimateSessionHandlerConfig' in method 'initialize'.
UltimateSessionHandlerConfig::getInstance($useEncryption)
);
$changeIdCallback = null;
if($useEncryption) {
$changeIdCallback = function ($oldSessionId, $newSessionId) use ($handler)
{
$handler->changeKeyCookieSessionId(
$oldSessionId,
$newSessionId
);
};
}
return new UltimateSessionManager(
new UltimateSessionManagerConfig(),
$changeIdCallback,
null,
$logger
);
}
}