1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace BEAR\Package\Provide\Cache; |
||
6 | |||
7 | use BEAR\AppMeta\AbstractAppMeta; |
||
8 | use BEAR\Package\Exception\DirectoryNotWritableException; |
||
9 | use Ray\Di\ProviderInterface; |
||
10 | |||
11 | use function is_writable; |
||
12 | use function mkdir; |
||
13 | |||
14 | /** |
||
15 | * Provide tmp directory |
||
16 | * |
||
17 | * @implements ProviderInterface<string> |
||
18 | */ |
||
19 | final class CacheDirProvider implements ProviderInterface |
||
20 | { |
||
21 | private const CACHE_DIRNAME = '/cache'; |
||
22 | |||
23 | public function __construct(private AbstractAppMeta $appMeta) |
||
24 | { |
||
25 | } |
||
26 | |||
27 | public function get(): string |
||
28 | { |
||
29 | $cacheDir = $this->appMeta->tmpDir . self::CACHE_DIRNAME; |
||
30 | if (! is_writable($cacheDir) && ! @mkdir($cacheDir)) { |
||
31 | // @codeCoverageIgnoreStart |
||
32 | throw new DirectoryNotWritableException($cacheDir); |
||
33 | // @codeCoverageIgnoreEnd |
||
34 | } |
||
35 | |||
36 | return $cacheDir; |
||
0 ignored issues
–
show
|
|||
37 | } |
||
38 | } |
||
39 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: