Passed
Push — main ( 42b4d9...c70814 )
by Frank
01:56
created

PathShapeRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderLineStringPath() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PrinsFrank\PhpGeoSVG\Html\Rendering;
6
7
use PrinsFrank\PhpGeoSVG\Coordinator\Coordinator;
8
use PrinsFrank\PhpGeoSVG\Geometry\GeometryObject\LineString;
9
10
class PathShapeRenderer
11
{
12
    public const MOVE_TO               = 'M';
13
    public const LINE_TO               = 'L';
14
    public const HORIZONTAL_LINE       = 'H';
15
    public const VERTICAL_LINE         = 'V';
16
    public const CLOSE_PATH            = 'Z';
17
    public const CUBIC_CURVE           = 'C';
18
    public const SHORT_CUBIC_CURVE     = 'S';
19
    public const QUADRATIC_CURVE       = 'Q';
20
    public const SHORT_QUADRATIC_CURVE = 'T';
21
    public const ARC                   = 'A';
22
23 3
    public static function renderLineStringPath(LineString $lineString, Coordinator $coordinator): string
24
    {
25 3
        $renderedLineString = '';
26 3
        foreach ($lineString->getPositions() as $key => $position) {
27 2
            if (0 === $key) {
28 2
                $renderedLineString .= self::MOVE_TO;
29
            } else {
30 1
                $renderedLineString .= ' ' . self::LINE_TO;
31
            }
32
33 2
            $renderedLineString .= $coordinator->getX($position) . ' ' . $coordinator->getY($position);
34
        }
35
36 3
        return $renderedLineString;
37
    }
38
}
39