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

FileCacheBatchProcessor::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
rs 10
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