Filtering::that()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ImmutableCollection;
6
7
use function array_filter;
8
use Closure;
9
use Stratadox\Collection\Collection;
10
use Stratadox\Collection\Filterable;
11
use Stratadox\Specification\Contract\Satisfiable;
12
13
/**
14
 * Behaviour to allow "filtering" the immutable collection.
15
 *
16
 * Provides access to filtering behaviour in the form of a method that
17
 * returns a modified copy of the original (immutable) collection.
18
 *
19
 * @package Stratadox\Collection
20
 * @author  Stratadox
21
 */
22
trait Filtering
23
{
24
    /**
25
     * @see Filterable::that
26
     * @param Satisfiable $condition
27
     * @return static
28
     */
29
    public function that(Satisfiable $condition)
30
    {
31
        return $this->newCopy(array_filter(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->newCopy(ar...ion, 'isSatisfiedBy'))) returns the type Stratadox\Collection\Collection which is incompatible with the documented return type Stratadox\ImmutableCollection\Filtering.
Loading history...
32
            $this->items(), [$condition, 'isSatisfiedBy']
33
        ));
34
    }
35
36
    /**
37
     * @see Filterable::filterWith
38
     * @param Closure $function
39
     * @return static
40
     */
41
    public function filterWith(Closure $function)
42
    {
43
        return $this->newCopy(array_filter(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->newCopy(ar...s->items(), $function)) returns the type Stratadox\Collection\Collection which is incompatible with the documented return type Stratadox\ImmutableCollection\Filtering.
Loading history...
44
            $this->items(), $function
45
        ));
46
    }
47
48
    /** @see Collection::items() */
49
    abstract public function items(): array;
50
51
    /**
52
     * @see ImmutableCollection::newCopy()
53
     * @param array $items
54
     * @return static
55
     */
56
    abstract protected function newCopy(array $items): Collection;
57
}
58