RestApiController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 25
ccs 5
cts 5
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 3 1
A index() 0 5 1
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