• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

craue / CraueConfigBundle / 5936153901

22 Aug 2023 08:09AM UTC coverage: 95.074% (-4.9%) from 100.0%
5936153901

push

github

craue
fixed tests with Symfony 6.4 dev

193 of 203 relevant lines covered (95.07%)

29.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.96
/CacheAdapter/SymfonyCacheComponentAdapter.php
1
<?php
2

3
namespace Craue\ConfigBundle\CacheAdapter;
4

5
use Psr\Cache\CacheItemPoolInterface;
6
use Psr\SimpleCache\CacheInterface;
7
use Symfony\Component\Cache\Adapter\Psr16Adapter;
8

9
/**
10
 * @author Christian Raue <christian.raue@gmail.com>
11
 * @copyright 2011-2023 Christian Raue
12
 * @license http://opensource.org/licenses/mit-license.php MIT License
13
 */
14
class SymfonyCacheComponentAdapter implements CacheAdapterInterface {
15

16
        /**
17
         * @var CacheItemPoolInterface
18
         */
19
        private $cache;
20

21
        public function __construct($cache) {
22
                if ($cache instanceof CacheItemPoolInterface) {
34✔
23
                        $this->cache = $cache;
30✔
24
                        return;
30✔
25
                }
26

27
                if ($cache instanceof CacheInterface) {
4✔
28
                        @trigger_error(sprintf('Configuring a cache of type %s is deprecated since CraueConfigBundle 2.2.1. Use %s instead.', CacheInterface::class, CacheItemPoolInterface::class), E_USER_DEPRECATED);
×
29

30
                        $this->cache = new Psr16Adapter($cache);
×
31
                        return;
×
32
                }
33

34
                throw new \InvalidArgumentException(sprintf('Expected argument of type "%s" or "%s", but "%s" given.',
4✔
35
                                CacheItemPoolInterface::class,
4✔
36
                                CacheInterface::class,
4✔
37
                                is_object($cache) ? get_class($cache) : gettype($cache)));
4✔
38
        }
39

40
        public function clear() {
41
                return $this->cache->clear();
20✔
42
        }
43

44
        public function has($key) {
45
                return $this->cache->hasItem($key);
28✔
46
        }
47

48
        public function get($key) {
49
                return $this->cache->getItem($key)->get();
20✔
50
        }
51

52
        public function set($key, $value) {
53
                $cacheItem = $this->cache->getItem($key);
20✔
54
                $cacheItem->set($value);
20✔
55

56
                return $this->cache->save($cacheItem);
20✔
57
        }
58

59
        public function setMultiple(array $keysAndValues) {
60
                foreach ($keysAndValues as $key => $value) {
14✔
61
                        $cacheItem = $this->cache->getItem($key);
14✔
62
                        $cacheItem->set($value);
14✔
63
                        if (!$this->cache->saveDeferred($cacheItem)) {
14✔
64
                                return false;
2✔
65
                        }
66
                }
67

68
                return $this->cache->commit();
12✔
69
        }
70

71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc