Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
Form
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
7 / 7
8
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
 setName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addFieldIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFieldIndices
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNumberOfFields
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStream
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Pdf\Document;
15
16/**
17 * Pdf form class
18 *
19 * @category   Pop
20 * @package    Pop\Pdf
21 * @author     Nick Sagona, III <dev@nolainteractive.com>
22 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    5.0.0
25 */
26class Form
27{
28
29    /**
30     * Form name
31     * @var ?string
32     */
33    protected ?string $name = null;
34
35    /**
36     * Form field indices
37     * @var array
38     */
39    protected array $fields = [];
40
41    /**
42     * Constructor
43     *
44     * Instantiate a PDF form object.
45     *
46     * @param string $name
47     */
48    public function __construct(string $name)
49    {
50        $this->setName($name);
51    }
52
53    /**
54     * Set form name
55     *
56     * @param  string $name
57     * @return Form
58     */
59    public function setName(string $name): Form
60    {
61        $this->name = $name;
62        return $this;
63    }
64
65    /**
66     * Get the form name
67     *
68     * @return ?string
69     */
70    public function getName(): ?string
71    {
72        return $this->name;
73    }
74
75    /**
76     * Add field index
77     *
78     * @param  int $i
79     * @return Form
80     */
81    public function addFieldIndex(int $i): Form
82    {
83        $this->fields[] = $i;
84        return $this;
85    }
86
87    /**
88     * Get field indices
89     *
90     * @return array
91     */
92    public function getFieldIndices(): array
93    {
94        return $this->fields;
95    }
96
97    /**
98     * Get number of fields
99     *
100     * @return int
101     */
102    public function getNumberOfFields(): int
103    {
104        return count($this->fields);
105    }
106
107    /**
108     * Get the form stream
109     *
110     * @param  int $i
111     * @return string
112     */
113    public function getStream(int $i): string
114    {
115        // Return the stream
116        $stream = "{$i} 0 obj\n<</Fields[";
117
118        $fields = '';
119        foreach ($this->fields as $value) {
120            $fields .= $value . ' 0 R ';
121        }
122        $fields = substr($fields, 0, -1);
123
124        $stream .= $fields . "]>>\nendobj\n\n";
125
126        return $stream;
127    }
128
129}