Completed
Pull Request — master (#2)
by
unknown
03:39
created

Venture::updatePriceOnPartner()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4286
cc 2
eloc 12
nc 1
nop 5
crap 2
1
<?php
2
3
namespace Iris\SaleWrapper;
4
5
use Iris\Exceptions\InvalidTransfer;
6
7
class Venture extends Base implements VentureInterface
8
{
9
    /**
10
     * @return \Iris\Interfaces\IrisPartner
11
     */
12 7
    public function getPartnerService()
13
    {
14 7
        return $this->getManager()->getService(\Iris\Factory::PARTNER);
15
    }
16
17
    /**
18
     * @return \Iris\Interfaces\IrisVenture
19
     */
20 2
    public function getVentureService()
21
    {
22 2
        return $this->getManager()->getService(\Iris\Factory::VENTURE);
23
    }
24
25
    /**
26
     * @return \Iris\Interfaces\Customer
27
     */
28 2
    public function getCustomerService()
29
    {
30 2
        return $this->getManager()->getService(\Iris\Factory::CUSTOMER);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function createOrder(array $orderData, $originCode)
37
    {
38 2
        $partner = $this->getPartnerService()->findByCode($originCode);
39
40 2
        $salesOrder = $this->getOrderMapping()->assign($orderData);
41
42 2
        $customer = $this->getCustomerService()->createByExternalData($salesOrder->getCustomer());
43
44 2
        $idIrisCustomer = $customer->getIdIrisCustomer();
45
46
        try {
47 2
            $irisOrder = $this->getOrderService()->getOrderNrByExternalshopNumberAndPartner(
48 2
                $orderData['order_number'],
49 2
                $partner->getPartnerCode()
50 2
            );
51 1
            $result = array('order_number' => $irisOrder);
52
53 2
        } catch (\Iris\Exceptions\OrderNotFound $exception) {
54 1
            $salesOrder = $this->getOrderService()->save($salesOrder);
55 1
            $orderData['id_iris_customer'] = $idIrisCustomer;
56 1
            $this->getVentureService()->saveExternalData($orderData, $salesOrder);
57 1
            $result = array('order_number' => $salesOrder->getOrderNr());
58
        }
59
60 2
        return $result;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 2
    public function confirmPaymentOrder($orderNumber, $originCode)
67
    {
68 2
        $partner = $this->getPartnerService()->findByCode($originCode);
69 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
70 2
            $orderNumber,
71 2
            $partner->getPartnerCode()
72 2
        );
73 2
        if (!$this->getOrderService()->confirmPayment($order)) {
74 1
            throw new \RuntimeException(sprintf('Order number %s can\'t be confirmed', $orderNumber));
75
        }
76 1
        return array('order_number' => $order->getOrderNr());
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 1
    public function findOrderByOrderNumber($orderNumber, $originCode)
83
    {
84 1
        return $this->getOrderService()->getOrderByOrderNumberAndPartnerCode($orderNumber, $originCode);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getOrderSe...erNumber, $originCode); (Iris\Transfer\Sales\Order) is incompatible with the return type declared by the interface Iris\SaleWrapper\BaseInt...:findOrderByOrderNumber of type Iris\SaleWrapper\Iris\Transfer\Sales\Order.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 2
    public function cancelOrder($orderNumber, $originCode)
91
    {
92 2
        $partner = $this->getPartnerService()->findByCode($originCode);
93 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
94 2
            $orderNumber,
95 2
            $partner->getPartnerCode()
96 2
        );
97 2
        if (!$this->getOrderService()->cancel($order)) {
98 1
            throw new \RuntimeException(sprintf('Order number %s can\'t be canceled', $orderNumber));
99
        }
100 1
        return array('order_number' => $order->getOrderNr());
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 1
    public function createProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products, $partnerCode)
107
    {
108 1
        $this->getVentureApiClient()->createProducts($products, $partnerCode);
109 1
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114 1
    public function updateProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products)
115
    {
116 1
        $this->getVentureApiClient()->updateProducts($products);
117 1
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122 1
    public function updateStockOnPartner($skuSimple, $stock)
123
    {
124 1
        $this->getVentureApiClient()->updateStock($skuSimple, $stock);
125 1
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130 1
    public function updatePriceOnPartner(
131
        $skuSimple,
132
        $price,
133
        $specialPrice = null,
134
        $specialFromDate = null,
135
        $specialToDate = null
136
    ) {
137 1
        $this->getVentureApiClient()->updatePrice(
138 1
            $skuSimple,
139 1
            $price,
140 1
            $specialPrice ?: $price,
141 1
            $specialFromDate,
142
            $specialToDate
143 1
        );
144 1
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function isPartnerItem(\Iris\Transfer\Sales\Order\Item $item)
150
    {
151
        $irisPartner = $this->getPartnerService()->findBySalesOrderId($item->getFkSalesOrder());
152
        return ($irisPartner instanceof \Iris\Transfer\Partner);
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158 1
    public function setStatusToShipped(\Iris\Transfer\Tracking\ShippedCollection $items)
159
    {
160 1
        return $this->getVentureApiClient()->setStatusToShipped($items);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getVenture...tatusToShipped($items); (GuzzleHttp\Message\Response) is incompatible with the return type declared by the interface Iris\SaleWrapper\Venture...ace::setStatusToShipped of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166 1
    public function setStatusToDelivered(\Iris\Transfer\Tracking\DeliveredCollection $items)
167
    {
168 1
        return $this->getVentureApiClient()->setStatusToDelivered($items);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getVenture...tusToDelivered($items); (GuzzleHttp\Message\Response) is incompatible with the return type declared by the interface Iris\SaleWrapper\Venture...e::setStatusToDelivered of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
169
    }
170
171
    /**
172
     * NOTE: Not implemented yet!
173
     *
174
     * {@inheritdoc}
175
     */
176 1
    public function setStatusToCanceled(\Iris\Transfer\Tracking\CanceledCollection $items)
177
    {
178 1
        return $this->getVentureApiClient()->setStatusToCanceled($items);
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184 1
    public function setStatusToFailedDelivery(\Iris\Transfer\Tracking\FailedDeliveryCollection $items)
185
    {
186 1
        return $this->getVentureApiClient()->setStatusToFailedDelivery($items);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getVenture...FailedDelivery($items); (GuzzleHttp\Message\Response) is incompatible with the return type declared by the interface Iris\SaleWrapper\Venture...tStatusToFailedDelivery of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192 1
    public function getName()
193
    {
194 1
        return 'venture';
195
    }
196
}
197