Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
GoToAction
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
5
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
 getActionType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Action;
6
7use Phpdftk\Pdf\Core\PdfDictionary;
8use Phpdftk\Pdf\Core\PdfName;
9
10/**
11 * GoTo action (/S /GoTo).
12 * Navigates to a destination within the document.
13 */
14class GoToAction extends Action
15{
16    public mixed $dest; // /D - destination (PdfName, PdfArray, or string)
17
18    public function __construct(mixed $dest)
19    {
20        $this->dest = $dest;
21    }
22
23    public function getActionType(): string
24    {
25        return 'GoTo';
26    }
27
28    public function toPdf(): string
29    {
30        $dict = new PdfDictionary();
31        $dict->set('Type', new PdfName(self::PDF_TYPE));
32        $dict->set('S', new PdfName($this->getActionType()));
33
34        if ($this->dest instanceof \Phpdftk\Pdf\Core\Serializable) {
35            $dict->set('D', $this->dest);
36        } else {
37            $dict->set('D', new \Phpdftk\Pdf\Core\PdfString((string) $this->dest));
38        }
39
40        if ($this->next !== null) {
41            $dict->set('Next', $this->next);
42        }
43
44        return $dict->toPdf();
45    }
46}