SimpleCacheSweeper::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace WebTheory\Saveyour\Processor;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Psr\SimpleCache\CacheInterface;
7
use WebTheory\Saveyour\Contracts\Processor\FormDataProcessorInterface;
8
use WebTheory\Saveyour\Contracts\Report\FormProcessReportInterface;
9
use WebTheory\Saveyour\Processor\Abstracts\AbstractFormDataProcessor;
10
use WebTheory\Saveyour\Report\FormProcessReport;
11
12
class SimpleCacheSweeper extends AbstractFormDataProcessor implements FormDataProcessorInterface
13
{
14
    protected CacheInterface $cache;
15
16
    /**
17
     * @var array<string>
18
     */
19
    protected array $keys;
20
21
    public function __construct(string $name, CacheInterface $cache, array $keys, ?array $fields = null)
22
    {
23
        parent::__construct($name, $fields);
24
25
        $this->cache = $cache;
26
        $this->keys = $keys;
27
    }
28
29
    public function process(ServerRequestInterface $request, array $results): ?FormProcessReportInterface
30
    {
31
        if ($this->allFieldsPresent($results)) {
32
            $status = $this->cache->deleteMultiple($this->keys);
33
        }
34
35
        return new FormProcessReport([
36
            'successful' => $status ?? null,
37
        ]);
38
    }
39
}
40