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

RestApiController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 28
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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