RequestFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 6
c 3
b 1
f 0
dl 0
loc 20
ccs 6
cts 6
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 4
1
<?php
2
/**
3
 * HTTP request object factory
4
 *
5
 * This factory should be used in index.php for request object initialization.
6
 * Example:
7
 *
8
 * $validator = (new Validator)->setAdapter(new PhpFilters);
9
 * $request = RequestFactory::create($_SERVER['CONTENT_TYPE'])->setValidator($validator);
10
 *
11
 * @file      RequestFactory.php
12
 *
13
 * PHP version 8.0+
14
 *
15
 * @author    Yancharuk Alexander <alex at itvault dot info>
16
 * @copyright © 2012-2021 Alexander Yancharuk <alex at itvault at info>
17
 * @date      2017-04-23 16:12
18
 * @license   The BSD 3-Clause License
19
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
20
 */
21
22
namespace Veles\Request;
23
24
class RequestFactory
25
{
26
	/**
27
	 * Create HTTP-request object depending on Content-type HTTP-header
28
	 *
29
	 * @param string $type Value of Content-type HTTP-header
30
	 *
31
	 * @return HttpRequestAbstract
32
	 */
33 9
	public static function create($type)
34
	{
35 9
		if (empty($type) || 0 === strpos($type, 'text/html')) {
36 4
			return new HttpGetRequest;
37
		}
38
39 5
		if (0 === strpos($type, 'application/json')) {
40 1
			return new HttpJsonRequest;
41
		}
42
43 4
		return new HttpPostRequest;
44
	}
45
}
46