Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DomainCatalogFileLoaderPhp
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
1 / 1
 getFileType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parseDomainCatalogFile
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3/**
4 * @author: Doug Wilbourne (dougwilbourne@gmail.com)
5 */
6
7declare(strict_types=1);
8
9namespace pvc\msg;
10
11use pvc\msg\err\InvalidDomainCatalogFileException;
12
13/**
14 * Class CatalogFileLoader
15 */
16class DomainCatalogFileLoaderPhp extends DomainCatalogFileLoader
17{
18    /**
19     * getFileType
20     * @return string
21     */
22    public function getFileType(): string
23    {
24        return 'php';
25    }
26
27    /**
28     * @param string $filepath
29     * @return array<string, string>
30     * @throws InvalidDomainCatalogFileException
31     */
32    public function parseDomainCatalogFile(string $filepath): array
33    {
34        /**
35         * if file is not parsable, engine will throw a parse error, which we are not going to try to catch.
36         */
37        $messages = include($filepath);
38
39        if (!is_array($messages)) {
40            throw new InvalidDomainCatalogFileException();
41        }
42
43        foreach ($messages as $key => $message) {
44            if (!is_string($key)) {
45                throw new InvalidDomainCatalogFileException();
46            }
47            if (!is_string($message)) {
48                throw new InvalidDomainCatalogFileException();
49            }
50        }
51        /** @var array<string, string> $messages */
52        return $messages;
53    }
54}