MultisetIterableImplementation   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A partialIntersection() 0 17 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\PartialIntersection;
6
7
use Smoren\PartialIntersection\Util\JustifyMultipleIterator;
8
use Smoren\PartialIntersection\Util\NoValueMonad;
9
use Smoren\PartialIntersection\Util\UsageMap;
10
11
class MultisetIterableImplementation
12
{
13
    /**
14
     * @template T
15
     *
16
     * @param bool $strict
17
     * @param int $m
18
     * @param iterable<T> ...$multisets
19
     *
20
     * @return \Generator<T>
21
     */
22 378
    public static function partialIntersection(bool $strict, int $m, iterable ...$multisets): \Generator
23
    {
24 378
        $usageMap = new UsageMap($strict);
25
26 378
        $multipleIterator = new JustifyMultipleIterator(...$multisets);
27
28 378
        foreach ($multipleIterator as $index => $values) {
29 322
            foreach ($values as $owner => $value) {
30 322
                if ($value instanceof NoValueMonad) {
31 125
                    continue;
32
                }
33
34 322
                $usageMap->addUsage($value, (string)$owner);
35
36 322
                if ($usageMap->getOwnersCount($value) === $m) {
37 210
                    yield $value;
38 210
                    $usageMap->deleteUsage($value);
39
                }
40
            }
41
        }
42
    }
43
}
44