Storage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
c 1
b 0
f 0
dl 0
loc 39
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 31 4
1
<?php
2
namespace Health\Checks;
3
4
use Illuminate\Support\Facades\Storage as StorageFacade;
5
6
class Storage extends BaseCheck implements HealthCheckInterface
7
{
8
9
    /**
10
     *
11
     * {@inheritdoc}
12
     * @see \Health\Checks\HealthCheckInterface::call()
13
     */
14
    public function call()
15
    {
16
        $builder = $this->getBuilder();
17
18
        $name = $this->getParam('name');
19
        $file = $this->getParam('file', '/health.txt');
20
21
        $contents = $this->getParam('contents', random_bytes(32));
22
        $options = $this->getParam('options', []);
23
24
        try {
25
            StorageFacade::disk($name)->put($file, $contents, $options);
26
27
            $fileContents = StorageFacade::disk($name)->get($file);
28
29
            if ($contents !== $fileContents) {
30
                $builder->down()->withData('error', 'Contents mismatch');
31
            }
32
33
            if (! StorageFacade::disk($name)->delete($file)) {
34
                $builder->down()->withData('error', 'Could not delete file');
35
            }
36
        } catch (\Exception $exception) {
37
            $builder->down()->withData('error', $exception->getMessage());
38
        }
39
40
        $builder->withData('name', $name)
41
            ->withData('file', $file)
42
            ->withData('contents', $contents);
43
44
        return $builder->build();
45
    }
46
}
47