StaticPageRegistry   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getPage() 0 3 1
1
<?php
2
3
4
namespace TheCodingMachine\CMS\Page;
5
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use TheCodingMachine\CMS\Block\BlockInterface;
9
10
class StaticPageRegistry implements PageRegistryInterface
11
{
12
    /**
13
     * @var array|BlockInterface[]
14
     */
15
    private $pages;
16
17
    /**
18
     * @param BlockInterface[] $pages An array associating the path (as key) to a Page object. The key must start with a '/'
19
     */
20
    public function __construct(array $pages)
21
    {
22
        $this->pages = $pages;
23
    }
24
25
    public function getPage(ServerRequestInterface $request): ?BlockInterface
26
    {
27
        return $this->pages[$request->getUri()->getPath()] ?? null;
28
    }
29
}
30