GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

OrderCreditIssued   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 106
Duplicated Lines 9.43 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
c 4
b 0
f 0
lcom 2
cbo 8
dl 10
loc 106
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventType() 0 4 1
A getSchemaFile() 0 4 1
A getXmlNamespace() 0 4 1
A getRootNodeName() 0 4 1
B __construct() 0 44 1
A getRootAttributes() 10 10 1
A serializeContents() 0 6 1
A serializeOrderSummary() 0 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
namespace eBayEnterprise\RetailOrderManagement\Payload\OrderEvents;
17
18
use eBayEnterprise\RetailOrderManagement\Payload\IPayload;
19
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap;
20
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator;
21
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator;
22
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory;
23
use eBayEnterprise\RetailOrderManagement\Payload\Payment\TAmount;
24
use eBayEnterprise\RetailOrderManagement\Payload\TTopLevelPayload;
25
use Psr\Log\LoggerInterface;
26
use Psr\Log\NullLogger;
27
28
class OrderCreditIssued implements IOrderCreditIssued
29
{
30
    use TTopLevelPayload, TOrderEvent, TCurrency, TLoyaltyProgramCustomer, TOrderItemContainer, TReturnSummary, TAmount;
31
32
    /**
33
     * @param IValidatorIterator
34
     * @param ISchemaValidator
35
     * @param IPayloadMap
36
     * @param LoggerInterface
37
     * @param IPayload
38
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
39
     */
40
    public function __construct(
41
        IValidatorIterator $validators,
42
        ISchemaValidator $schemaValidator,
43
        IPayloadMap $payloadMap,
44
        LoggerInterface $logger,
45
        IPayload $parentPayload = null
46
    ) {
47
        $this->logger = $logger;
0 ignored issues
show
Documentation Bug introduced by
It seems like $logger of type object<Psr\Log\LoggerInterface> is incompatible with the declared type object<eBayEnterprise\Re...ayload\LoggerInterface> of property $logger.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
        $this->validators = $validators;
49
        $this->schemaValidator = $schemaValidator;
50
        $this->payloadMap = $payloadMap;
51
        $this->parentPayload = $parentPayload;
52
        $this->payloadFactory = new PayloadFactory();
53
54
        $this->loyaltyPrograms =
55
            $this->buildPayloadForInterface(static::LOYALTY_PROGRAM_ITERABLE_INTERFACE);
56
        $this->orderItems =
57
            $this->buildPayloadForInterface(static::ORDER_ITEM_ITERABLE_INTERFACE);
58
59
        $this->extractionPaths = [
60
            'storeId' => 'string(@storeId)',
61
            'currencyCode' => 'string(@currency)',
62
            'currencySymbol' => 'string(@currencySymbol)',
63
            'customerFirstName' => 'string(x:Customer/x:Name/x:FirstName)',
64
            'customerLastName' => 'string(x:Customer/x:Name/x:LastName)',
65
            'customerEmailAddress' => 'string(x:Customer/x:Name/x:EmailAddress)',
66
            'orderId' => 'string(@customerOrderId)',
67
            'returnOrCredit' => 'string(x:CreditIssuedSummary/@returnOrCreditIssued)',
68
            'referenceNumber' => 'string(x:CreditIssuedSummary/@creditRefNumber)',
69
            'totalCredit' => 'string(x:CreditIssuedSummary/@totalCredit)'
70
        ];
71
72
        $this->optionalExtractionPaths = [
73
            'customerId' => 'x:Customer/@customerId',
74
            'customerMiddleName' => 'x:Customer/x:Name/x:MiddleName',
75
            'customerHonorificName' => 'x:Customer/x:Name/x:Honorific',
76
            'customerEmailAddress' => 'x:Customer/x:EmailAddress'
77
        ];
78
79
        $this->subpayloadExtractionPaths = [
80
            'loyaltyPrograms' => 'x:Customer/x:LoyaltyPrograms',
81
            'orderItems' => 'x:AdjustedOrderItems'
82
        ];
83
    }
84
85 View Code Duplication
    protected function getRootAttributes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        return [
88
            'xmlns' => $this->getXmlNamespace(),
89
            'customerOrderId' => $this->getCustomerOrderId(),
90
            'storeId' => $this->getStoreId(),
91
            'currency' => $this->getCurrencyCode(),
92
            'currencySymbol' => $this->getCurrencySymbol()
93
        ];
94
    }
95
96
    public function getEventType()
97
    {
98
        return static::ROOT_NODE;
99
    }
100
101
    protected function getSchemaFile()
102
    {
103
        return $this->getSchemaDir() . self::XSD;
104
    }
105
106
    protected function getXmlNamespace()
107
    {
108
        return self::XML_NS;
109
    }
110
111
    protected function getRootNodeName()
112
    {
113
        return self::ROOT_NODE;
114
    }
115
116
    protected function serializeContents()
117
    {
118
        return $this->serializeCustomer()
119
            . $this->getOrderItems()->serialize()
120
            . $this->serializeOrderSummary();
121
    }
122
123
    protected function serializeOrderSummary()
124
    {
125
        $format = '<CreditIssuedSummary returnOrCreditIssued="%s" creditRefNumber="%s" totalCredit="%s"></CreditIssuedSummary>';
126
        return sprintf(
127
            $format,
128
            $this->getReturnOrCredit(),
129
            $this->getReferenceNumber(),
130
            $this->formatAmount($this->getTotalCredit())
131
        );
132
    }
133
}
134