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

VatCalculatorValidatorExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 4
c 2
b 1
f 1
lcom 0
cbo 1
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A validateVatNumber() 0 8 2
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