Completed
Push — master ( 270f06...04fd8b )
by ARCANEDEV
12:31
created

CurrencyValidator::validateCurrencyIso()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 11
rs 9.4285
1
<?php namespace Arcanedev\Currencies\Validators;
2
3
use Arcanedev\Currencies\Contracts\CurrencyManager;
4
5
/**
6
 * Class     CurrencyValidator
7
 *
8
 * @package  Arcanedev\Currencies\Validators
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class CurrencyValidator
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /** @var  \Arcanedev\Currencies\Contracts\CurrencyManager */
18
    protected $manager;
19
20
    /* ------------------------------------------------------------------------------------------------
21
     |  Constructor
22
     | ------------------------------------------------------------------------------------------------
23
     */
24
    /**
25
     * CurrencyValidator constructor.
26
     *
27
     * @param  \Arcanedev\Currencies\Contracts\CurrencyManager  $manager
28
     */
29
    public function __construct(CurrencyManager $manager)
30
    {
31
        $this->manager = $manager;
32
    }
33
34
    /* ------------------------------------------------------------------------------------------------
35
     |  Main Functions
36
     | ------------------------------------------------------------------------------------------------
37
     */
38
    public function validateCurrencyIso($attribute, $value, $parameters, $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $attribute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
        $manager = $this->manager;
41
42
        /** @var \Illuminate\Validation\Validator $validator */
43
        $validator->addReplacer('currency_iso', function($message, $attribute, $rule, $parameters) use ($manager) {
0 ignored issues
show
Unused Code introduced by
The parameter $rule is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
            return trans("currencies::validation.currency.iso", ['attribute' => $attribute]);
45
        });
46
47
        return in_array($value, $manager->currencies()->keys()->toArray());
48
    }
49
50
    /**
51
     * @param  string                            $attribute
52
     * @param  mixed                             $value
53
     * @param  array                             $parameters
54
     * @param  \Illuminate\Validation\Validator  $validator
55
     *
56
     * @return bool
57
     */
58
    public function validateCurrencySupported($attribute, $value, $parameters, $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $attribute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60
        $manager = $this->manager;
61
62
        /** @var \Illuminate\Validation\Validator $validator */
63
        $validator->addReplacer('currency_supported', function($message, $attribute, $rule, $parameters) use ($manager) {
0 ignored issues
show
Unused Code introduced by
The parameter $rule is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
            return trans("currencies::validation.currency.supported", ['attribute' => $attribute]);
65
        });
66
67
        return in_array($value, $manager->getSupported());
68
    }
69
}
70