Skip to content

Commit 23b5df9

Browse files
committed
Merge branch 'develop'
* develop: specify next release replace Maybes by Attempts use promoted properties add NoDiscard attributes update dependencies fix ci badge
2 parents a26419c + 581013c commit 23b5df9

10 files changed

Lines changed: 65 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,3 @@ jobs:
1212
uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main
1313
cs:
1414
uses: innmind/github-workflows/.github/workflows/cs.yml@main
15-
with:
16-
php-version: '8.2'

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 5.0.0 - 2026-02-15
4+
5+
### Changed
6+
7+
- Requires PHP `8.4`
8+
- Requires `innmind/foundation:~2.1`
9+
- `Innmind\HttpSession\Manager::start()`, `::save()` and `::close()` now return a `Innmind\Immutable\Attempt`
10+
311
## 4.1.0 - 2025-07-30
412

513
### Changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Http session
22

3-
[![Build Status](https://github.com/Innmind/HttpSession/workflows/CI/badge.svg?branch=master)](https://github.com/Innmind/HttpSession/actions?query=workflow%3ACI)
3+
[![CI](https://github.com/Innmind/HttpSession/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Innmind/HttpSession/actions/workflows/ci.yml)
44
[![codecov](https://codecov.io/gh/Innmind/HttpSession/branch/develop/graph/badge.svg)](https://codecov.io/gh/Innmind/HttpSession)
55
[![Type Coverage](https://shepherd.dev/github/Innmind/HttpSession/coverage.svg)](https://shepherd.dev/github/Innmind/HttpSession)
66

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"issues": "http://github.com/Innmind/HttpSession/issues"
1616
},
1717
"require": {
18-
"php": "~8.2",
19-
"innmind/foundation": "~1.3"
18+
"php": "~8.4",
19+
"innmind/foundation": "~2.1"
2020
},
2121
"autoload": {
2222
"psr-4": {
@@ -31,7 +31,7 @@
3131
},
3232
"require-dev": {
3333
"innmind/black-box": "^6.4.1",
34-
"innmind/static-analysis": "^1.2.1",
34+
"innmind/static-analysis": "~1.3",
3535
"innmind/coding-standard": "~2.0"
3636
}
3737
}

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
<directory name="vendor" />
1515
</ignoreFiles>
1616
</projectFiles>
17+
<issueHandlers>
18+
<UndefinedAttributeClass errorLevel="suppress" />
19+
</issueHandlers>
1720
</psalm>

src/Manager.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@
55

66
use Innmind\Http\ServerRequest;
77
use Innmind\Immutable\{
8-
Maybe,
8+
Attempt,
99
SideEffect,
1010
};
1111

1212
interface Manager
1313
{
1414
/**
15-
* @return Maybe<Session>
15+
* @return Attempt<Session>
1616
*/
17-
public function start(ServerRequest $request): Maybe;
17+
#[\NoDiscard]
18+
public function start(ServerRequest $request): Attempt;
1819

1920
/**
20-
* @return Maybe<SideEffect>
21+
* @return Attempt<SideEffect>
2122
*/
22-
public function save(Session $session): Maybe;
23+
#[\NoDiscard]
24+
public function save(Session $session): Attempt;
2325

2426
/**
25-
* @return Maybe<SideEffect>
27+
* @return Attempt<SideEffect>
2628
*/
27-
public function close(Session $session): Maybe;
29+
#[\NoDiscard]
30+
public function close(Session $session): Attempt;
2831
}

src/Manager/Native.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Innmind\Url\Path;
1818
use Innmind\Immutable\{
1919
Map,
20+
Attempt,
2021
Maybe,
2122
SideEffect,
2223
};
@@ -32,24 +33,25 @@ private function __construct(?Path $save = null)
3233
}
3334
}
3435

36+
#[\NoDiscard]
3537
public static function of(?Path $save = null): self
3638
{
3739
return new self($save);
3840
}
3941

4042
#[\Override]
41-
public function start(ServerRequest $request): Maybe
43+
public function start(ServerRequest $request): Attempt
4244
{
4345
if ($this->session instanceof Id) {
44-
/** @var Maybe<Session> */
45-
return Maybe::nothing();
46+
/** @var Attempt<Session> */
47+
return Attempt::error(new \LogicException('Session already started'));
4648
}
4749

4850
$this->configureSessionId($request);
4951

5052
if (\session_start(['use_cookies' => false]) === false) {
51-
/** @var Maybe<Session> */
52-
return Maybe::nothing();
53+
/** @var Attempt<Session> */
54+
return Attempt::error(new \RuntimeException('Failed to start session'));
5355
}
5456

5557
/** @var Map<string, mixed> */
@@ -76,15 +78,16 @@ public function start(ServerRequest $request): Maybe
7678
$this->session = $session->id();
7779

7880
return $session;
79-
});
81+
})
82+
->attempt(static fn() => new \RuntimeException('Session id or name is invalid'));
8083
}
8184

8285
#[\Override]
83-
public function save(Session $session): Maybe
86+
public function save(Session $session): Attempt
8487
{
8588
if ($this->session !== $session->id()) {
86-
/** @var Maybe<SideEffect> */
87-
return Maybe::nothing();
89+
/** @var Attempt<SideEffect> */
90+
return Attempt::error(new \LogicException('Trying to save a different session than the started one'));
8891
}
8992

9093
$_ = $session
@@ -95,32 +98,32 @@ public function save(Session $session): Maybe
9598
});
9699

