Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Password
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setRenderValue
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getRenderValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Form\Element\Input;
16
17use Pop\Form\Element;
18
19/**
20 * Form password element class
21 *
22 * @category   Pop
23 * @package    Pop\Form
24 * @author     Nick Sagona, III <nick@popphp.org>
25 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
26 * @license    https://www.popphp.org/license     New BSD License
27 * @version    5.0.0
28 */
29
30class Password extends Element\Input
31{
32
33    /**
34     * Flag to allow rendering the value
35     * @var bool
36     */
37    protected bool $renderValue = false;
38
39    /**
40     * Constructor
41     *
42     * Instantiate the password input form element
43     *
44     * @param  string  $name
45     * @param  ?string $value
46     * @param  ?string $indent
47     * @param  bool    $renderValue
48     */
49    public function __construct(string $name, $value = null, $indent = null, bool $renderValue = false)
50    {
51        parent::__construct($name, 'password', $value, $indent);
52        $this->setRenderValue($renderValue);
53    }
54
55    /**
56     * Set the render value flag
57     *
58     * @param  bool $renderValue
59     * @return Password
60     */
61    public function setRenderValue(bool $renderValue): Password
62    {
63        $this->renderValue = $renderValue;
64        return $this;
65    }
66
67    /**
68     * Get the render value flag
69     *
70     * @return bool
71     */
72    public function getRenderValue(): bool
73    {
74        return $this->renderValue;
75    }
76
77    /**
78     * Render the password element
79     *
80     * @param  int     $depth
81     * @param  ?string $indent
82     * @param  bool    $inner
83     * @return string
84     */
85    public function render(int $depth = 0, ?string $indent = null, bool $inner = false): string
86    {
87        if (!$this->renderValue) {
88            $this->setAttribute('value', '');
89        }
90        return parent::render($depth, $indent, $inner);
91    }
92
93}