1
|
|
|
<?php |
2
|
|
|
namespace VatNumberCheck\Utility\Model; |
3
|
|
|
use Cake\Core\Configure; |
4
|
|
|
use Cake\Network\Exception\InternalErrorException; |
5
|
|
|
use VatNumberCheck\Soap\Soap; |
6
|
|
|
use VatNumberCheck\Utility\Model\App; |
7
|
|
|
/** |
8
|
|
|
* VatNumberCheck Model. |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
class VatNumberCheck extends App |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The name of the soap connection that this Model uses. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
public $useDbConfig = 'vatNumberCheckWebservice'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Use table. |
22
|
|
|
* |
23
|
|
|
* @var mixed False or table name |
24
|
|
|
*/ |
25
|
|
|
public $useTable = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The (translation) domain to be used for extracted validation messages in models. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
public $validationDomain = 'vat_number_check'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Normalizes a VAT number. |
36
|
|
|
* |
37
|
|
|
* @param string $vatNumber A VAT number |
38
|
|
|
* @return string A (normalized) VAT number |
39
|
|
|
*/ |
40
|
|
|
public function normalize(string $vatNumber) : string { |
41
|
|
|
return preg_replace('/[^A-Z0-9]/', '', strtoupper($vatNumber)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Checks a given VAT number. |
46
|
|
|
* |
47
|
|
|
* @param string $vatNumber A VAT number |
48
|
|
|
* @return bool Valid or not |
49
|
|
|
* @throws InternalErrorException |
50
|
|
|
*/ |
51
|
|
|
public function check(string $vatNumber) : bool { |
52
|
|
|
$memberStateCode = substr($vatNumber, 0, 2); |
53
|
|
|
$number = substr($vatNumber, 2); |
54
|
|
|
|
55
|
|
|
$params = ['countryCode' => $memberStateCode, 'vatNumber' => $number]; |
56
|
|
|
|
57
|
|
|
$result = $this->query('checkVat', $params); |
|
|
|
|
58
|
|
|
|
59
|
|
|
return $result->valid ?? false; |
60
|
|
|
} |
61
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.