Completed
Push — master ( 960354...758f3f )
by Aimeos
04:30
created

JqadmController::deleteAction()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 11
loc 11
rs 9.4286
cc 3
eloc 6
nc 4
nop 3
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015
6
 * @package laravel-package
7
 * @subpackage Controller
8
 */
9
10
11
namespace Aimeos\Shop\Controller;
12
13
use Illuminate\Routing\Controller;
14
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
15
16
17
/**
18
 * Aimeos controller for the JQuery admin interface
19
 *
20
 * @package laravel-package
21
 * @subpackage Controller
22
 */
23
class JqadmController extends Controller
24
{
25
	use AuthorizesRequests;
26
27
28
	/**
29
	 * Returns the HTML code for a copy of a resource object
30
	 *
31
	 * @param string Resource location, e.g. "product"
32
	 * @param string $sitecode Unique site code
0 ignored issues
show
Bug introduced by
There is no parameter named $sitecode. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33
	 * @param integer $id Unique resource ID
34
	 * @return string Generated output
35
	 */
36
	public function copyAction( $site = 'default', $resource, $id )
37
	{
38
		if( config( 'shop.authorize', true ) ) {
39
			$this->authorize( 'admin' );
40
		}
41
42
		$cntl = $this->createClient( $site, $resource );
43
		$content = $cntl->copy( $id );
0 ignored issues
show
Bug introduced by
The method copy() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
45
		return \View::make('shop::admin.jqadm', array( 'content' => $content ) );
46
	}
47
48
49
	/**
50
	 * Returns the HTML code for a new resource object
51
	 *
52
	 * @param string Resource location, e.g. "product"
53
	 * @param string $sitecode Unique site code
0 ignored issues
show
Bug introduced by
There is no parameter named $sitecode. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
	 * @return string Generated output
55
	 */
56
	public function createAction( $site = 'default', $resource )
57
	{
58
		if( config( 'shop.authorize', true ) ) {
59
			$this->authorize( 'admin' );
60
		}
61
62
		$cntl = $this->createClient( $site, $resource );
63
		$content = $cntl->create( $id );
0 ignored issues
show
Bug introduced by
The variable $id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The method create() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
65
		return \View::make('shop::admin.jqadm', array( 'content' => $content ) );
66
	}
67
68
69
	/**
70
	 * Deletes the resource object or a list of resource objects
71
	 *
72
	 * @param string Resource location, e.g. "product"
73
	 * @param string $sitecode Unique site code
0 ignored issues
show
Bug introduced by
There is no parameter named $sitecode. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
74
	 * @param integer $id Unique resource ID
75
	 * @return string Generated output
76
	 */
77 View Code Duplication
	public function deleteAction( $site = 'default', $resource, $id )
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
	{
79
		if( config( 'shop.authorize', true ) ) {
80
			$this->authorize( 'admin' );
81
		}
82
83
		$cntl = $this->createClient( $site, $resource );
84
		$content = ( $cntl->delete( $id ) ? : $cntl->search() );
0 ignored issues
show
Bug introduced by
The method delete() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method search() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
86
		return \View::make('shop::admin.jqadm', array( 'content' => $content ) );
87
	}
88
89
90
	/**
91
	 * Returns the HTML code for the requested resource object
92
	 *
93
	 * @param string Resource location, e.g. "product"
94
	 * @param string $sitecode Unique site code
0 ignored issues
show
Bug introduced by
There is no parameter named $sitecode. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
95
	 * @param integer $id Unique resource ID
96
	 * @return string Generated output
97
	 */
98
	public function getAction( $site = 'default', $resource, $id )
99
	{
100
		if( config( 'shop.authorize', true ) ) {
101
			$this->authorize( 'admin' );
102
		}
103
104
		$cntl = $this->createClient( $site, $resource );
105
		$content = $cntl->get( $id );
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
107
		return \View::make('shop::admin.jqadm', array( 'content' => $content ) );
108
	}
109
110
111
	/**
112
	 * Saves a new resource object
113
	 *
114
	 * @param string Resource location, e.g. "product"
115
	 * @param string $sitecode Unique site code
0 ignored issues
show
Bug introduced by
There is no parameter named $sitecode. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
116
	 * @return string Generated output
117
	 */
118 View Code Duplication
	public function saveAction( $site = 'default', $resource )
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
	{
120
		if( config( 'shop.authorize', true ) ) {
121
			$this->authorize( 'admin' );
122
		}
123
124
		$cntl = $this->createClient( $site, $resource );
125
		$content = ( $cntl->save() ? : $cntl->search() );
0 ignored issues
show
Bug introduced by
The method save() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method search() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
126
127
		return \View::make('shop::admin.jqadm', array( 'content' => $content ) );
128
	}
129
130
131
	/**
132
	 * Returns the HTML code for a list of resource objects
133
	 *
134
	 * @param string Resource location, e.g. "product"
135
	 * @param string $sitecode Unique site code
0 ignored issues
show
Bug introduced by
There is no parameter named $sitecode. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
136
	 * @return string Generated output
137
	 */
138
	public function searchAction( $site = 'default', $resource )
139
	{
140
		if( config( 'shop.authorize', true ) ) {
141
			$this->authorize( 'admin' );
142
		}
143
144
		$cntl = $this->createClient( $site, $resource );
145
		$content = $cntl->search();
0 ignored issues
show
Bug introduced by
The method search() does not seem to exist on object<Aimeos\MShop\Context\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
146
147
		return \View::make('shop::admin.jqadm', array( 'content' => $content ) );
148
	}
149
150
151
	/**
152
	 * Returns the resource controller
153
	 *
154
	 * @param string $sitecode Unique site code
155
	 * @return \Aimeos\MShop\Context\Item\Iface Context item
156
	 */
157 View Code Duplication
	protected function createClient( $sitecode, $resource )
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
	{
159
		$lang = \Input::get( 'lang', config( 'app.locale', 'en' ) );
160
161
		$aimeos = app( '\Aimeos\Shop\Base\Aimeos' )->get();
162
		$templatePaths = $aimeos->getCustomPaths( 'controller/jqadm/templates' );
163
164
		$context = app( '\Aimeos\Shop\Base\Context' )->get( false );
165
		$context = $this->setLocale( $context, $sitecode, $lang );
166
167
		$view = app( '\Aimeos\Shop\Base\View' )->create( $context->getConfig(), $templatePaths, $lang );
168
		$context->setView( $view );
169
170
		return \Aimeos\Client\JQAdm\Factory::createClient( $context, $templatePaths, $resource );
171
	}
172
173
174
	/**
175
	 * Sets the locale item in the given context
176
	 *
177
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
178
	 * @param string $sitecode Unique site code
179
	 * @param string $lang ISO language code, e.g. "en" or "en_GB"
180
	 * @return \Aimeos\MShop\Context\Item\Iface Modified context object
181
	 */
182 View Code Duplication
	protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode, $lang )
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
183
	{
184
		$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
185
186
		try
187
		{
188
			$localeItem = $localeManager->bootstrap( $sitecode, '', '', false );
189
			$localeItem->setLanguageId( null );
190
			$localeItem->setCurrencyId( null );
191
		}
192
		catch( \Aimeos\MShop\Locale\Exception $e )
193
		{
194
			$localeItem = $localeManager->createItem();
195
		}
196
197
		$context->setLocale( $localeItem );
198
		$context->setI18n( app('\Aimeos\Shop\Base\I18n')->get( array( $lang ) ) );
199
200
		return $context;
201
	}
202
}
203