Passed
Push — main ( 994ffc...08f4bd )
by Sílvio
01:02 queued 14s
created

FileCacheBatchProcessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 8 2
A __construct() 0 2 1
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\CacheStore\Support;
4
5
use Silviooosilva\CacheerPhp\CacheStore\FileCacheStore;
6
use Silviooosilva\CacheerPhp\Helpers\CacheFileHelper;
7
8
/**
9
 * Class FileCacheBatchProcessor
10
 * @author Sílvio Silva <https://github.com/silviooosilva>
11
 * @package Silviooosilva\CacheerPhp
12
 */
13
class FileCacheBatchProcessor
14
{
15
16
    /**
17
     * FileCacheBatchProcessor constructor.
18
     *
19
     * @param FileCacheStore $store
20
     */
21
    public function __construct(private FileCacheStore $store)
22
    {
23
    }
24
    
25
    /**
26
     * Processes a batch of cache items and stores them.
27
     *
28
     * @param array $batchItems
29
     * @param string $namespace
30
     * @return void
31
     */
32
    public function process(array $batchItems, string $namespace)
33
    {
34
        foreach ($batchItems as $item) {
35
            CacheFileHelper::validateCacheItem($item);
36
            $cacheKey = $item['cacheKey'];
37
            $cacheData = $item['cacheData'];
38
            $mergedData = CacheFileHelper::mergeCacheData($cacheData);
39
            $this->store->putCache($cacheKey, $mergedData, $namespace);
40
        }
41
    }
42
}
43