97100
if (\session_write_close() === false) {
98-
/** @var Maybe<SideEffect> */
99-
return Maybe::nothing();
101+
/** @var Attempt<SideEffect> */
102+
return Attempt::error(new \RuntimeException('Failed to persist the session data'));
100103
}
101104

102105
$this->session = null;
103106
$_SESSION = [];
104107

105-
return Maybe::just(new SideEffect);
108+
return Attempt::result(SideEffect::identity);
106109
}
107110

108111
#[\Override]
109-
public function close(Session $session): Maybe
112+
public function close(Session $session): Attempt
110113
{
111114
if ($this->session !== $session->id()) {
112-
/** @var Maybe<SideEffect> */
113-
return Maybe::nothing();
115+
/** @var Attempt<SideEffect> */
116+
return Attempt::error(new \LogicException('Trying to close a different session than the started one'));
114117
}
115118

116119
if (\session_destroy() === false) {
117-
/** @var Maybe<SideEffect> */
118-
return Maybe::nothing();
120+
/** @var Attempt<SideEffect> */
121+
return Attempt::error(new \RuntimeException('Failed to close the session'));
119122
}
120123

121124
$this->session = null;
122125

123-
return Maybe::just(new SideEffect);
126+
return Attempt::result(SideEffect::identity);
124127
}
125128

126129
private function configureSessionId(ServerRequest $request): void

src/Session.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,34 @@
1818
*/
1919
final class Session
2020
{
21-
private Id $id;
22-
private Name $name;
23-
/** @var Map<string, mixed> */
24-
private Map $values;
25-
2621
/**
2722
* @param Map<string, mixed> $values
2823
*/
29-
private function __construct(Id $id, Name $name, Map $values)
30-
{
31-
$this->id = $id;
32-
$this->name = $name;
33-
$this->values = $values;
24+
private function __construct(
25+
private Id $id,
26+
private Name $name,
27+
private Map $values,
28+
) {
3429
}
3530

3631
/**
3732
* @psalm-pure
3833
*
3934
* @param Map<string, mixed> $values
4035
*/
36+
#[\NoDiscard]
4137
public static function of(Id $id, Name $name, Map $values): self
4238
{
4339
return new self($id, $name, $values);
4440
}
4541

42+
#[\NoDiscard]
4643
public function id(): Id
4744
{
4845
return $this->id;
4946
}
5047

48+
#[\NoDiscard]
5149
public function name(): Name
5250
{
5351
return $this->name;
@@ -58,6 +56,7 @@ public function name(): Name
5856
*
5957
* @throws LogicException
6058
*/
59+
#[\NoDiscard]
6160
public function get(string $key): mixed
6261
{
6362
return $this->maybe($key)->match(
@@ -69,16 +68,19 @@ public function get(string $key): mixed
6968
/**
7069
* @return Maybe<mixed>
7170
*/
71+
#[\NoDiscard]
7272
public function maybe(string $key): Maybe
7373
{
7474
return $this->values->get($key);
7575
}
7676

77+
#[\NoDiscard]
7778
public function contains(string $key): bool
7879
{
7980
return $this->values->contains($key);
8081
}
8182

83+
#[\NoDiscard]
8284
public function with(string $key, mixed $value): self
8385
{
8486
return new self(
@@ -95,6 +97,7 @@ public function with(string $key, mixed $value): self
9597
*
9698
* @return Map<string, mixed>
9799
*/
100+
#[\NoDiscard]
98101
public function values(): Map
99102
{
100103
return $this->values;

src/Session/Id.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@
1313
*/
1414
final class Id
1515
{
16-
private string $value;
17-
18-
private function __construct(string $value)
16+
private function __construct(private string $value)
1917
{
20-
$this->value = $value;
2118
}
2219

2320
/**
2421
* @psalm-pure
2522
*
2623
* @return Maybe<self>
2724
*/
25+
#[\NoDiscard]
2826
public static function maybe(string $value): Maybe
2927
{
3028
return Maybe::just(Str::of($value))
3129
->filter(static fn($value) => $value->matches('~^[\w\-\_]+$~'))
3230
->map(static fn($value) => new self($value->toString()));
3331
}
3432

33+
#[\NoDiscard]
3534
public function toString(): string
3635
{
3736
return $this->value;

src/Session/Name.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@
1414
*/
1515
final class Name
1616
{
17-
private string $value;
18-
19-
private function __construct(string $value)
17+
private function __construct(private string $value)
2018
{
21-
$this->value = $value;
2219
}
2320

2421
/**
2522
* @psalm-pure
2623
*
2724
* @return Maybe<self>
2825
*/
26+
#[\NoDiscard]
2927
public static function maybe(string $value): Maybe
3028
{
3129
return Maybe::just(Str::of($value))
3230
->filter(static fn($value) => $value->matches('~^[\w\-\_]+$~'))
3331
->map(static fn($value) => new self($value->toString()));
3432
}
3533

34+
#[\NoDiscard]
3635
public function toString(): string
3736
{
3837
return $this->value;

0 commit comments

Comments
 (0)