Lines
87.50%
7 / 8
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| LinkListLoader | 87.50% | 7 / 8 | 50.00% | 1 / 2 | 3.02 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| load | 85.71% | 6 / 7 | 0.00% | 0 / 1 | 2.01 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\LinkList; | |
| 6 | ||
| 7 | use App\ApiResource\LinkList; | |
| 8 | use Symfony\Component\DependencyInjection\Attribute\Autowire; | |
| 9 | use Symfony\Contracts\Cache\CacheInterface; | |
| 10 | ||
| 11 | /** | |
| 12 | * The link list of docs/links.md (the deploy has the whole repository), parsed once per change | |
| 13 | * of the file. Without the file the list is empty. | |
| 14 | */ | |
| 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 | } |