Issues (15)

src/Appending.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ImmutableCollection;
6
7
use function array_merge;
8
use Stratadox\Collection\Appendable;
9
use Stratadox\Collection\Collection;
10
11
/**
12
 * Behaviour to allow "appending" the immutable collection.
13
 *
14
 * Provides access to appending behaviour in the form of a method that
15
 * returns a modified copy of the original (immutable) collection.
16
 *
17
 * @package Stratadox\Collection
18
 * @author  Stratadox
19
 */
20
trait Appending
21
{
22
    /**
23
     * @see Appendable::add()
24
     * @param array ...$newItems
25
     * @return static
26
     */
27
    public function add(...$newItems)
28
    {
29
        return $this->newCopy(array_merge($this->items(), $newItems));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->newCopy(ar...s->items(), $newItems)) returns the type Stratadox\Collection\Collection which is incompatible with the documented return type Stratadox\ImmutableCollection\Appending.
Loading history...
30
    }
31
32
    /** @see Collection::items() */
33
    abstract public function items(): array;
34
35
    /**
36
     * @see ImmutableCollection::newCopy()
37
     * @param array $items
38
     * @return static
39
     */
40
    abstract protected function newCopy(array $items): Collection;
41
}
42