| Total Complexity | 8 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 90% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class FileProvider implements MetadataProviderInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var StatementDirectorySource |
||
| 17 | */ |
||
| 18 | private $source; |
||
| 19 | |||
| 20 | 4 | public function __construct(StatementDirectorySource $source) |
|
| 21 | { |
||
| 22 | 4 | $this->source = $source; |
|
| 23 | 4 | } |
|
| 24 | |||
| 25 | 3 | public function getMetadata(RegistrationResultInterface $registrationResult): ?MetadataInterface |
|
| 26 | { |
||
| 27 | 3 | $identifier = $registrationResult->getIdentifier(); |
|
| 28 | 3 | if ($identifier === null) { |
|
| 29 | 1 | return null; |
|
| 30 | } |
||
| 31 | |||
| 32 | 2 | $iterator = new GlobIterator($this->source->getMetadataDir() . DIRECTORY_SEPARATOR . '*.json'); |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @var SplFileInfo $fileInfo |
||
| 36 | */ |
||
| 37 | 2 | foreach ($iterator as $fileInfo) { |
|
| 38 | 2 | if (!$fileInfo->isFile()) { |
|
| 39 | continue; |
||
| 40 | } |
||
| 41 | |||
| 42 | 2 | $data = file_get_contents($fileInfo->getPathname()); |
|
| 43 | 2 | if ($data === false) { |
|
| 44 | throw new WebAuthnException(sprintf('Cannot read file %s.', $fileInfo->getPathname())); |
||
| 45 | } |
||
| 46 | 2 | $statement = MetadataStatement::decodeString($data); |
|
| 47 | |||
| 48 | 2 | if ($statement->matchesIdentifier($identifier)) { |
|
| 49 | 1 | return $statement; |
|
| 50 | } |
||
| 51 | } |
||
| 52 | 1 | return null; |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | public function getDescription(): string |
|
| 58 | } |
||
| 59 | } |
||
| 60 |