RestApiController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Base controller for REST API
4
 *
5
 * @file      RestApiController.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      2016-12-07 18:54
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\Controllers;
17
18
use Veles\Exceptions\Http\NotAllowedException;
19
20
/**
21
 * Class   RestApiController
22
 *
23
 * @author Yancharuk Alexander <alex at itvault at info>
24
 */
25
class RestApiController extends BaseController
26
{
27
	/**
28
	 * Call specific method depending on request method
29
	 *
30
	 * @return array|null
31
	 */
32 10
	public function index(): ?array
33
	{
34 10
		$method = strtolower($_SERVER['REQUEST_METHOD']);
35
36 10
		return $this->$method();
37
	}
38
39
	/**
40
	 * For not defined methods return 405 response
41
	 *
42
	 * @param $name
43
	 * @param $arguments
44
	 *
45
	 * @throws NotAllowedException
46
	 */
47 6
	public function __call($name, $arguments)
48
	{
49 6
		throw new NotAllowedException($this);
50
	}
51
}
52