StaticPageRegistry::getPage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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