Completed
Push — master ( 42a773...a9c19a )
by Marcel
18:32 queued 08:31
created

VatCalculatorValidatorExtension::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 2
eloc 5
c 2
b 1
f 1
nc 2
nop 5
dl 0
loc 10
rs 9.4285
1
<?php
2
3
namespace Mpociot\VatCalculator\Validators;
4
5
use Illuminate\Validation\Validator;
6
use Mpociot\VatCalculator\Exceptions\VATCheckUnavailableException;
7
use Mpociot\VatCalculator\Facades\VatCalculator;
8
9
class VatCalculatorValidatorExtension extends Validator
10
{
11
    /**
12
     * Creates a new instance of ValidatorExtension.
13
     */
14
    public function __construct($translator, $data, $rules, $messages, array $customAttributes = [])
15
    {
16
        // Set custom validation error messages
17
        if (!isset($messages['vat_number'])) {
18
            $messages['vat_number'] = $translator->get(
19
                'vatnumber-validator::validation.vat_number'
20
            );
21
        }
22
        parent::__construct($translator, $data, $rules, $messages, $customAttributes);
23
    }
24
25
    /**
26
     * Usage: vat_number.
27
     *
28
     * @param string $attribute
29
     * @param mixed  $value
30
     * @param array  $parameters
31
     *
32
     * @return bool
33
     */
34
    public function validateVatNumber($attribute, $value, $parameters)
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...
35
    {
36
        try {
37
            return VatCalculator::isValidVATNumber($value);
38
        } catch (VATCheckUnavailableException $e) {
39
            return false;
40
        }
41
    }
42
}
43