Passed
Push — main ( fac3c3...502827 )
by Stefan
02:24
created

FormCur   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
dl 0
loc 31
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onParentSet() 0 14 4
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Formgenerator;
5
6
/**
7
 * Input field for currency value.
8
 * - always right aligned
9
 * 
10
 * #### History
11
 * - *2020-05-12*   initial version
12
 * - *2021-01-07*   PHP 7.4
13
 *
14
 * @package Formgenerator
15
 * @version 1.1.0
16
 * @author Stefanius <[email protected]>
17
 * @copyright MIT License - see the LICENSE file for details
18
*/
19
class FormCur extends FormFloat
20
{
21
    /**
22
     * Creates input field for currency values.
23
     * @param string $strName
24
     * @param int $iSize
25
     * @param int $wFlags    default value = 0
26
     */
27
    public function __construct(string $strName, int $iSize, int $wFlags = 0) 
28
    {
29
        parent::__construct($strName, $iSize, 2, $wFlags);
30
    }
31
    
32
    /**
33
     * get format from configuration: <ul>
34
     * <li> currency symbol (default: from locale settings) </li></ul>
35
     */
36
    protected function onParentSet() : void
37
    {
38
        parent::onParentSet();
39
        
40
        $li = localeconv();
41
        
42
        $this->strDP = $this->oFG->getConfig()->getString('Currency.DecimalPoint', $this->strDP);
43
        $this->strTS = $this->oFG->getConfig()->getString('Currency.ThousandsSep', $this->strTS);
44
        
45
        $this->addAttribute('data-validation', 'float:' . ($this->bEmptyAllowed ? 'e' : 'x') . $this->iDec . $this->strDP . $this->strTS);
46
        $this->setPlaceholder($this->oFG->getConfig()->getString('Currency.Placeholder'));
47
        
48
        if ($this->oFlags->isSet(FormFlags::ADD_CUR)) {
49
            $this->strSuffix = $this->oFG->getConfig()->getString('Currency.Symbol', ($li['currency_symbol'] ?: 'USD'));
50
        }
51
    }
52
}
53