Completed
Pull Request — master (#2)
by
unknown
05:39
created

VatNumberChecksController::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 2
1
<?php
2
namespace VatNumberCheck\Controller;
3
4
use Cake\Event\Event;
5
use Cake\Network\Exception\InternalErrorException;
6
use VatNumberCheck\Utility\VatNumberCheck;
7
/**
8
 * VatNumberChecks Controller.
9
 *
10
 * @property \Cake\Controller\Component\RequestHandlerComponent $RequestHandler
11
 * @property \VatNumberCheck\Utility\VatNumberCheck $VatNumberCheck
12
 */
13
class VatNumberChecksController extends AppController
14
{
15
/**
16
 * Constructor
17
 *
18
 * @param CakeRequest $request Request instance.
0 ignored issues
show
Bug introduced by
The type VatNumberCheck\Controller\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...
19
 * @param CakeResponse $response Response instance.
0 ignored issues
show
Bug introduced by
The type VatNumberCheck\Controller\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...
20
 */
21
	public function __construct($request = null, $response = null) {
22
		parent::__construct($request, $response);
23
		$this->constructClasses();
0 ignored issues
show
Bug introduced by
The method constructClasses() does not exist on VatNumberCheck\Controlle...tNumberChecksController. ( Ignorable by Annotation )

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

23
		$this->/** @scrutinizer ignore-call */ 
24
         constructClasses();

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...
24
		if (!$this->Components->attached('RequestHandler')) {
0 ignored issues
show
Bug Best Practice introduced by
The property Components does not exist on VatNumberCheck\Controlle...tNumberChecksController. Since you implemented __get, consider adding a @property annotation.
Loading history...
25
			$this->RequestHandler = $this->Components->load('RequestHandler');
26
		}
27
	}
28
29
/**
30
* Called before the controller action.
31
*
32
* @return void
33
*/
34
	public function beforeFilter() {
35
		parent::beforeFilter();
0 ignored issues
show
Bug introduced by
The call to Cake\Controller\Controller::beforeFilter() has too few arguments starting with event. ( Ignorable by Annotation )

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

35
		parent::/** @scrutinizer ignore-call */ 
36
          beforeFilter();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
36
		if (in_array($this->request->action, ['check'], true)) {
37
			// Disable Security component checks
38
			if ($this->Components->enabled('Security')) {
0 ignored issues
show
Bug Best Practice introduced by
The property Components does not exist on VatNumberCheck\Controlle...tNumberChecksController. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
				$this->Components->disable('Security');
40
			}
41
			// Allow action without authentication
42
			if ($this->Components->enabled('Auth')) {
43
				$this->Auth->allow($this->request->action);
44
			}
45
		}
46
	}
47
48
/**
49
* Checks a given vat number (from POST data).
50
*
51
* @return void
52
*/
53
	public function check() {
54
		$vatNumber = $this->request->data('vatNumber') ?: '';
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::data() has been deprecated: 3.4.0 Use withData() and getData() or getParsedBody() instead. ( Ignorable by Annotation )

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

54
		$vatNumber = /** @scrutinizer ignore-deprecated */ $this->request->data('vatNumber') ?: '';

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55
		$vatNumber = $this->VatNumberCheck->normalize($vatNumber);
0 ignored issues
show
Bug introduced by
It seems like $vatNumber can also be of type Cake\Http\ServerRequest; however, parameter $vatNumber of VatNumberCheck\Utility\VatNumberCheck::normalize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

55
		$vatNumber = $this->VatNumberCheck->normalize(/** @scrutinizer ignore-type */ $vatNumber);
Loading history...
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 (Exception $e) {
0 ignored issues
show
Bug introduced by
The type VatNumberCheck\Controller\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
63
			$this->response->statusCode(503);
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\Response::statusCode() has been deprecated: 3.4.0 Use `getStatusCode()` and `withStatus()` instead. ( Ignorable by Annotation )

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

63
			/** @scrutinizer ignore-deprecated */ $this->response->statusCode(503);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
64
		}
65
		$this->set(compact('jsonData'));
66
		$this->set('_serialize', 'jsonData');
67
	}
68
}