Issues (145)

src/Controller/JqadmController.php (25 issues)

1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 */
7
8
9
namespace Aimeos\Shop\Controller;
10
11
use Illuminate\Support\Facades\View;
12
use Illuminate\Support\Facades\Route;
13
use Illuminate\Support\Facades\Request;
14
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
15
16
17
/**
18
 * Aimeos controller for the JQuery admin interface
19
 */
20
class JqadmController extends AdminController
21
{
22
	use AuthorizesRequests;
23
24
25
	/**
26
	 * Returns the JS file content
27
	 *
28
	 * @return \Illuminate\Http\Response Response object containing the generated output
29
	 */
30
	public function fileAction()
31
	{
32
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
33
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
34
		}
35
36
		$files = [];
37
		$aimeos = app( 'aimeos' )->get();
38
		$name = Route::input( 'name', Request::get( 'name' ) );
39
40
		foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths )
41
		{
42
			foreach( $paths as $path ) {
43
				$files[] = $base . '/' . $path;
44
			}
45
		}
46
47
		$response = response( \Aimeos\Admin\JQAdm\Bundle::get( $files, $name ) );
48
49
		if( str_ends_with( $name, 'js' ) ) {
50
			$response->header( 'Content-Type', 'application/javascript' );
51
		} elseif( str_ends_with( $name, 'css' ) ) {
52
			$response->header( 'Content-Type', 'text/css' );
53
		}
54
55
		return $response->header( 'Cache-Control', 'public, max-age=3600' );
56
	}
57
58
59
	/**
60
	 * Returns the HTML code for batch operations on a resource object
61
	 *
62
	 * @return string Generated output
63
	 */
64
	public function batchAction()
65
	{
66
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
67
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
68
		}
69
70
		$cntl = $this->createAdmin();
71
72
		if( ( $html = $cntl->batch() ) == '' ) {
73
			return $cntl->response();
74
		}
75
76
		return $this->getHtml( (string) $html );
77
	}
78
79
80
	/**
81
	 * Returns the HTML code for a copy of a resource object
82
	 *
83
	 * @return string Generated output
84
	 */
85
	public function copyAction()
86
	{
87
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
88
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
89
		}
90
91
		$cntl = $this->createAdmin();
92
93
		if( ( $html = $cntl->copy() ) == '' ) {
94
			return $cntl->response();
95
		}
96
97
		return $this->getHtml( (string) $html );
98
	}
99
100
101
	/**
102
	 * Returns the HTML code for a new resource object
103
	 *
104
	 * @return string Generated output
105
	 */
106
	public function createAction()
107
	{
108
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
109
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
110
		}
111
112
		$cntl = $this->createAdmin();
113
114
		if( ( $html = $cntl->create() ) == '' ) {
115
			return $cntl->response();
116
		}
117
118
		return $this->getHtml( (string) $html );
119
	}
120
121
122
	/**
123
	 * Deletes the resource object or a list of resource objects
124
	 *
125
	 * @return string Generated output
126
	 */
127
	public function deleteAction()
128
	{
129
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

129
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

129
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
130
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
131
		}
132
133
		$cntl = $this->createAdmin();
134
135
		if( ( $html = $cntl->delete() ) == '' ) {
136
			return $cntl->response();
137
		}
138
139
		return $this->getHtml( (string) $html );
140
	}
141
142
143
	/**
144
	 * Exports the data for a resource object
145
	 *
146
	 * @return string Generated output
147
	 */
148
	public function exportAction()
149
	{
150
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

150
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

150
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
151
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
152
		}
153
154
		$cntl = $this->createAdmin();
155
156
		if( ( $html = $cntl->export() ) == '' ) {
157
			return $cntl->response();
158
		}
159
160
		return $this->getHtml( (string) $html );
161
	}
162
163
164
	/**
165
	 * Returns the HTML code for the requested resource object
166
	 *
167
	 * @return string Generated output
168
	 */
169
	public function getAction()
170
	{
171
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

171
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

171
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
172
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
173
		}
174
175
		$cntl = $this->createAdmin();
176
177
		if( ( $html = $cntl->get() ) == '' ) {
178
			return $cntl->response();
179
		}
180
181
		return $this->getHtml( (string) $html );
182
	}
183
184
185
	/**
186
	 * Imports the data for a resource object
187
	 *
188
	 * @return string Generated output
189
	 */
190
	public function importAction()
191
	{
192
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

192
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

192
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
193
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
194
		}
195
196
		$cntl = $this->createAdmin();
197
198
		if( ( $html = $cntl->import() ) == '' ) {
199
			return $cntl->response();
200
		}
201
202
		return $this->getHtml( (string) $html );
203
	}
204
205
206
	/**
207
	 * Saves a new resource object
208
	 *
209
	 * @return string Generated output
210
	 */
211
	public function saveAction()
212
	{
213
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

213
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

213
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
214
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
215
		}
