CompanyDetailsTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 29.4%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 70
ccs 5
cts 17
cp 0.294
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
getParameter() 0 1 ?
setParameter() 0 1 ?
A getCompanyDetails() 0 4 1
A setCompanyDetails() 0 4 1
A appendCompanyDetails() 0 7 2
A appendCompanyDetailsAdditional() 0 8 1
1
<?php
2
3
namespace Omnipay\BillPay\Message\RequestData;
4
5
use Omnipay\BillPay\Company;
6
use Omnipay\BillPay\Message\AuthorizeRequest;
7
use Omnipay\Common\Exception\InvalidRequestException;
8
use Omnipay\Common\Message\AbstractRequest;
9
use SimpleXMLElement;
10
11
/**
12
 * Class CompanyDetailsTrait.
13
 */
14
trait CompanyDetailsTrait
15
{
16 11
    public function getCompanyDetails()
17
    {
18 11
        return $this->getParameter('companyDetails');
19
    }
20
21
    /**
22
     * Sets the company detail information.
23
     *
24
     * @param Company $company
25
     *
26
     * @return AuthorizeRequest
27
     */
28
    public function setCompanyDetails($company)
29
    {
30
        return $this->setParameter('companyDetails', $company);
31
    }
32
33
    /**
34
     * @param SimpleXMLElement $data
35
     *
36
     * @throws InvalidRequestException
37
     */
38 11
    protected function appendCompanyDetails(SimpleXMLElement $data)
39
    {
40 11
        if ($this->getCompanyDetails()) {
41
            $data->addChild('company_details');
42
            $this->appendCompanyDetailsAdditional($data, $this->getCompanyDetails());
43
        }
44 11
    }
45
46
    /**
47
     * Get a single parameter.
48
     *
49
     * @param string $key The parameter key
50
     *
51
     * @return mixed
52
     *
53
     * @codeCoverageIgnore
54
     */
55
    abstract protected function getParameter($key);
56
57
    /**
58
     * Set a single parameter.
59
     *
60
     * @param string $key   The parameter key
61
     * @param mixed  $value The value to set
62
     *
63
     * @return AbstractRequest Provides a fluent interface
64
     *
65
     * @codeCoverageIgnore
66
     */
67
    abstract protected function setParameter($key, $value);
68
69
    /**
70
     * Fills additional data.
71
     *
72
     * @param SimpleXMLElement $data
73
     * @param Company         $company
74
     */
75
    private function appendCompanyDetailsAdditional(SimpleXMLElement $data, Company $company)
76
    {
77
        $data->company_details[0]['name'] = $company->getName();
78
        $data->company_details[0]['legalForm'] = $company->getLegalForm();
79
        $data->company_details[0]['registerNumber'] = $company->getRegisterNumber();
80
        $data->company_details[0]['holderName'] = $company->getHolderName();
81
        $data->company_details[0]['taxNumber'] = $company->getTaxNumber();
82
    }
83
}
84