Passed
Push — master ( 49c0d4...ffd40d )
by Aimeos
19:25 queued 16:39
created

Standard   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 17 3
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020-2022
6
 * @package MW
7
 * @subpackage View
8
 */
9
10
11
namespace Aimeos\Base\View\Helper\Attrname;
12
13
14
/**
15
 * View helper class for creating an HTML image tag
16
 *
17
 * @package MW
18
 * @subpackage View
19
 */
20
class Standard
21
	extends \Aimeos\Base\View\Helper\Base
22
	implements \Aimeos\Base\View\Helper\Attrname\Iface
23
{
24
	/**
25
	 * Returns the attribute name with price if available
26
	 *
27
	 * @param \Aimeos\MShop\Attribute\Item\Iface $item Attribute item
28
	 * @return string Attribute name with price (optional)
29
	 */
30
	public function transform( \Aimeos\MShop\Attribute\Item\Iface $item ) : string
31
	{
32
		if( $priceItem = $item->getRefItems( 'price', 'default', 'default' )->first() )
33
		{
34
			/// Configurable product attribute name (%1$s) with sign (%4$s, +/-), price value (%2$s) and currency (%3$s)
35
			$str = $this->translate( 'client', '%1$s (%4$s%2$s%3$s)' );
36
			$value = $priceItem->getValue() + $priceItem->getCosts();
37
			$view = $this->view();
38
39
			return sprintf( $str, $item->getName(),
40
				$view->number( abs( $value ), $priceItem->getPrecision() ),
41
				$view->translate( 'currency', $priceItem->getCurrencyId() ),
42
				( $value < 0 ? '−' : '+' )
43
			);
44
		}
45
46
		return $item->getName();
47
	}
48
}
49