216
217
		$cntl = $this->createAdmin();
218
219
		if( ( $html = $cntl->save() ) == '' ) {
220
			return $cntl->response();
221
		}
222
223
		return $this->getHtml( (string) $html );
224
	}
225
226
227
	/**
228
	 * Returns the HTML code for a list of resource objects
229
	 *
230
	 * @return string Generated output
231
	 */
232
	public function searchAction()
233
	{
234
		if( config( 'shop.authorize', true ) ) {
0 ignored issues
show
The call to config() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

234
		if( /** @scrutinizer ignore-call */ config( 'shop.authorize', true ) ) {

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. Please note the @ignore annotation hint above.

Loading history...
'shop.authorize' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

234
		if( config( /** @scrutinizer ignore-type */ 'shop.authorize', true ) ) {
Loading history...
235
			$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] );
236
		}
237
238
		$cntl = $this->createAdmin();
239
240
		if( ( $html = $cntl->search() ) == '' ) {
241
			return $cntl->response();
242
		}
243
244
		return $this->getHtml( (string) $html );
245
	}
246
247
248
	/**
249
	 * Returns the resource controller
250
	 *
251
	 * @return \Aimeos\Admin\JQAdm\Iface JQAdm client
252
	 */
253
	protected function createAdmin() : \Aimeos\Admin\JQAdm\Iface
254
	{
255
		$site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) );
0 ignored issues
show
'shop.mshop.locale.site' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

255
		$site = Route::input( 'site', Request::get( 'site', config( /** @scrutinizer ignore-type */ 'shop.mshop.locale.site', 'default' ) ) );
Loading history...
The call to config() has too many arguments starting with 'default'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

255
		$site = Route::input( 'site', Request::get( 'site', /** @scrutinizer ignore-call */ config( 'shop.mshop.locale.site', 'default' ) ) );

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. Please note the @ignore annotation hint above.

Loading history...
256
		$lang = Request::get( 'locale', config( 'app.locale', 'en' ) );
257
		$resource = Route::input( 'resource' );
258
259
		$aimeos = app( 'aimeos' )->get();
260
261
		$context = app( 'aimeos.context' )->get( false, 'backend' );
262
		$context->setI18n( app( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) );
263
		$context->setLocale( app( 'aimeos.locale' )->getBackend( $context, $site ) );
264
265
		$siteManager = \Aimeos\MShop::create( $context, 'locale/site');
266
		$context->config()->apply( $siteManager->find( $site )->getConfig() );
0 ignored issues
show
The method find() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Order\Manag...rvice\Transaction\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Service\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Cms\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Address\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Product\Attribute\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Coupon\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Service\Attribute\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Cms\Manager\Lists\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Basket\Iface or Aimeos\MShop\Order\Manager\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

266
		$context->config()->apply( $siteManager->/** @scrutinizer ignore-call */ find( $site )->getConfig() );
Loading history...
267
268
        	$paths = $aimeos->getTemplatePaths( 'admin/jqadm/templates', $context->locale()->getSiteItem()->getTheme() );
269
		$view = app( 'aimeos.view' )->create( $context, $paths, $lang );
270
271
		$view->aimeosType = 'Laravel';
272
		$view->aimeosVersion = app( 'aimeos' )->getVersion();
273
		$view->aimeosExtensions = implode( ',', $aimeos->getExtensions() );
274
275
		$context->setView( $view );
276
277
		return \Aimeos\Admin\JQAdm::create( $context, $aimeos, $resource );
278
	}
279
280
281
	/**
282
	 * Returns the generated HTML code
283
	 *
284
	 * @param string $content Content from admin client
285
	 * @return \Illuminate\Contracts\View\View View for rendering the output
286
	 */
287
	protected function getHtml( string $content )
288
	{
289
		$site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) );
0 ignored issues
show
'shop.mshop.locale.site' of type string is incompatible with the type array expected by parameter $options of config(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

289
		$site = Route::input( 'site', Request::get( 'site', config( /** @scrutinizer ignore-type */ 'shop.mshop.locale.site', 'default' ) ) );
Loading history...
The call to config() has too many arguments starting with 'default'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

289
		$site = Route::input( 'site', Request::get( 'site', /** @scrutinizer ignore-call */ config( 'shop.mshop.locale.site', 'default' ) ) );

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. Please note the @ignore annotation hint above.

Loading history...
290
		$lang = Request::get( 'locale', config( 'app.locale', 'en' ) );
291
292
		return View::make( 'shop::jqadm.index', [
293
			'content' => $content,
294
			'site' => $site,
295
			'locale' => $lang,
296
			'localeDir' => in_array( $lang, ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur'] ) ? 'rtl' : 'ltr',
297
			'theme' => ( $_COOKIE['aimeos_backend_theme'] ?? '' ) == 'dark' ? 'dark' : 'light'
298
		] );
299
	}
300
}
301