Completed
Push — develop ( d04237...676fe2 )
by Jens
20:02
created

setPaymentId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Message;
7
8
use Commercetools\Core\Model\Common\DateTimeDecorator;
9
use Commercetools\Core\Model\Common\Reference;
10
use Commercetools\Core\Model\Payment\Transaction;
11
use DateTime;
12
13
/**
14
 * @package Commercetools\Core\Model\Message
15
 * @link https://dev.commercetools.com/http-api-projects-messages.html#paymentstatusinterfacecodeset-message
16
 * @method string getId()
17
 * @method PaymentStatusInterfaceCodeSetMessage setId(string $id = null)
18
 * @method int getVersion()
19
 * @method PaymentStatusInterfaceCodeSetMessage setVersion(int $version = null)
20
 * @method DateTimeDecorator getCreatedAt()
21
 * @method PaymentStatusInterfaceCodeSetMessage setCreatedAt(DateTime $createdAt = null)
22
 * @method DateTimeDecorator getLastModifiedAt()
23
 * @method PaymentStatusInterfaceCodeSetMessage setLastModifiedAt(DateTime $lastModifiedAt = null)
24
 * @method int getSequenceNumber()
25
 * @method PaymentStatusInterfaceCodeSetMessage setSequenceNumber(int $sequenceNumber = null)
26
 * @method Reference getResource()
27
 * @method PaymentStatusInterfaceCodeSetMessage setResource(Reference $resource = null)
28
 * @method int getResourceVersion()
29
 * @method PaymentStatusInterfaceCodeSetMessage setResourceVersion(int $resourceVersion = null)
30
 * @method string getType()
31
 * @method PaymentStatusInterfaceCodeSetMessage setType(string $type = null)
32
 * @method string getInterfaceCode()
33
 * @method PaymentStatusInterfaceCodeSetMessage setInterfaceCode(string $interfaceCode = null)
34
 */
35
class PaymentStatusInterfaceCodeSetMessage extends Message
36
{
37
    const MESSAGE_TYPE = 'PaymentStatusInterfaceCodeSet';
38
39
    public function fieldDefinitions()
40
    {
41
        $definitions = parent::fieldDefinitions();
42
        $definitions['paymentId'] = [static::TYPE => 'string'];
43
        $definitions['interfaceCode'] = [static::TYPE => 'string'];
44
45
        return $definitions;
46
    }
47
48
    /**
49
     * @deprecated
50
     * @return string
51
     */
52
    public function getPaymentId()
53
    {
54
        return parent::getPaymentId();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Commercetools\Core\Model\Message\Message as the method getPaymentId() does only exist in the following sub-classes of Commercetools\Core\Model\Message\Message: Commercetools\Core\Model...InterfaceCodeSetMessage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
55
    }
56
57
    /**
58
     * @deprecated
59
     * @param string $paymentId
60
     * @return static
61
     */
62
    public function setPaymentId($paymentId = null)
63
    {
64
        return parent::setPaymentId($paymentId);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Commercetools\Core\Model\Message\Message as the method setPaymentId() does only exist in the following sub-classes of Commercetools\Core\Model\Message\Message: Commercetools\Core\Model...InterfaceCodeSetMessage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
65
    }
66
}
67