Passed
Push — developer ( 748bda...0a7e9b )
by Mariusz
49:14 queued 14:14
created

Base::validateRequest()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
/**
3
 * Base controller class.
4
 *
5
 * @copyright YetiForce Sp. z o.o.
6
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
7
 * @author    Mariusz Krzaczkowski <[email protected]>
8
 */
9
10
namespace App\Controller;
11
12
use App\Request;
13
14
abstract class Base
0 ignored issues
show
Coding Style introduced by
Base does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
15
{
16
	/** @var \App\Headers Headers instance. */
17
	public $headers;
18
19
	/** @var Request Request object. */
20
	protected $request;
21
22
	/** @var string Module name. */
23
	protected $moduleName;
24
25
	/**
26
	 * Construct.
27
	 *
28
	 * @param \App\Request $request
29
	 */
30
	public function __construct(Request $request)
31
	{
32
		$this->headers = \App\Controller\Headers::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \App\Controller\Headers::getInstance() of type object<App\Controller\Headers> is incompatible with the declared type object<App\Headers> of property $headers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
		if (\App\Config::get('csrfProtection')) {
34
			require_once ROOT_DIRECTORY . '/config/csrf_config.php';
35
			\CsrfMagic\Csrf::init();
36
		}
37
		$this->request = $request;
38
		$this->moduleName = $request->getModule();
39
	}
40
41
	/**
42
	 * Login required.
43
	 *
44
	 * @return bool
45
	 */
46
	public function loginRequired(): bool
0 ignored issues
show
Coding Style introduced by
function loginRequired() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
47
	{
48
		return true;
49
	}
50
51
	/**
52
	 * Main action.
53
	 *
54
	 * @return void
55
	 */
56
	abstract public function process();
57
58
	/**
59
	 * Validates request. Checks type of request.
60
	 *
61
	 * @return void
62
	 */
63
	abstract public function validateRequest();
64
65
	/**
66
	 * Action invoke before process.
67
	 *
68
	 * @return void
69
	 */
70
	abstract public function preProcess();
71
72
	/**
73
	 * Action invoke after process.
74
	 *
75
	 * @return void
76
	 */
77
	abstract public function postProcess();
78
79
	/**
80
	 * Action invoke before process for AJAX.
81
	 *
82
	 * @return void
83
	 */
84
	abstract public function preProcessAjax();
85
86
	/**
87
	 * Action invoke after process for AJAX.
88
	 *
89
	 * @return void
90
	 */
91
	abstract public function postProcessAjax();
92
93
	/**
94
	 * Send headers.
95
	 */
96
	public function sendHeaders()
97
	{
98
		$this->headers->send();
99
	}
100
101
	/**
102
	 * Error handler.
103
	 *
104
	 * @param string $errno
0 ignored issues
show
Documentation introduced by
Should the type for parameter $errno not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
105
	 * @param string $errstr
106
	 * @param string $errfile
107
	 * @param string $errline
108
	 * @param string $errcontext
109
	 *
110
	 * @return void
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use NoType.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
111
	 */
112
	public static function exceptionErrorHandler(int $errno, string $errstr, $errfile, $errline, $errcontext)
0 ignored issues
show
Unused Code introduced by
The parameter $errfile 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 $errline 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 $errcontext 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...
113
	{
114
		throw new \App\Exceptions\AppException($errstr, $errno);
115
	}
116
}
117