Completed
Push — master ( 6ea955...957cdc )
by Aimeos
03:32
created

JqadmController::createClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 15
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 2
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
		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
167
	 * @param string $content
168
	 */
169
	protected function getHtml( $site, $content )
170
	{
171
		$content = str_replace( ['{type}', '{version}'], ['Laravel', $this->getVersion()], $content );
172
		$params = array( 'site' => $site, 'content' => $content );
173
174
		return View::make('shop::admin.jqadm', $params );
175
	}
176
}
177