Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass errorLevel="suppress" />
</issueHandlers>
</psalm>
3 changes: 3 additions & 0 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ interface Manager
/**
* @return Maybe<Session>
*/
#[\NoDiscard]
public function start(ServerRequest $request): Maybe;

/**
* @return Maybe<SideEffect>
*/
#[\NoDiscard]
public function save(Session $session): Maybe;

/**
* @return Maybe<SideEffect>
*/
#[\NoDiscard]
public function close(Session $session): Maybe;
}
1 change: 1 addition & 0 deletions src/Manager/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private function __construct(?Path $save = null)
}
}

#[\NoDiscard]
public static function of(?Path $save = null): self
{
return new self($save);
Expand Down
8 changes: 8 additions & 0 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ private function __construct(Id $id, Name $name, Map $values)
*
* @param Map<string, mixed> $values
*/
#[\NoDiscard]
public static function of(Id $id, Name $name, Map $values): self
{
return new self($id, $name, $values);
}

#[\NoDiscard]
public function id(): Id
{
return $this->id;
}

#[\NoDiscard]
public function name(): Name
{
return $this->name;
Expand All @@ -58,6 +61,7 @@ public function name(): Name
*
* @throws LogicException
*/
#[\NoDiscard]
public function get(string $key): mixed
{
return $this->maybe($key)->match(
Expand All @@ -69,16 +73,19 @@ public function get(string $key): mixed
/**
* @return Maybe<mixed>
*/
#[\NoDiscard]
public function maybe(string $key): Maybe
{
return $this->values->get($key);
}

#[\NoDiscard]
public function contains(string $key): bool
{
return $this->values->contains($key);
}

#[\NoDiscard]
public function with(string $key, mixed $value): self
{
return new self(
Expand All @@ -95,6 +102,7 @@ public function with(string $key, mixed $value): self
*
* @return Map<string, mixed>
*/
#[\NoDiscard]
public function values(): Map
{
return $this->values;
Expand Down
2 changes: 2 additions & 0 deletions src/Session/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ private function __construct(string $value)
*
* @return Maybe<self>
*/
#[\NoDiscard]
public static function maybe(string $value): Maybe
{
return Maybe::just(Str::of($value))
->filter(static fn($value) => $value->matches('~^[\w\-\_]+$~'))
->map(static fn($value) => new self($value->toString()));
}

#[\NoDiscard]
public function toString(): string
{
return $this->value;
Expand Down
2 changes: 2 additions & 0 deletions src/Session/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ private function __construct(string $value)
*
* @return Maybe<self>
*/
#[\NoDiscard]
public static function maybe(string $value): Maybe
{
return Maybe::just(Str::of($value))
->filter(static fn($value) => $value->matches('~^[\w\-\_]+$~'))
->map(static fn($value) => new self($value->toString()));
}

#[\NoDiscard]
public function toString(): string
{
return $this->value;
Expand Down