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

ICanBoogie / Storage / 11646577464

02 Nov 2024 11:22PM UTC coverage: 82.778%. First build
11646577464

push

github

olvlvl
Test against PHP 8.4.0RC3

147 of 178 new or added lines in 13 files covered. (82.58%)

149 of 180 relevant lines covered (82.78%)

6.64 hits per line

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

71.43
/lib/CacheCollection.php
1
<?php
2

3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace ICanBoogie\Storage;
13

14
use Traversable;
15

16
/**
17
 * A collection of {@link Cache} instances.
18
 */
19
class CacheCollection implements Cache
20
{
21
    /**
22
     * @var Cache[]
23
     */
24
    protected array $collection = [];
25

26
    /**
27
     * @param Cache[] $collection
28
     */
29
    public function __construct(array $collection)
30
    {
31
        $this->collection = $collection;
18✔
32
    }
33

34
    /**
35
     * @inheritdoc
36
     */
37
    public function exists(string $key): bool
38
    {
39
        foreach ($this->collection as $cache) {
4✔
40
            if ($cache->exists($key)) {
4✔
41
                return true;
4✔
42
            }
43
        }
44

45
        return false;
3✔
46
    }
47

48
    /**
49
     * @inheritdoc
50
     */
51
    public function retrieve(string $key): mixed
52
    {
NEW
53
        foreach ($this->collection as $cache) {
×
NEW
54
            if ($cache->exists($key)) {
×
NEW
55
                return $cache->retrieve($key);
×
56
            }
57
        }
58

NEW
59
        return null;
×
60
    }
61

62
    /**
63
     * @inheritdoc
64
     */
65
    public function getIterator(): Traversable
66
    {
67
        return reset($this->collection)->getIterator();
1✔
68
    }
69

70
    /**
71
     * Finds a cache by type.
72
     *
73
     * @param string $type The class or interface of the storage to find.
74
     *
75
     * @return Cache|null The cache matching the specified type or `null` if none match.
76
     */
77
    public function find_by_type(string $type): ?Cache
78
    {
79
        foreach ($this->collection as $cache) {
2✔
80
            if ($cache instanceof $type) {
2✔
81
                return $cache;
1✔
82
            }
83
        }
84

85
        return null;
1✔
86
    }
87
}
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