Completed
Push — 2016.10 ( 83b84d...c5e9d5 )
by Aimeos
09:36
created

T3Salutation::translate()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 8.8571
cc 5
eloc 11
nc 5
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2014
7
 * @package MShop
8
 * @subpackage Common
9
 */
10
11
12
namespace Aimeos\MW\Criteria\Plugin;
13
14
15
/**
16
 * Criteria plugin for TYPO3 salutation/gender.
17
 *
18
 * @package MW
19
 * @subpackage Common
20
 */
21
class T3Salutation implements \Aimeos\MW\Criteria\Plugin\Iface
22
{
23
	/**
24
	 * Translates the MShop value into its TYPO3 equivalent.
25
	 *
26
	 * @param string $value Address constant from \Aimeos\MShop\Common\Item\Address\Base
27
	 * @return integer TYPO3 gender value or 99 if nothing matches
28
	 */
29
	public function translate( $value )
30
	{
31
		switch( $value )
32
		{
33
			case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR:
34
				return 0;
35
			case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MRS:
36
				return 1;
37
			case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MISS:
38
				return 2;
39
			case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY:
40
				return 10;
41
		}
42
43
		return 99;
44
	}
45
46
47
	/**
48
	 * Reverses the translation from the TYPO3 value to the MShop constant.
49
	 *
50
	 * @param string $value TYPO3 value or empty if not set
51
	 * @return string Address constant from \Aimeos\MShop\Common\Item\Address\Base
52
	 */
53
	public function reverse( $value )
54
	{
55
		switch( $value )
56
		{
57
			case 0:
58
				return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR;
59
			case 1:
60
				return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MRS;
61
			case 2:
62
				return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MISS;
63
			case 10:
64
				return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY;
65
		}
66
67
		return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_UNKNOWN;
68
	}
69
}
70