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
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\Form\Element\Input;
15
16use Pop\Form\Element;
17
18/**
19 * Form password element class
20 *
21 * @category   Pop
22 * @package    Pop\Form
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    4.0.0
27 */
28
29class Password extends Element\Input
30{
31
32    /**
33     * Flag to allow rendering the value
34     * @var bool
35     */
36    protected bool $renderValue = false;
37
38    /**
39     * Constructor
40     *
41     * Instantiate the password input form element
42     *
43     * @param  string  $name
44     * @param  ?string $value
45     * @param  ?string $indent
46     * @param  bool    $renderValue
47     */
48    public function __construct(string $name, $value = null, $indent = null, bool $renderValue = false)
49    {
50        parent::__construct($name, 'password', $value, $indent);
51        $this->setRenderValue($renderValue);
52    }
53
54    /**
55     * Set the render value flag
56     *
57     * @param  bool $renderValue
58     * @return Password
59     */
60    public function setRenderValue(bool $renderValue): Password
61    {
62        $this->renderValue = $renderValue;
63        return $this;
64    }
65
66    /**
67     * Get the render value flag
68     *
69     * @return bool
70     */
71    public function getRenderValue(): bool
72    {
73        return $this->renderValue;
74    }
75
76    /**
77     * Render the password element
78     *
79     * @param  int     $depth
80     * @param  ?string $indent
81     * @param  bool    $inner
82     * @return string
83     */
84    public function render(int $depth = 0, ?string $indent = null, bool $inner = false): string
85    {
86        if (!$this->renderValue) {
87            $this->setAttribute('value', '');
88        }
89        return parent::render($depth, $indent, $inner);
90    }
91
92}