Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit c73137e

Browse files
DevquasarX9spont4e
authored andcommitted
Refactor method signatures in MongoDbSessionHandler for clarity and type safety. Add .editorconfig for consistent coding style across files. Update composer.json to include ext-mongodb requirement. (#23)
1 parent a24fbae commit c73137e

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
max_line_length = 120
10+
11+
[*.php]
12+
indent_size = 4
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[{*.html,*.blade.php,*.less,*.sass,*.scss,*.css,*.js,*.json}]
18+
indent_size = 2
19+
20+
[*.{xml,yml,yaml}]
21+
indent_size = 2
22+
23+
[composer.json]
24+
indent_size = 4

src/MongoDbSessionHandler.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,37 @@ public function __construct($connection, $table = 'sessions', $minutes = 60)
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function open($savePath, $sessionName)
31+
public function open($path, $name): bool
3232
{
3333
return true;
3434
}
3535

3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function close()
39+
public function close(): bool
4040
{
4141
return true;
4242
}
4343

4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function read($sessionId)
47+
public function read($id): false|string
4848
{
49-
$session = $this->query()->find($sessionId);
49+
$session = $this->query()->find($id);
5050

5151
return $session ? $session['payload'] : '';
5252
}
5353

5454
/**
5555
* {@inheritdoc}
5656
*/
57-
public function write($sessionId, $data)
57+
public function write($id, $data): bool
5858
{
5959
try {
6060
return (bool) $this->query()
61-
->where('_id', $sessionId)
61+
->where('_id', $id)
6262
->update($this->buildPayload($data), ['upsert' => true]);
6363
} catch (BulkWriteException $exception) {
6464
// high concurrency exception
@@ -69,17 +69,17 @@ public function write($sessionId, $data)
6969
/**
7070
* {@inheritdoc}
7171
*/
72-
public function destroy($sessionId)
72+
public function destroy($id): bool
7373
{
74-
$this->query()->where('_id', $sessionId)->delete();
74+
$this->query()->where('_id', $id)->delete();
7575

7676
return true;
7777
}
7878

7979
/**
8080
* {@inheritdoc}
8181
*/
82-
public function gc($lifetime)
82+
public function gc($max_lifetime): false|int
8383
{
8484
// Garbage collection is handled by ttl index in the database
8585
return true;
@@ -88,7 +88,6 @@ public function gc($lifetime)
8888
/**
8989
* Returns the query builder
9090
*
91-
* @return \Jenssegers\Mongodb\Query\Builder
9291
*/
9392
protected function query()
9493
{

0 commit comments

Comments
 (0)