Completed
Push — master ( 74bf43...ea64de )
by Aimeos
14:12
created

JsonapiController::deleteAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2017
6
 * @package laravel
7
 * @subpackage Controller
8
 */
9
10
11
namespace Aimeos\Shop\Controller;
12
13
use Illuminate\Http\Request;
14
use Illuminate\Routing\Controller;
15
use Illuminate\Support\Facades\Input;
16
use Illuminate\Support\Facades\Route;
17
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
18
use Psr\Http\Message\ServerRequestInterface;
19
use Zend\Diactoros\Response;
20
21
22
/**
23
 * Aimeos controller for the JSON REST API
24
 *
25
 * @package laravel
26
 * @subpackage Controller
27
 */
28
class JsonapiController extends Controller
29
{
30
	/**
31
	 * Deletes the resource object or a list of resource objects
32
	 *
33
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
34
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
35
	 */
36
	public function deleteAction( ServerRequestInterface $request )
37
	{
38
		return $this->createClient()->delete( $request, new Response() );
39
	}
40
41
42
	/**
43
	 * Returns the requested resource object or list of resource objects
44
	 *
45
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
46
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
47
	 */
48
	public function getAction( ServerRequestInterface $request )
49
	{
50
		return $this->createClient()->get( $request, new Response() );
51
	}
52
53
54
	/**
55
	 * Updates a resource object or a list of resource objects
56
	 *
57
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
58
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
59
	 */
60
	public function patchAction( ServerRequestInterface $request )
61
	{
62
		return $this->createClient()->patch( $request, new Response() );
63
	}
64
65
66
	/**
67
	 * Creates a new resource object or a list of resource objects
68
	 *
69
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
70
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
71
	 */
72
	public function postAction( ServerRequestInterface $request )
73
	{
74
		return $this->createClient()->post( $request, new Response() );
75
	}
76
77
78
	/**
79
	 * Creates or updates a single resource object
80
	 *
81
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
82
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
83
	 */
84
	public function putAction( ServerRequestInterface $request )
85
	{
86
		return $this->createClient()->put( $request, new Response() );
87
	}
88
89
90
	/**
91
	 * Returns the available HTTP verbs and the resource URLs
92
	 *
93
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
94
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
95
	 */
96
	public function optionsAction( ServerRequestInterface $request )
97
	{
98
		return $this->createClient()->options( $request, new Response() );
99
	}
100
101
102
	/**
103
	 * Returns the JsonAdm client
104
	 *
105
	 * @return \Aimeos\Client\JsonApi\Iface JsonApi client
106
	 */
107
	protected function createClient()
108
	{
109
		$site = Route::input( 'site', Input::get( 'site', 'default' ) );
0 ignored issues
show
Unused Code introduced by
$site is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
110
		$lang = Input::get( 'lang', config( 'app.locale', 'en' ) );
111
		$resource = Route::input( 'resource' );
112
113
		$tmplPaths = app( '\Aimeos\Shop\Base\Aimeos' )->get()->getCustomPaths( 'client/jsonapi/templates' );
114
115
		$context = app( '\Aimeos\Shop\Base\Context' )->get();
116
		$context->setView( app( '\Aimeos\Shop\Base\View' )->create( $context, $tmplPaths, $lang ) );
117
118
		return \Aimeos\Client\JsonApi\Factory::createClient( $context, $tmplPaths, $resource );
119
	}
120
}
121