Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
DashPattern
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 solid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 dashed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 dotted
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 dashDot
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toOperatorArgs
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Writer;
6
7/**
8 * Dash pattern for stroked paths.
9 *
10 * Wraps the PDF dash array + phase for use with Page::drawLine()
11 * and other stroked shape methods.
12 */
13final class DashPattern
14{
15    /**
16     * @param float[] $pattern Alternating on/off lengths in points (e.g. [4, 2])
17     * @param float   $phase  Offset into the pattern to start at
18     */
19    public function __construct(
20        public readonly array $pattern,
21        public readonly float $phase = 0,
22    ) {}
23
24    public static function solid(): self
25    {
26        return new self([], 0);
27    }
28
29    public static function dashed(float $on = 4, float $off = 4): self
30    {
31        return new self([$on, $off]);
32    }
33
34    public static function dotted(float $dot = 1, float $gap = 2): self
35    {
36        return new self([$dot, $gap]);
37    }
38
39    public static function dashDot(float $dash = 6, float $dot = 1, float $gap = 2): self
40    {
41        return new self([$dash, $gap, $dot, $gap]);
42    }
43
44    /**
45     * @return array{0: float[], 1: float} For ContentStream::setDashPattern()
46     */
47    public function toOperatorArgs(): array
48    {
49        return [$this->pattern, $this->phase];
50    }
51}