Skip to content

Commit

Permalink
Upgrade Coding Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Nov 11, 2023
1 parent 8807b6b commit 8de7627
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"require-dev": {
"ext-xdebug": "*",
"aplus/coding-standard": "^1.14",
"aplus/coding-standard": "^2.0",
"ergebnis/composer-normalize": "^2.25",
"jetbrains/phpstorm-attributes": "^1.0",
"phpmd/phpmd": "^2.13",
Expand Down
4 changes: 2 additions & 2 deletions src/Debug/SessionCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public function setSaveHandler(SaveHandler $handler) : static

public function getContents() : string
{
if ( ! isset($this->session)) {
if (!isset($this->session)) {
return '<p>No Session instance has been set on this collector.</p>';
}
if ( ! $this->session->isActive()) {
if (!$this->session->isActive()) {
return '<p>Session is inactive.</p>';
}
\ob_start(); ?>
Expand Down
3 changes: 2 additions & 1 deletion src/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ abstract class SaveHandler implements \SessionHandlerInterface, \SessionUpdateTi
* @param Logger|null $logger
*/
public function __construct(
#[SensitiveParameter] array $config = [],
#[SensitiveParameter]
array $config = [],
Logger $logger = null
) {
$this->prepareConfig($config);
Expand Down
10 changes: 5 additions & 5 deletions src/SaveHandlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public function open($path, $name) : bool

public function read($id) : string
{
if ( ! isset($this->database) || $this->lock($id) === false) {
if (!isset($this->database) || $this->lock($id) === false) {
$this->setFingerprint('');
return '';
}
if ( ! isset($this->sessionId)) {
if (!isset($this->sessionId)) {
$this->sessionId = $id;
}
$statement = $this->database
Expand All @@ -194,7 +194,7 @@ public function read($id) : string

public function write($id, $data) : bool
{
if ( ! isset($this->database)) {
if (!isset($this->database)) {
return false;
}
if ($this->lockId === false) {
Expand Down Expand Up @@ -245,7 +245,7 @@ protected function writeUpdate(string $id, string $data) : bool
return 'NOW()';
},
];
if ( ! $this->hasSameFingerprint($data)) {
if (!$this->hasSameFingerprint($data)) {
$columns[$this->getColumn('data')] = $data;
}
$this->addUserIdColumn($columns);
Expand Down Expand Up @@ -277,7 +277,7 @@ public function updateTimestamp($id, $data) : bool

public function close() : bool
{
$closed = ! ($this->lockId && ! $this->unlock());
$closed = !($this->lockId && !$this->unlock());
$this->database = null;
return $closed;
}
Expand Down
22 changes: 11 additions & 11 deletions src/SaveHandlers/FilesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ protected function prepareConfig(#[SensitiveParameter] array $config) : void
$this->config['directory'],
\DIRECTORY_SEPARATOR
) . \DIRECTORY_SEPARATOR;
if ( ! \is_dir($this->config['directory'])) {
if (!\is_dir($this->config['directory'])) {
throw new LogicException(
'Session config directory does not exist: ' . $this->config['directory']
);
}
if ($this->config['prefix']) {
$dirname = $this->config['directory'] . $this->config['prefix'] . \DIRECTORY_SEPARATOR;
if ( ! \is_dir($dirname) && ! \mkdir($dirname, 0700) && ! \is_dir($dirname)) {
if (!\is_dir($dirname) && !\mkdir($dirname, 0700) && !\is_dir($dirname)) {
throw new RuntimeException(
"Session prefix directory '{$dirname}' was not created",
);
Expand Down Expand Up @@ -105,19 +105,19 @@ public function read($id) : string
}
$filename = $this->getFilename($id);
$dirname = \dirname($filename);
if ( ! \is_dir($dirname) && ! \mkdir($dirname, 0700) && ! \is_dir($dirname)) {
if (!\is_dir($dirname) && !\mkdir($dirname, 0700) && !\is_dir($dirname)) {
throw new RuntimeException(
"Session subdirectory '{$dirname}' was not created",
);
}
$this->sessionExists = \is_file($filename);
if ( ! $this->lock($filename)) {
if (!$this->lock($filename)) {
return '';
}
if ( ! isset($this->sessionId)) {
if (!isset($this->sessionId)) {
$this->sessionId = $id;
}
if ( ! $this->sessionExists) {
if (!$this->sessionExists) {
\chmod($filename, 0600);
$this->setFingerprint('');
return '';
Expand All @@ -128,7 +128,7 @@ public function read($id) : string
protected function readData() : string
{
$data = '';
while ( ! \feof($this->stream)) {
while (!\feof($this->stream)) {
$data .= \fread($this->stream, 1024);
}
$this->setFingerprint($data);
Expand All @@ -137,14 +137,14 @@ protected function readData() : string

public function write($id, $data) : bool
{
if ( ! isset($this->stream)) {
if (!isset($this->stream)) {
return false;
}
if ($id !== $this->sessionId) {
$this->sessionId = $id;
}
if ($this->hasSameFingerprint($data)) {
return ! $this->sessionExists || \touch($this->getFilename($id));
return !$this->sessionExists || \touch($this->getFilename($id));
}
if ($this->sessionExists) {
\ftruncate($this->stream, 0);
Expand All @@ -171,7 +171,7 @@ public function updateTimestamp($id, $data) : bool

public function close() : bool
{
if ( ! \is_resource($this->stream)) {
if (!\is_resource($this->stream)) {
return true;
}
$this->unlock();
Expand All @@ -184,7 +184,7 @@ public function destroy($id) : bool
$this->close();
\clearstatcache();
$filename = $this->getFilename($id);
return ! \is_file($filename) || \unlink($filename);
return !\is_file($filename) || \unlink($filename);
}

public function gc($max_lifetime) : int | false
Expand Down
22 changes: 11 additions & 11 deletions src/SaveHandlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function prepareConfig(#[SensitiveParameter] array $config) : void
'match_ua' => false,
], $config);
foreach ($this->config['servers'] as $index => $server) {
if ( ! isset($server['host'])) {
if (!isset($server['host'])) {
throw new OutOfBoundsException(
"Memcached host not set on server config '{$index}'"
);
Expand Down Expand Up @@ -165,7 +165,7 @@ public function open($path, $name) : bool
if ($result === false) {
$this->log('Session (memcached): ' . $this->memcached->getLastErrorMessage());
}
if ( ! $this->memcached->getStats()) {
if (!$this->memcached->getStats()) {
$this->log('Session (memcached): Could not connect to any server');
return false;
}
Expand All @@ -174,10 +174,10 @@ public function open($path, $name) : bool

public function read($id) : string
{
if ( ! isset($this->memcached) || ! $this->lock($id)) {
if (!isset($this->memcached) || !$this->lock($id)) {
return '';
}
if ( ! isset($this->sessionId)) {
if (!isset($this->sessionId)) {
$this->sessionId = $id;
}
$data = (string) $this->memcached->get($this->getKey($id));
Expand All @@ -187,11 +187,11 @@ public function read($id) : string

public function write($id, $data) : bool
{
if ( ! isset($this->memcached)) {
if (!isset($this->memcached)) {
return false;
}
if ($id !== $this->sessionId) {
if ( ! $this->unlock() || ! $this->lock($id)) {
if (!$this->unlock() || !$this->lock($id)) {
return false;
}
$this->setFingerprint('');
Expand Down Expand Up @@ -229,7 +229,7 @@ public function close() : bool
if ($this->lockId) {
$this->memcached->delete($this->lockId);
}
if ( ! $this->memcached->quit()) {
if (!$this->memcached->quit()) {
return false;
}
$this->memcached = null;
Expand All @@ -238,11 +238,11 @@ public function close() : bool

public function destroy($id) : bool
{
if ( ! $this->lockId) {
if (!$this->lockId) {
return false;
}
$destroyed = $this->memcached->delete($this->getKey($id));
return ! ($destroyed === false
return !($destroyed === false
&& $this->memcached->getResultCode() !== Memcached::RES_NOTFOUND);
}

Expand All @@ -265,7 +265,7 @@ protected function lock(string $id) : bool
\usleep($this->config['lock_sleep']);
continue;
}
if ( ! $this->memcached->set($lockId, \time(), $expiration)) {
if (!$this->memcached->set($lockId, \time(), $expiration)) {
$this->log('Session (memcached): Error while trying to lock ' . $lockId);
return false;
}
Expand All @@ -286,7 +286,7 @@ protected function unlock() : bool
if ($this->lockId === false) {
return true;
}
if ( ! $this->memcached->delete($this->lockId) &&
if (!$this->memcached->delete($this->lockId) &&
$this->memcached->getResultCode() !== Memcached::RES_NOTFOUND
) {
$this->log('Session (memcached): Error while trying to unlock ' . $this->lockId);
Expand Down
22 changes: 11 additions & 11 deletions src/SaveHandlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function open($path, $name) : bool
}
}
if (isset($this->config['database'])
&& ! $this->redis->select($this->config['database'])
&& !$this->redis->select($this->config['database'])
) {
$this->log(
"Session (redis): Could not select the database '{$this->config['database']}'"
Expand All @@ -142,10 +142,10 @@ public function open($path, $name) : bool

public function read($id) : string
{
if ( ! isset($this->redis) || ! $this->lock($id)) {
if (!isset($this->redis) || !$this->lock($id)) {
return '';
}
if ( ! isset($this->sessionId)) {
if (!isset($this->sessionId)) {
$this->sessionId = $id;
}
$data = $this->redis->get($this->getKey($id));
Expand All @@ -156,11 +156,11 @@ public function read($id) : string

public function write($id, $data) : bool
{
if ( ! isset($this->redis)) {
if (!isset($this->redis)) {
return false;
}
if ($id !== $this->sessionId) {
if ( ! $this->unlock() || ! $this->lock($id)) {
if (!$this->unlock() || !$this->lock($id)) {
return false;
}
$this->sessionExists = false;
Expand All @@ -171,7 +171,7 @@ public function write($id, $data) : bool
}
$maxlifetime = $this->getMaxlifetime();
$this->redis->expire($this->lockId, $this->config['lock_ttl']);
if ($this->sessionExists === false || ! $this->hasSameFingerprint($data)) {
if ($this->sessionExists === false || !$this->hasSameFingerprint($data)) {
if ($this->redis->set($this->getKey($id), $data, $maxlifetime)) {
$this->setFingerprint($data);
$this->sessionExists = true;
Expand All @@ -189,15 +189,15 @@ public function updateTimestamp($id, $data) : bool

public function close() : bool
{
if ( ! isset($this->redis)) {
if (!isset($this->redis)) {
return true;
}
try {
if ($this->redis->ping()) {
if ($this->lockId) {
$this->redis->del($this->lockId);
}
if ( ! $this->redis->close()) {
if (!$this->redis->close()) {
return false;
}
}
Expand All @@ -210,7 +210,7 @@ public function close() : bool

public function destroy($id) : bool
{
if ( ! $this->lockId) {
if (!$this->lockId) {
return false;
}
$result = $this->redis->del($this->getKey($id));
Expand Down Expand Up @@ -243,7 +243,7 @@ protected function lock(string $id) : bool
\usleep($this->config['lock_sleep']);
continue;
}
if ( ! $this->redis->setex($lockId, $ttl, (string) \time())) {
if (!$this->redis->setex($lockId, $ttl, (string) \time())) {
$this->log('Session (redis): Error while trying to lock ' . $lockId);
return false;
}
Expand All @@ -270,7 +270,7 @@ protected function unlock() : bool
if ($this->lockId === false) {
return true;
}
if ( ! $this->redis->del($this->lockId)) {
if (!$this->redis->del($this->lockId)) {
$this->log('Session (redis): Error while trying to unlock ' . $this->lockId);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function start(array $customOptions = []) : bool
if ($this->isActive()) {
throw new LogicException('Session was already active');
}
if ( ! @\session_start($this->getOptions($customOptions))) {
if (!@\session_start($this->getOptions($customOptions))) {
$message = '';
if (\error_get_last()) {
$message = ': ' . \error_get_last()['message'];
Expand Down
2 changes: 1 addition & 1 deletion tests/Debug/SessionCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function testAutoRegenerateId() : void
public function saveHandlerProvider() : Generator
{
$directory = \sys_get_temp_dir() . '/sessions';
if ( ! \is_dir($directory)) {
if (!\is_dir($directory)) {
\mkdir($directory);
}
yield [
Expand Down
2 changes: 1 addition & 1 deletion tests/SaveHandlers/FilesHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FilesHandlerTest extends AbstractHandler
public function setUp() : void
{
$directory = \getenv('FILES_DIR');
if ($directory && ! \is_dir($directory)) {
if ($directory && !\is_dir($directory)) {
\mkdir($directory, 0700, true);
}
$this->replaceConfig([
Expand Down

0 comments on commit 8de7627

Please sign in to comment.