Mapping   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A map() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ImmutableCollection;
6
7
use function array_map;
8
use Closure;
9
use Stratadox\Collection\Collection;
10
use Stratadox\Collection\Mappable;
11
12
/**
13
 * Behaviour to map the collection according to a closure.
14
 *
15
 * Provides access to mapping behaviour in the form of a method that maps the
16
 * collection according to an anonymous function.
17
 *
18
 * @package Stratadox\Collection
19
 * @author  Stratadox
20
 */
21
trait Mapping
22
{
23
    /**
24
     * @see Mappable::map()
25
     * @param Closure $function
26
     * @return static
27
     */
28
    public function map(Closure $function)
29
    {
30
        return $this->newCopy(array_map($function, $this->items()));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->newCopy(ar...ction, $this->items())) returns the type Stratadox\Collection\Collection which is incompatible with the documented return type Stratadox\ImmutableCollection\Mapping.
Loading history...
31
    }
32
33
    /** @see Collection::items() */
34
    abstract public function items(): array;
35
36
    /**
37
     * @see ImmutableCollection::newCopy()
38
     * @param array $items
39
     * @return Collection|static
40
     */
41
    abstract protected function newCopy(array $items): Collection;
42
}
43