HttpPostRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 3 1
A check() 0 12 2
1
<?php
2
/**
3
 * Processing HTTP-request with POST body
4
 *
5
 * @file      HttpPostRequest.php
6
 *
7
 * PHP version 8.0+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2021 Alexander Yancharuk <alex at itvault at info>
11
 * @date      2017-01-18 10:34
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\Request;
17
18
use Veles\Exceptions\Http\UnprocessableException;
19
20
/**
21
 * Class   HttpPostRequest
22
 *
23
 * @author Yancharuk Alexander <alex at itvault at info>
24
 */
25
class HttpPostRequest extends HttpRequestAbstract
26
{
27
	/**
28
	 * Getting http-request body
29
	 *
30
	 * @return array
31
	 */
32 7
	public function getBody()
33
	{
34 7
		return $_POST;
35
	}
36
37
	/**
38
	 * Check input according definitions
39
	 *
40
	 * @param mixed $definitions
41
	 *
42
	 * @throws UnprocessableException
43
	 */
44 4
	public function check($definitions)
45
	{
46 4
		$raw_data  = $this->getBody();
47 4
		$validator = $this->getValidator();
48
49 4
		$validator->check($raw_data, $definitions);
50
51 4
		if (!$validator->isValid()) {
52 1
			throw new UnprocessableException($validator->getErrors());
53
		}
54
55 3
		$this->setData($validator->getData());
56
	}
57
}
58