Completed
Push — development ( 8fc14f...221b3d )
by Alexander
03:23
created

RestApiController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Base controller for REST API
4
 *
5
 * @file      RestApiController.php
6
 *
7
 * PHP version 5.6+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2017 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
	 * @throws NotAllowedException
32
	 */
33 6
	public function index()
34
	{
35 6
		$method = strtolower($_SERVER['REQUEST_METHOD']);
36
37 6
		return $this->$method();
38
	}
39
40
	/**
41
	 * For not defined methods return 405 response
42
	 *
43
	 * @param $name
44
	 * @param $arguments
45
	 *
46
	 * @throws NotAllowedException
47
	 */
48 4
	public function __call($name, $arguments)
49
	{
50 4
		throw new NotAllowedException($this);
51
	}
52
}
53