Issues (39)

src/Resolver/Cache/FileManager.php (7 issues)

1
<?php
2
3
namespace Nip\Dispatcher\Resolver\Cache;
4
5
/**
6
 * Class FileManager
7
 * @package Nip\Dispatcher\Resolver\Cache
8
 */
9
class FileManager
10
{
11
    /**
12
     * @param DefinitionsCollection $definitionCollection
13
     * @param null $path
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $path is correct as it would always require null to be passed?
Loading history...
14
     */
15 3
    public static function write($definitionCollection, $path = null)
16
    {
17 3
        $path = $path ? $path : static::filePath();
0 ignored issues
show
$path is of type null, thus it always evaluated to false.
Loading history...
18 3
        $content = '<?php return ' . var_export($definitionCollection->all(), true) . ';';
19 3
        file_put_contents($path, $content);
20 3
    }
21
22
    /**
23
     * @param DefinitionsCollection $definitionCollection
24
     * @param null $path
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $path is correct as it would always require null to be passed?
Loading history...
25
     */
26 2
    public static function read($definitionCollection, $path = null)
27
    {
28 2
        $path = $path ? $path : static::filePath();
0 ignored issues
show
$path is of type null, thus it always evaluated to false.
Loading history...
29
        /** @noinspection PhpIncludeInspection */
30 2
        $items = require $path;
31 2
        $definitionCollection->replace($items);
32 2
    }
33
34
    /**
35
     * @param null $path
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $path is correct as it would always require null to be passed?
Loading history...
36
     */
37
    public static function empty($path = null)
38
    {
39
        $path = $path ? $path : static::filePath();
0 ignored issues
show
$path is of type null, thus it always evaluated to false.
Loading history...
40
        $content = '<?php return [];';
41
        file_put_contents($path, $content);
42
    }
43
44
    /**
45
     * @return bool
46
     */
47 1
    public static function hasCacheFile()
48
    {
49 1
        $path = static::filePath();
50 1
        return is_file($path);
51
    }
52
53
    /**
54
     * @return string
55
     */
56 3
    public static function filePath()
57
    {
58 3
        return static::filePathBase() . '/dispatcher.php';
59
    }
60
61
    /**
62
     * @return string
63
     */
64 3
    public static function filePathBase()
65
    {
66 3
        return function_exists('app') && app()->has('path.storage')
67
            ? app('path.storage') . DIRECTORY_SEPARATOR . 'cache'
0 ignored issues
show
Are you sure app('path.storage') of type mixed|object can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
            ? /** @scrutinizer ignore-type */ app('path.storage') . DIRECTORY_SEPARATOR . 'cache'
Loading history...
68 3
            : dirname(dirname(dirname(__DIR__))) . '/cache';
69
    }
70
}
71