Lines
87.50%
7 / 8
Methods
50.00%
1 / 2
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| load | 85.71% | 6 / 7 | 0.00% | 0 / 1 | 2.01 | ||
| 15 | final readonly class LinkListLoader | |
| 16 | { | |
| 17 | public function __construct( | |
| 18 | private LinkListParser $parser, | |
| 19 | private CacheInterface $cache, | |
| 20 | #[Autowire('%kernel.project_dir%/../docs/links.md')] | |
| 21 | private string $file, | |
| 22 | ) { | |
| 23 | } | |
| 24 | ||
| 25 | public function load(): LinkList | |
| 26 | { | |
| 27 | $modified = @\filemtime($this->file); | |
| 28 | ||
| 29 | if (false === $modified) { | |
| 30 | return new LinkList(); | |
| 31 | } | |
| 32 | ||
| 33 | return $this->cache->get( | |
| 34 | 'link_list_'.\hash('xxh3', $this->file.'|'.$modified.'|'.\filesize($this->file)), | |
| 35 | fn (): LinkList => $this->parser->parse((string) \file_get_contents($this->file)), | |
| 36 | ); | |
| 37 | } | |
| 38 | } |