VatNumberChecksController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 22
c 4
b 0
f 0
dl 0
loc 59
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A beforeFilter() 0 12 4
A check() 0 16 3
1
<?php
2
App::uses('VatNumberChecksAppController', 'VatNumberCheck.Controller');
3
4
/**
5
 * VatNumberChecks Controller
6
 *
7
 * @property VatNumberCheck.VatNumberCheck $VatNumberCheck
8
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment VatNumberCheck.VatNumberCheck at position 0 could not be parsed: Unknown type name 'VatNumberCheck.VatNumberCheck' at position 0 in VatNumberCheck.VatNumberCheck.
Loading history...
9
class VatNumberChecksController extends VatNumberChecksAppController {
10
11
/**
12
 * Constructor
13
 *
14
 * @param CakeRequest $request Request instance.
0 ignored issues
show
Bug introduced by
The type CakeRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
 * @param CakeResponse $response Response instance.
0 ignored issues
show
Bug introduced by
The type CakeResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
 */
17
	public function __construct($request = null, $response = null) {
18
		parent::__construct($request, $response);
19
		$this->constructClasses();
20
		if (!$this->Components->attached('RequestHandler')
21
		) {
22
			$this->RequestHandler = $this->Components->load('RequestHandler');
0 ignored issues
show
Bug Best Practice introduced by
The property RequestHandler does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
		}
24
	}
25
26
/**
27
 * Called before the controller action.
28
 *
29
 * @return void
30
 */
31
	public function beforeFilter() {
32
		parent::beforeFilter();
33
34
		if (in_array($this->request->action, ['check'], true)) {
35
			// Disable Security component checks
36
			if ($this->Components->enabled('Security')) {
37
				$this->Components->disable('Security');
38
			}
39
40
			// Allow action without authentication
41
			if ($this->Components->enabled('Auth')) {
42
				$this->Auth->allow($this->request->action);
43
			}
44
		}
45
	}
46
47
/**
48
 * Checks a given vat number (from POST data).
49
 *
50
 * @return void
51
 */
52
	public function check() {
53
		$vatNumber = $this->request->data('vatNumber');
54
		$vatNumber = $this->VatNumberCheck->normalize($vatNumber);
55
56
		$jsonData = array_merge(compact('vatNumber'), ['status' => 'failure']);
57
		try {
58
			$vatNumberValid = $this->VatNumberCheck->check($vatNumber);
59
			if ($vatNumberValid) {
60
				$jsonData = array_merge(compact('vatNumber'), ['status' => 'ok']);
61
			}
62
		} catch (InternalErrorException $e) {
0 ignored issues
show
Bug introduced by
The type InternalErrorException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
			$this->response->statusCode(503);
64
		}
65
66
		$this->set(compact('jsonData'));
67
		$this->set('_serialize', 'jsonData');
68
	}
69
70
}
71