Passed
Push — master ( 1ef39a...062823 )
by Aimeos
04:05
created

AdminController::indexAction()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 21
rs 9.5222
cc 5
nc 3
nop 1
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2014-2016
6
 * @package laravel
7
 * @subpackage Controller
8
 */
9
10
11
namespace Aimeos\Shop\Controller;
12
13
use Illuminate\Routing\Controller;
14
use Illuminate\Support\Facades\Auth;
15
use Illuminate\Support\Facades\Request;
16
use Illuminate\Support\Facades\Route;
17
use Illuminate\Support\Facades\View;
18
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
19
20
21
/**
22
 * Controller providing the ExtJS administration interface
23
 *
24
 * @package laravel
25
 * @subpackage Controller
26
 */
27
class AdminController extends Controller
28
{
29
	use AuthorizesRequests;
30
31
32
	/**
33
	 * Returns the initial HTML view for the admin interface.
34
	 *
35
	 * @param \Illuminate\Http\Request $request Laravel request object
36
	 * @return \Illuminate\Contracts\View\View View for rendering the output
37
	 */
38
	public function indexAction( \Illuminate\Http\Request $request )
39
	{
40
		if( Auth::check() === false
41
			|| $request->user()->can( 'admin', [AdminController::class, ['admin', 'editor']] ) === false
42
		) {
43
			return redirect()->guest( route( 'login', app()->getLocale() ) );
0 ignored issues
show
introduced by
The method getLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

43
			return redirect()->guest( route( 'login', app()->/** @scrutinizer ignore-call */ getLocale() ) );
Loading history...
44
		}
45
46
		$context = app( 'aimeos.context' )->get( false );
47
		$siteManager = \Aimeos\MShop::create( $context, 'locale/site' );
48
		$siteId = current( array_reverse( explode( '.', trim( $request->user()->siteid, '.' ) ) ) );
49
		$siteCode = ( $siteId ? $siteManager->get( $siteId )->getCode() : config( 'shop.mshop.locale.site', 'default' ) );
0 ignored issues
show
Bug introduced by
'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

49
		$siteCode = ( $siteId ? $siteManager->get( $siteId )->getCode() : config( /** @scrutinizer ignore-type */ 'shop.mshop.locale.site', 'default' ) );
Loading history...
Unused Code introduced by
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

49
		$siteCode = ( $siteId ? $siteManager->get( $siteId )->getCode() : /** @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...
50
		$locale = $request->user()->langid ?: config( 'app.locale', 'en' );
51
52
		$param = array(
53
			'resource' => 'dashboard',
54
			'site' => Route::input( 'site', Request::get( 'site', $siteCode ) ),
55
			'locale' => Route::input( 'locale', Request::get( 'locale', $locale ) )
56
		);
57
58
		return redirect()->route( 'aimeos_shop_jqadm_search', $param );
59
	}
60
}
61