Completed
Push — master ( 98be7b...7a3330 )
by Dorian
01:30
created

Path::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace App\Domain\Collection;
4
5
use App\Domain\PathPart;
6
use Doctrine\Common\Collections\Criteria;
7
8
/**
9
 * This is a Collection of PathPart, which we can name a "Path" (beware: it is not a Collection of "Paths").
10
 *
11
 * @method PathPart first()
12
 * @method PathPart last()
13
 * @method PathPart next()
14
 * @method PathPart current()
15
 * @method PathPart get($key)
16
 * @method PathPart[] toArray()
17
 * @method PathPart[] getValues()
18
 * @method PathPart[]|Path map(\Closure $p)
19
 * @method PathPart[]|Path filter(\Closure $p)
20
 * @method PathPart[]|Path slice($offset, $length = null)
21
 * @method PathPart[]|Path matching(Criteria $criteria)
22
 * @method Path[] partition(\Closure $p)
23
 */
24
final class Path extends Collection
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function __toString(): string
30
    {
31
        return implode(
32
            DIRECTORY_SEPARATOR,
33
            $this->matching(Criteria::create()->orderBy(array('priority' => Criteria::ASC)))
34
                ->map(function (PathPart $pathPart) {
35
                    return $pathPart->getPath();
36
                })
37
                ->toArray()
38
        );
39
    }
40
}
41