Passed
Push — master ( a6b03a...955296 )
by Aimeos
02:30
created

Base::translatePluginErrorCodes()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 * @package Client
7
 * @subpackage JsonApi
8
 */
9
10
11
namespace Aimeos\Client\JsonApi\Basket;
12
13
14
/**
15
 * Base class for JSON API basket clients
16
 *
17
 * @package Client
18
 * @subpackage JsonApi
19
 */
20
class Base extends \Aimeos\Client\JsonApi\Base
21
{
22
	/**
23
	 * Clears the basket cache shared between HTML and JSON clients
24
	 */
25
	protected function clearCache()
26
	{
27
		$session = $this->getContext()->getSession();
28
29
		foreach( $session->get( 'aimeos/basket/cache', [] ) as $key => $value ) {
30
			$session->set( $key, null );
31
		}
32
	}
33
34
35
	/**
36
	 * Translates the plugin error codes to human readable error strings.
37
	 *
38
	 * @param array $codes Associative list of scope and object as key and error code as value
39
	 * @return array List of translated error messages
40
	 */
41
	protected function translatePluginErrorCodes( array $codes )
42
	{
43
		$errors = [];
44
		$i18n = $this->getContext()->getI18n();
45
46
		foreach( $codes as $scope => $list )
47
		{
48
			foreach( $list as $object => $errcode )
49
			{
50
				$key = $scope . ( $scope !== 'product' ? '.' . $object : '' ) . '.' . $errcode;
51
				$errors[] = $i18n->dt( 'mshop/code', $key );
52
			}
53
		}
54
55
		return $errors;
56
	}
57
}
58