Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
58.82% covered (warning)
58.82%
10 / 17
61.54% covered (warning)
61.54%
8 / 13
CRAP
25.00% covered (danger)
25.00%
1 / 4
TemplateStore
57.14% covered (warning)
57.14%
4 / 7
57.14% covered (warning)
57.14%
4 / 7
10.86
0.00% covered (danger)
0.00%
0 / 1
 createCookie
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createSession
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createTemporary
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
n/a
0 / 0
n/a
0 / 0
0
 offsetExists
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 offsetGet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetSet
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 offsetUnset
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
LocalTemplateCookieStore
25.00% covered (danger)
25.00%
1 / 4
50.00% covered (danger)
50.00%
1 / 2
6.80
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
LocalTemplateSessionStore
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
LocalTemplateTemporaryStore
50.00% covered (danger)
50.00%
1 / 2
50.00% covered (danger)
50.00%
1 / 2
2.50
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\Mvc\Template;
6
7use ArrayAccess;
8use PeServer\Core\Store\CookieStore;
9use PeServer\Core\Store\SessionStore;
10use PeServer\Core\Store\TemporaryStore;
11use PeServer\Core\Throws\NotImplementedException;
12
13abstract class TemplateStore implements ArrayAccess //@phpstan-ignore-line missingType.generics
14{
15    #region function
16
17    public static function createCookie(CookieStore $store): TemplateStore
18    {
19        return new LocalTemplateCookieStore($store);
20    }
21
22    public static function createSession(SessionStore $store): TemplateStore
23    {
24        return new LocalTemplateSessionStore($store);
25    }
26
27    public static function createTemporary(TemporaryStore $store): TemplateStore
28    {
29        return new LocalTemplateTemporaryStore($store);
30    }
31
32    abstract protected function get(string $name): mixed;
33
34    #endregion
35
36    #region ArrayAccess
37
38    public function offsetExists(mixed $offset): bool
39    {
40        throw new NotImplementedException();
41    }
42    public function offsetGet(mixed $offset): mixed
43    {
44        return $this->get($offset);
45    }
46    public function offsetSet(mixed $offset, mixed $value): void
47    {
48        throw new NotImplementedException();
49    }
50    public function offsetUnset(mixed $offset): void
51    {
52        throw new NotImplementedException();
53    }
54
55    #endregion
56}
57
58//phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
59final class LocalTemplateCookieStore extends TemplateStore
60{
61    public function __construct(
62        private CookieStore $store
63    ) {
64    }
65
66    protected function get(string $name): mixed
67    {
68        if ($this->store->tryGet($name, $result)) {
69            return $result;
70        }
71
72        return null;
73    }
74}
75
76//phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
77final class LocalTemplateSessionStore extends TemplateStore
78{
79    public function __construct(
80        private SessionStore $store
81    ) {
82    }
83
84    protected function get(string $name): mixed
85    {
86        if ($this->store->tryGet($name, $result)) {
87            return $result;
88        }
89
90        return null;
91    }
92}
93
94//phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
95final class LocalTemplateTemporaryStore extends TemplateStore
96{
97    public function __construct(
98        private TemporaryStore $store
99    ) {
100    }
101
102    protected function get(string $name): mixed
103    {
104        return $this->store->peek($name);
105    }
106}