Completed
Push — master ( da2dea...5ebe79 )
by Aimeos
22:25
created

JqadmController::setLocale()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 20
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 20
loc 20
rs 9.4286
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
6
 * @package laravel-package
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-package
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
		$content = $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
		return View::make('shop::admin.jqadm', array( 'content' => $content, 'site' => $site ) );
47
	}
48
49
50
	/**
51
	 * Returns the HTML code for a new resource object
52
	 *
53
	 * @param string Resource location, e.g. "product"
54
	 * @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...
55
	 * @return string Generated output
56
	 */
57 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...
58
	{
59
		if( config( 'shop.authorize', true ) ) {
60
			$this->authorize( 'admin' );
61
		}
62
63
		$cntl = $this->createClient( $site, $resource );
64
		$content = $cntl->create();
65
66
		return View::make('shop::admin.jqadm', array( 'content' => $content, 'site' => $site ) );
67
	}
68
69
70
	/**
71
	 * Deletes the resource object or a list of resource objects
72
	 *
73
	 * @param string Resource location, e.g. "product"
74
	 * @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...
75
	 * @param integer $id Unique resource ID
76
	 * @return string Generated output
77
	 */
78 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...
79
	{
80
		if( config( 'shop.authorize', true ) ) {
81
			$this->authorize( 'admin' );
82
		}
83
84
		$cntl = $this->createClient( $site, $resource );
85
		$content = $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...
86
87
		return View::make('shop::admin.jqadm', array( 'content' => $content, 'site' => $site ) );
88
	}
89
90
91
	/**
92
	 * Returns the HTML code for the requested resource object
93
	 *
94
	 * @param string Resource location, e.g. "product"
95
	 * @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...
96
	 * @param integer $id Unique resource ID
97
	 * @return string Generated output
98
	 */
99 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...
100
	{
101
		if( config( 'shop.authorize', true ) ) {
102
			$this->authorize( 'admin' );
103
		}
104
105
		$cntl = $this->createClient( $site, $resource );
106
		$content = $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...
107
108
		return View::make('shop::admin.jqadm', array( 'content' => $content, 'site' => $site ) );
109
	}
110
111
112
	/**
113
	 * Saves a new resource object
114
	 *
115
	 * @param string Resource location, e.g. "product"
116
	 * @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...
117
	 * @return string Generated output
118
	 */
119 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...
120
	{
121
		if( config( 'shop.authorize', true ) ) {
122
			$this->authorize( 'admin' );
123
		}
124
125
		$cntl = $this->createClient( $site, $resource );
126
		$content = ( $cntl->save() ? : $cntl->search() );
127
128
		return View::make('shop::admin.jqadm', array( 'content' => $content, 'site' => $site ) );
129
	}
130
131
132
	/**
133
	 * Returns the HTML code for a list of resource objects
134
	 *
135
	 * @param string Resource location, e.g. "product"
136
	 * @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...
137
	 * @return string Generated output
138
	 */
139 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...
140
	{
141
		if( config( 'shop.authorize', true ) ) {
142
			$this->authorize( 'admin' );
143
		}
144
145
		$cntl = $this->createClient( $site, $resource );
146
		$content = $cntl->search();
147
148
		return View::make('shop::admin.jqadm', array( 'content' => $content, 'site' => $site ) );
149
	}
150
151
152
	/**
153
	 * Returns the resource controller
154
	 *
155
	 * @param string $sitecode Unique site code
156
	 * @return \Aimeos\MShop\Context\Item\Iface Context item
157
	 */
158 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...
159
	{
160
		$lang = Input::get( 'lang', config( 'app.locale', 'en' ) );
161
162
		$aimeos = app( '\Aimeos\Shop\Base\Aimeos' )->get();
163
		$templatePaths = $aimeos->getCustomPaths( 'admin/jqadm/templates' );
164
165
		$context = app( '\Aimeos\Shop\Base\Context' )->get( false );
166
		$context = $this->setLocale( $context, $sitecode, $lang );
167
168
		$view = app( '\Aimeos\Shop\Base\View' )->create( $context->getConfig(), $templatePaths, $lang );
169
		$context->setView( $view );
170
171
		return \Aimeos\Admin\JQAdm\Factory::createClient( $context, $templatePaths, $resource );
172
	}
173
}
174