Issues (138)

src/Elements/Money.php (1 issue)

Labels
Severity
1
<?php
2
3
use ByTIC\Money\Money;
4
5
class Nip_Form_Element_Money extends Nip_Form_Element_Number
6
{
7
    protected $_type = 'money';
8
9
    public function init()
10
    {
11
        parent::init();
12
        $this->setOption('currency', '');
13
    }
14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function setValue($value)
19
    {
20
        if ($value instanceof Money) {
21
            /** @var Money $value */
22
            $scale = $value::getCurrencies()->subunitFor($value->getCurrency());
23
24
            $step = pow(1 / 10, $scale);
25
            $this->setAttrib('step', $step);
26
            $this->setOption('currency', $value->getCurrency());
27
            $value = $value->formatByDecimal();
28
        }
29
        return parent::setValue($value);
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function getValue($requester = 'abstract')
36
    {
37
        $return = parent::getValue($requester);
38
        if ($requester == 'model') {
39
            return Money::parseByDecimal($return, $this->getOption('currency'));
0 ignored issues
show
Are you sure the usage of $this->getOption('currency') targeting Nip\Form\Elements\AbstractElement::getOption() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
        }
41
        return $return;
42
    }
43
}
44