1 | <?php declare(strict_types=1); |
||
2 | |||
3 | namespace Compolomus\RssReader; |
||
4 | |||
5 | use SplFileObject; |
||
6 | |||
7 | class FileCache implements CacheInterface |
||
8 | { |
||
9 | public function __construct( |
||
10 | public string $cacheDir = '/tmp/.rssreader_cache', |
||
11 | public string $cacheIdsFile = 'cacheIds.txt', |
||
12 | private ?SplFileObject $cacheIds = null, |
||
13 | ) { |
||
14 | // Read path cache dir from env |
||
15 | if (!empty($_ENV['RSSREADER_CACHE_DIR'])) { |
||
16 | $this->cacheDir = $_ENV['RSSREADER_CACHE_DIR']; |
||
17 | } |
||
18 | |||
19 | if (!is_dir($this->cacheDir)) { |
||
20 | if (!mkdir($this->cacheDir) && !is_dir($this->cacheDir)) { |
||
21 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $this->cacheDir)); |
||
22 | } |
||
23 | } |
||
24 | |||
25 | $this->cacheIds = new SplFileObject($this->cacheDir . '/' . $this->cacheIdsFile, 'a+b'); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param array $ids List of IDs to save |
||
30 | * |
||
31 | * @return int Amount of saved bytes |
||
32 | */ |
||
33 | public function saveIds(array $ids = []): int |
||
34 | { |
||
35 | return $this->cacheIds->fwrite(implode(PHP_EOL, $ids) . PHP_EOL); |
||
0 ignored issues
–
show
|
|||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Get list of cached IDs |
||
40 | * |
||
41 | * @return array |
||
42 | */ |
||
43 | public function getIds(): array |
||
44 | { |
||
45 | $cacheFile = $this->cacheDir . '/' . $this->cacheIdsFile; |
||
46 | |||
47 | return |
||
48 | file_exists($cacheFile) |
||
49 | ? file($cacheFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) |
||
50 | : []; |
||
51 | } |
||
52 | } |
||
53 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.