Passed
Push — master ( 8bcf0d...10ee87 )
by Aimeos
06:29
created

Free   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 60
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkConfigBE() 0 6 1
A getConfigBE() 0 3 1
A isAvailable() 0 9 3
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020
6
 * @package MShop
7
 * @subpackage Service
8
 */
9
10
11
namespace Aimeos\MShop\Service\Provider\Decorator;
12
13
14
/**
15
 * Checks if basket total value is 0.00 and enables/disables option
16
 *
17
 * @package MShop
18
 * @subpackage Service
19
 */
20
class Free
21
	extends \Aimeos\MShop\Service\Provider\Decorator\Base
22
	implements \Aimeos\MShop\Service\Provider\Decorator\Iface
23
{
24
	private $beConfig = [
25
		'free.show' => [
26
			'code' => 'free.show',
27
			'internalcode' => 'free.show',
28
			'label' => 'Enable or disable option if basket total is 0.00',
29
			'type' => 'boolean',
30
			'internaltype' => 'boolean',
31
			'default' => '',
32
			'required' => true,
33
		],
34
	];
35
36
37
	/**
38
	 * Checks the backend configuration attributes for validity.
39
	 *
40
	 * @param array $attributes Attributes added by the shop owner in the administraton interface
41
	 * @return array An array with the attribute keys as key and an error message as values for all attributes that are
42
	 * 	known by the provider but aren't valid
43
	 */
44
	public function checkConfigBE( array $attributes ) : array
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
45
	{
46
		$error = $this->getProvider()->checkConfigBE( $attributes );
47
		$error += $this->checkConfig( $this->beConfig, $attributes );
48
49
		return $error;
50
	}
51
52
53
	/**
54
	 * Returns the configuration attribute definitions of the provider to generate a list of available fields and
55
	 * rules for the value of each field in the administration interface.
56
	 *
57
	 * @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface
58
	 */
59
	public function getConfigBE() : array
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
60
	{
61
		return array_merge( $this->getProvider()->getConfigBE(), $this->getConfigItems( $this->beConfig ) );
62
	}
63
64
65
	/**
66
	 * Checks if the service provider should be available.
67
	 *
68
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
69
	 * @return bool True if payment provider can be used, false if not
70
	 */
71
	public function isAvailable( \Aimeos\MShop\Order\Item\Base\Iface $basket ) : bool
72
	{
73
		$value = $basket->getPrice()->getValue();
74
75
		if( $value === '0.00' && (bool) $this->getConfigValue( 'free.show' ) === false ) {
76
			return false;
77
		}
78
79
		return $this->getProvider()->isAvailable( $basket );
80
	}
81
}
82