Completed
Push — master ( 0a4763...f5ea6d )
by Aimeos
49:24 queued 18:11
created

JqadmController::setLocale()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 20
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 20
loc 20
rs 9.4285
cc 2
eloc 11
nc 4
nop 3
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Controller
8
 */
9
10
11
namespace Aimeos\Shop\Controller;
12
13
use Illuminate\Support\Facades\View;
14
use Illuminate\Support\Facades\Input;
15
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
16
17
18
/**
19
 * Aimeos controller for the JQuery admin interface
20
 *
21
 * @package laravel
22
 * @subpackage Controller
23
 */
24
class JqadmController extends AdminController
25
{
26
	use AuthorizesRequests;
27
28
29
	/**
30
	 * Returns the HTML code for a copy of a resource object
31
	 *
32
	 * @param string Resource location, e.g. "product"
33
	 * @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...
34
	 * @param integer $id Unique resource ID
35
	 * @return string Generated output
36
	 */
37 View Code Duplication
	public function copyAction( $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...
38
	{
39
		if( config( 'shop.authorize', true ) ) {
40
			$this->authorize( 'admin' );
41
		}
42
43
		$cntl = $this->createClient( $site, $resource );
44
		return $this->getHtml( $site, $cntl->copy( $id ) );
0 ignored issues
show
Unused Code introduced by
The call to Iface::copy() has too many arguments starting with $id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
45
	}
46
47
48
	/**
49
	 * Returns the HTML code for a new resource object
50
	 *
51
	 * @param string Resource location, e.g. "product"
52
	 * @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...
53
	 * @return string Generated output
54
	 */
55 View Code Duplication
	public function createAction( $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...
56
	{
57
		if( config( 'shop.authorize', true ) ) {
58
			$this->authorize( 'admin' );
59
		}
60
61
		$cntl = $this->createClient( $site, $resource );
62
		return $this->getHtml( $site, $cntl->create() );
63
	}
64
65
66
	/**
67
	 * Deletes the resource object or a list of resource objects
68
	 *
69
	 * @param string Resource location, e.g. "product"
70
	 * @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...
71
	 * @param integer $id Unique resource ID
72
	 * @return string Generated output
73
	 */
74 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...
75
	{
76
		if( config( 'shop.authorize', true ) ) {
77
			$this->authorize( 'admin' );
78
		}
79
80
		$cntl = $this->createClient( $site, $resource );
81
		return $this->getHtml( $site, $cntl->delete( $id ) . $cntl->search() );
0 ignored issues
show
Unused Code introduced by
The call to Iface::delete() has too many arguments starting with $id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
82
	}
83
84
85
	/**
86
	 * Returns the HTML code for the requested resource object
87
	 *
88
	 * @param string Resource location, e.g. "product"
89
	 * @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...
90
	 * @param integer $id Unique resource ID
91
	 * @return string Generated output
92
	 */
93 View Code Duplication
	public function getAction( $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...
94
	{
95
		if( config( 'shop.authorize', true ) ) {
96
			$this->authorize( 'admin' );
97
		}
98
99
		$cntl = $this->createClient( $site, $resource );
100
		return $this->getHtml( $site, $cntl->get( $id ) );
0 ignored issues
show
Unused Code introduced by
The call to Iface::get() has too many arguments starting with $id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
101
	}
102
103
104
	/**
105
	 * Saves a new resource object
106
	 *
107
	 * @param string Resource location, e.g. "product"
108
	 * @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...
109
	 * @return string Generated output
110
	 */
111 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...
112
	{
113
		if( config( 'shop.authorize', true ) ) {
114
			$this->authorize( 'admin' );
115
		}
116
117
		$cntl = $this->createClient( $site, $resource );
118
		return $this->getHtml( $site, ( $cntl->save() ? : $cntl->search() ) );
119
	}
120
121
122
	/**
123
	 * Returns the HTML code for a list of resource objects
124
	 *
125
	 * @param string Resource location, e.g. "product"
126
	 * @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...
127
	 * @return string Generated output
128
	 */
129 View Code Duplication
	public function searchAction( $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...
130
	{
131
		if( config( 'shop.authorize', true ) ) {
132
			$this->authorize( 'admin' );
133
		}
134
135
		$cntl = $this->createClient( $site, $resource );
136
		return $this->getHtml( $site, $cntl->search() );
137
	}
138
139
140
	/**
141
	 * Returns the resource controller
142
	 *
143
	 * @param string $sitecode Unique site code
144
	 * @return \Aimeos\MShop\Context\Item\Iface Context item
145
	 */
146 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...
147
	{
148
		$lang = Input::get( 'lang', config( 'app.locale', 'en' ) );
149
150
		$aimeos = app( '\Aimeos\Shop\Base\Aimeos' )->get();
151
		$templatePaths = $aimeos->getCustomPaths( 'admin/jqadm/templates' );
152
153
		$context = app( '\Aimeos\Shop\Base\Context' )->get( false );
154
		$context = $this->setLocale( $context, $sitecode, $lang );
155
156
		$view = app( '\Aimeos\Shop\Base\View' )->create( $context->getConfig(), $templatePaths, $lang );
157
		$context->setView( $view );
158
159
		return \Aimeos\Admin\JQAdm\Factory::createClient( $context, $templatePaths, $resource );
160
	}
161
162
163
	/**
164
	 * Returns the generated HTML code
165
	 *
166
	 * @param string $site Unique site code
167
	 * @param string $content Content from admin client
168
	 * @return \Illuminate\Contracts\View\View View for rendering the output
169
	 */
170
	protected function getHtml( $site, $content )
0 ignored issues
show
Unused Code introduced by
The parameter $site is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
	{
172
		$version = app( '\Aimeos\Shop\Base\Aimeos' )->getVersion();
173
		$content = str_replace( ['{type}', '{version}'], ['Laravel', $version], $content );
174
175
		return View::make( 'shop::jqadm.index', array( 'content' => $content ) );
176
	}
177
178
179
	/**
180
	 * Sets the locale item in the given context
181
	 *
182
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
183
	 * @param string $sitecode Unique site code
184
	 * @param string $lang ISO language code, e.g. "en" or "en_GB"
185
	 * @return \Aimeos\MShop\Context\Item\Iface Modified context object
186
	 */
187 View Code Duplication
	protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $lang = null )
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...
188
	{
189
		$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
190
191
		try
192
		{
193
			$localeItem = $localeManager->bootstrap( $sitecode, '', '', false );
194
			$localeItem->setLanguageId( null );
195
			$localeItem->setCurrencyId( null );
196
		}
197
		catch( \Aimeos\MShop\Locale\Exception $e )
198
		{
199
			$localeItem = $localeManager->createItem();
200
		}
201
202
		$context->setLocale( $localeItem );
203
		$context->setI18n( app('\Aimeos\Shop\Base\I18n')->get( array( $lang ) ) );
204
205
		return $context;
206
	}
207
}
208