Passed
Pull Request — master (#2)
by
unknown
05:11
created

VatNumberCheck::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
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);
0 ignored issues
show
Bug introduced by
The method query() does not exist on VatNumberCheck\Utility\Model\VatNumberCheck. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
		/** @scrutinizer ignore-call */ 
58
  $result = $this->query('checkVat', $params);

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.

Loading history...
58
59
		return $result->valid ?? false;
60
	}
61
}