Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PossibleRoutePrefixProvider
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getPossiblePrefixes
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\Common\RouteDefinitions;
3
4use Apie\Common\Enums\UrlPrefix;
5use Apie\Common\Interfaces\HasRouteDefinition;
6use Apie\Common\ValueObjects\PossibleRoutePrefixes;
7
8final class PossibleRoutePrefixProvider
9{
10    /**
11     * @var array<string, string>
12     */
13    private array $prefixes;
14
15    public function __construct(
16        private readonly string $cmsPath,
17        private readonly string $apiPath
18    ) {
19        $this->prefixes = [
20            UrlPrefix::CMS->value => ltrim($this->cmsPath, '/'),
21            UrlPrefix::API->value => ltrim($this->apiPath, '/'),
22        ];
23    }
24
25    public function getPossiblePrefixes(HasRouteDefinition $routeDefinition): PossibleRoutePrefixes
26    {
27        $result = [];
28        foreach ($routeDefinition->getUrlPrefixes() as $urlPrefix) {
29            if (isset($this->prefixes[$urlPrefix->value])) {
30                $result[] = $this->prefixes[$urlPrefix->value];
31            }
32        }
33        return PossibleRoutePrefixes::fromNative($result);
34    }
35}