Passed
Pull Request — developer (#17179)
by Mariusz
29:27 queued 10:21
created

BankAccount::convertCurrency()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 15
rs 9.9332
c 1
b 0
f 0
cc 4
nc 4
nop 3
1
<?php
2
3
/**
4
 * Comarch bank account synchronization map file.
5
 *
6
 * The file is part of the paid functionality. Using the file is allowed only after purchasing a subscription.
7
 * File modification allowed only with the consent of the system producer.
8
 *
9
 * @package Integration
10
 *
11
 * @copyright YetiForce S.A.
12
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
13
 * @author    Mariusz Krzaczkowski <[email protected]>
14
 */
15
16
namespace App\Integrations\Comarch\Xl\Maps;
17
18
/**
19
 * Comarch bank account synchronization map class.
20
 */
21
class BankAccount extends \App\Integrations\Comarch\Map
22
{
23
	/** {@inheritdoc} */
24
	protected $moduleName = 'BankAccounts';
25
	/** {@inheritdoc} */
26
	protected $fieldMap = [
27
		'name' => 'rkB_Id',
28
		'bank_name' => 'bnk_Nazwa',
29
		'account_number' => 'rkB_NrRachunku',
30
		'currency_id' => ['name' => 'rkB_Waluta', 'fn' => 'convertCurrency'],
31
	];
32
	/** {@inheritdoc} */
33
	protected $defaultDataYf = [
34
		'fieldMap' => [
35
			'bankaccount_status' => 'PLL_ACTIVE'
36
		]
37
	];
38
39
	/** {@inheritdoc} */
40
	protected function convertCurrency($value, array $field, bool $fromApi)
41
	{
42
		if ($fromApi) {
43
			if ($value) {
44
				$currency = \App\Fields\Currency::getIdByCode($value);
45
				if (empty($currency)) {
46
					$currency = \App\Fields\Currency::addCurrency($value);
47
				}
48
			} else {
49
				$currency = \App\Fields\Currency::getDefault()['id'];
50
			}
51
		} else {
52
			$currency = \App\Fields\Currency::getById($value)['currency_code'];
53
		}
54
		return $currency;
55
	}
56
}
57