Locale::getBackend()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
use Illuminate\Support\Facades\Request;
14
use Illuminate\Support\Facades\Route;
15
16
17
/**
18
 * Service providing the context objects
19
 *
20
 * @package laravel
21
 * @subpackage Base
22
 */
23
class Locale
24
{
25
	/**
26
	 * @var \Illuminate\Contracts\Config\Repository
27
	 */
28
	private $config;
29
30
	/**
31
	 * @var \Aimeos\MShop\Locale\Item\Iface
32
	 */
33
	private $locale;
34
35
36
	/**
37
	 * Initializes the object
38
	 *
39
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
40
	 */
41
	public function __construct( \Illuminate\Contracts\Config\Repository $config )
42
	{
43
		$this->config = $config;
44
	}
45
46
47
	/**
48
	 * Returns the locale item for the current request
49
	 *
50
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
51
	 * @return \Aimeos\MShop\Locale\Item\Iface Locale item object
52
	 */
53
	public function get( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Locale\Item\Iface
54
	{
55
		if( $this->locale === null )
56
		{
57
			$site = Request::input( 'site', config( 'shop.mshop.locale.site', 'default' ) );
0 ignored issues
show
Unused Code introduced by Andreas
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

57
			$site = Request::input( '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...
Bug introduced by Andreas
'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

57
			$site = Request::input( 'site', config( /** @scrutinizer ignore-type */ 'shop.mshop.locale.site', 'default' ) );
Loading history...
58
			$lang = Request::input( 'locale', app()->getLocale() );
0 ignored issues
show
introduced by Andreas
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

58
			$lang = Request::input( 'locale', app()->/** @scrutinizer ignore-call */ getLocale() );
Loading history...
59
			$currency = Request::input( 'currency', '' );
60
61
			if( Route::current() )
62
			{
63
				$site = Request::route( 'site', $site );
0 ignored issues
show
Bug introduced by Andreas
It seems like $site can also be of type array; however, parameter $default of Illuminate\Support\Facades\Request::route() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

63
				$site = Request::route( 'site', /** @scrutinizer ignore-type */ $site );
Loading history...
64
				$lang = Request::route( 'locale', $lang );
65
				$currency = Request::route( 'currency', $currency );
66
			}
67
68
			$localeManager = \Aimeos\MShop::create( $context, 'locale' );
69
			$disableSites = $this->config->get( 'shop.disableSites', true );
70
71
			$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites );
0 ignored issues
show
Bug introduced by Andreas
The method bootstrap() 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\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\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\Coupon\Manager\Code\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Price\Manager\Property\Type\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\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\Order\Manag...Product\Attribute\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\Attribute\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MShop\Common\Manager\Type\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Customer\Manager\Group\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\Media\Manager\Property\Type\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\Service\Manager\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\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\Index\Manager\Iface or Aimeos\MShop\Index\Manager\Attribute\Iface or Aimeos\MShop\Index\Manager\Text\Iface or Aimeos\MShop\Index\Manager\Supplier\Iface or Aimeos\MShop\Index\Manager\Catalog\Iface or Aimeos\MShop\Index\Manager\Price\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

71
			/** @scrutinizer ignore-call */ 
72
   $this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites );
Loading history...
72
		}
73
74
		return $this->locale;
75
	}
76
77
78
	/**
79
	 * Returns the locale item for the current request
80
	 *
81
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
82
	 * @param string $site Unique site code
83
	 * @return \Aimeos\MShop\Locale\Item\Iface Locale item object
84
	 */
85
	public function getBackend( \Aimeos\MShop\Context\Item\Iface $context, string $site ) : \Aimeos\MShop\Locale\Item\Iface
86
	{
87
		$localeManager = \Aimeos\MShop::create( $context, 'locale' );
88
89
		try {
90
			$localeItem = $localeManager->bootstrap( $site, '', '', false, null, true );
91
		} catch( \Aimeos\MShop\Exception $e ) {
92
			$localeItem = $localeManager->create();
93
		}
94
95
		return $localeItem->setCurrencyId( null )->setLanguageId( null );
96
	}
97
}
98