Completed
Push — master ( d7f0f7...553103 )
by Jesse
01:54
created

Imploding::implode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ImmutableCollection;
6
7
use Stratadox\Collection\Collection;
8
use Stratadox\Collection\ConversionFailed;
9
use Stratadox\Collection\Implodable;
10
use Throwable;
11
12
/**
13
 * Behaviour to implode the collection to a string.
14
 *
15
 * Provides access to serialisation behaviour in the form of a method that
16
 * serializes the collection to an imploded string.
17
 *
18
 * @package Stratadox\Collection
19
 * @author  Stratadox
20
 */
21
trait Imploding
22
{
23
    /**
24
     * @see Implodable::implode()
25
     * @return string
26
     * @throws ConversionFailed
27
     */
28
    public function implode($glue = ', '): string
29
    {
30
        try {
31
            return implode($glue, $this->items());
32
        } catch (Throwable $exception) {
33
            /** @var Collection $this */
34
            throw CouldNotImplode::encountered($this, $exception);
35
        }
36
    }
37
38
    /** @see Collection::items() */
39
    abstract public function items(): array;
40
}
41