Completed
Push — master ( 31dc8b...77b29b )
by Aimeos
02:53
created

Base::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Order\Decorator;
12
13
14
/**
15
 * Base for order frontend controller decorators
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
abstract class Base extends \Aimeos\Controller\Frontend\Common\Decorator\Base
21
{
22
	/**
23
	 * Creates a new order from the given basket.
24
	 *
25
	 * Saves the given basket to the storage including the addresses, coupons,
26
	 * products, services, etc. and creates/stores a new order item for that
27
	 * order.
28
	 *
29
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object to be stored
30
	 * @return \Aimeos\MShop\Order\Item\Iface Order item that belongs to the stored basket
31
	 */
32
	public function store( \Aimeos\MShop\Order\Item\Base\Iface $basket )
33
	{
34
		$this->getController()->store( $basket );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method store() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Order\Standard.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
35
	}
36
37
38
	/**
39
	 * Blocks the resources listed in the order.
40
	 *
41
	 * Every order contains resources like products or redeemed coupon codes
42
	 * that must be blocked so they can't be used by another customer in a
43
	 * later order. This method reduces the the stock level of products, the
44
	 * counts of coupon codes and others.
45
	 *
46
	 * It's save to call this method multiple times for one order. In this case,
47
	 * the actions will be executed only once. All subsequent calls will do
48
	 * nothing as long as the resources haven't been unblocked in the meantime.
49
	 *
50
	 * You can also block and unblock resources several times. Please keep in
51
	 * mind that unblocked resources may be reused by other orders in the
52
	 * meantime. This can lead to an oversell of products!
53
	 *
54
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
55
	 * @return void
56
	 */
57
	public function block( \Aimeos\MShop\Order\Item\Iface $orderItem )
58
	{
59
		$this->getController()->block( $orderItem );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method block() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Order\Standard.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
60
	}
61
62
63
	/**
64
	 * Frees the resources listed in the order.
65
	 *
66
	 * If customers created orders but didn't pay for them, the blocked resources
67
	 * like products and redeemed coupon codes must be unblocked so they can be
68
	 * ordered again or used by other customers. This method increased the stock
69
	 * level of products, the counts of coupon codes and others.
70
	 *
71
	 * It's save to call this method multiple times for one order. In this case,
72
	 * the actions will be executed only once. All subsequent calls will do
73
	 * nothing as long as the resources haven't been blocked in the meantime.
74
	 *
75
	 * You can also unblock and block resources several times. Please keep in
76
	 * mind that unblocked resources may be reused by other orders in the
77
	 * meantime. This can lead to an oversell of products!
78
	 *
79
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
80
	 * @return void
81
	 */
82
	public function unblock( \Aimeos\MShop\Order\Item\Iface $orderItem )
83
	{
84
		$this->getController()->unblock( $orderItem );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method unblock() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Order\Standard.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
85
	}
86
87
88
	/**
89
	 * Blocks or frees the resources listed in the order if necessary.
90
	 *
91
	 * After payment status updates, the resources like products or coupon
92
	 * codes listed in the order must be blocked or unblocked. This method
93
	 * cares about executing the appropriate action depending on the payment
94
	 * status.
95
	 *
96
	 * It's save to call this method multiple times for one order. In this case,
97
	 * the actions will be executed only once. All subsequent calls will do
98
	 * nothing as long as the payment status hasn't changed in the meantime.
99
	 *
100
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
101
	 * @return void
102
	 */
103
	public function update( \Aimeos\MShop\Order\Item\Iface $orderItem )
104
	{
105
		$this->getController()->update( $orderItem );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method update() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Order\Standard.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
106
	}
107
}
108