Completed
Push — master ( 69b1d3...8c6c3a )
by Song
02:45
created

Currency::digits()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
class Currency extends Text
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $symbol = '$';
11
12
    /**
13
     * @var array
14
     */
15
    protected static $js = [
16
        '/vendor/laravel-admin/AdminLTE/plugins/input-mask/jquery.inputmask.bundle.min.js',
17
    ];
18
19
    /**
20
     * @see https://github.com/RobinHerbots/Inputmask#options
21
     *
22
     * @var array
23
     */
24
    protected $options = [
25
        'alias'              => 'currency',
26
        'radixPoint'         => '.',
27
        'prefix'             => '',
28
        'removeMaskOnSubmit' => true,
29
    ];
30
31
    /**
32
     * Set symbol for currency field.
33
     *
34
     * @param string $symbol
35
     * @return $this
36
     */
37
    public function symbol($symbol)
38
    {
39
        $this->symbol = $symbol;
40
41
        return $this;
42
    }
43
44
    /**
45
     * Set digits for input number
46
     *
47
     * @param integer $digits
48
     * @return $this
49
     */
50
    public function digits($digits)
51
    {
52
        return $this->options(compact('digits'));
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function prepare($value)
59
    {
60
        return (float) $value;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $options = json_encode($this->options);
69
70
        $this->script = <<<EOT
71
$('{$this->getElementClassSelector()}').inputmask($options);
72
EOT;
73
74
        $this->prepend($this->symbol)
75
            ->defaultAttribute('style', 'width: 120px');
76
77
        return parent::render();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::render(); of type string|Illuminate\View\V...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 77 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
78
    }
79
}
80