Passed
Push — master ( 99faad...fa79ba )
by Aimeos
13:30 queued 10:33
created

T3Salutation::translate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
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-2022
7
 * @package MShop
8
 * @subpackage Common
9
 */
10
11
12
namespace Aimeos\Base\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\Base\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_MS:
36
				return 1;
37
			case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY:
38
				return 10;
39
		}
40
41
		return 99;
42
	}
43
44
45
	/**
46
	 * Reverses the translation from the TYPO3 value to the MShop constant.
47
	 *
48
	 * @param string $value TYPO3 value or empty if not set
49
	 * @return string Address constant from \Aimeos\MShop\Common\Item\Address\Base
50
	 */
51
	public function reverse( $value )
52
	{
53
		switch( $value )
54
		{
55
			case 0:
56
				return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR;
57
			case 1:
58
				return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MS;
59
			case 10:
60
				return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY;
61
		}
62
63
		return \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_UNKNOWN;
64
	}
65
}
66