Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ClientContext
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 set
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 get
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 has
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace AqwSocketClient\Scripts;
6
7use Psl\Collection\MutableMap;
8
9/**
10 * Mutable session-scoped state shared across all scripts in a run.
11 *
12 * Deliberately not a value object — it is mutable by design and does not
13 * belong in src/Objects/. Each client run creates one instance and passes
14 * it through every start() and handle() call.
15 */
16final class ClientContext
17{
18    /** @var MutableMap<string, mixed> */
19    private MutableMap $data;
20
21    public function __construct()
22    {
23        /** @var array<string, mixed> $empty */
24        $empty = [];
25        $this->data = new MutableMap($empty);
26    }
27
28    public function set(string $key, mixed $value): void
29    {
30        if ($this->data->contains($key)) {
31            $this->data->set($key, $value);
32            return;
33        }
34
35        $this->data->add($key, $value);
36    }
37
38    public function get(string $key): mixed
39    {
40        if (!$this->data->contains($key)) {
41            return null;
42        }
43
44        return $this->data->get($key);
45    }
46
47    public function has(string $key): bool
48    {
49        return $this->data->contains($key);
50    }
51}