Completed
Pull Request — master (#2)
by
unknown
04:25
created

Venture::isPartnerItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Iris\SaleWrapper;
4
5
class Venture extends Base implements VentureInterface
6
{
7
    /**
8
     * @return \Iris\Interfaces\IrisPartner
9
     */
10 7
    public function getPartnerService()
11
    {
12 7
        return $this->getManager()->getService(\Iris\Factory::PARTNER);
13
    }
14
15
    /**
16
     * @return \Iris\Interfaces\IrisVenture
17
     */
18 2
    public function getVentureService()
19
    {
20 2
        return $this->getManager()->getService(\Iris\Factory::VENTURE);
21
    }
22
23
    /**
24
     * @return \Iris\Interfaces\Customer
25
     */
26 2
    public function getCustomerService()
27
    {
28 2
        return $this->getManager()->getService(\Iris\Factory::CUSTOMER);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function createOrder(array $orderData, $originCode)
35
    {
36 2
        $partner = $this->getPartnerService()->findByCode($originCode);
37
38 2
        $salesOrder = $this->getOrderMapping()->assign($orderData);
39
40 2
        $customer = $this->getCustomerService()->createByExternalData($salesOrder->getCustomer());
41
42 2
        $idIrisCustomer = $customer->getIdIrisCustomer();
43
44
        try {
45 2
            $irisOrder = $this->getOrderService()->getOrderNrByExternalshopNumberAndPartner(
46 2
                $orderData['order_number'],
47 2
                $partner->getPartnerCode()
48 2
            );
49 1
            $result = array('order_number' => $irisOrder);
50
51 2
        } catch (\Iris\Exceptions\OrderNotFound $exception) {
52 1
            $salesOrder = $this->getOrderService()->save($salesOrder);
53 1
            $orderData['id_iris_customer'] = $idIrisCustomer;
54 1
            $this->getVentureService()->saveExternalData($orderData, $salesOrder);
55 1
            $result = array('order_number' => $salesOrder->getOrderNr());
56
        }
57
58 2
        return $result;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 2
    public function confirmPaymentOrder($orderNumber, $originCode)
65
    {
66 2
        $partner = $this->getPartnerService()->findByCode($originCode);
67 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
68 2
            $orderNumber,
69 2
            $partner->getPartnerCode()
70 2
        );
71 2
        if (!$this->getOrderService()->confirmPayment($order)) {
72 1
            throw new \RuntimeException(sprintf('Order number %s can\'t be confirmed', $orderNumber));
73
        }
74 1
        return array('order_number' => $order->getOrderNr());
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 1
    public function findOrderByOrderNumber($orderNumber, $originCode)
81
    {
82 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...
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88 2
    public function cancelOrder($orderNumber, $originCode)
89
    {
90 2
        $partner = $this->getPartnerService()->findByCode($originCode);
91 2
        $order = $this->getOrderService()->getOrderByOrderNumberAndPartnerCode(
92 2
            $orderNumber,
93 2
            $partner->getPartnerCode()
94 2
        );
95 2
        if (!$this->getOrderService()->cancel($order)) {
96 1
            throw new \RuntimeException(sprintf('Order number %s can\'t be canceled', $orderNumber));
97
        }
98 1
        return array('order_number' => $order->getOrderNr());
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104 1
    public function createProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products, $partnerCode)
105
    {
106 1
        $this->getVentureApiClient()->createProducts($products, $partnerCode);
107 1
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112 1
    public function updateProductsOnPartner(\Iris\Transfer\Catalog\ConfigCollection $products)
113
    {
114 1
        $this->getVentureApiClient()->updateProducts($products);
115 1
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120 1
    public function updateStockOnPartner($skuSimple, $stock)
121
    {
122 1
        $this->getVentureApiClient()->updateStock($skuSimple, $stock);
123 1
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128 1
    public function updatePriceOnPartner(
129
        $skuSimple,
130
        $price,
131
        $specialPrice = null,
132
        $specialFromDate = null,
133
        $specialToDate = null
134
    ) {
135 1
        $this->getVentureApiClient()->updatePrice(
136 1
            $skuSimple,
137 1
            $price,
138 1
            $specialPrice ?: $price,
139 1
            $specialFromDate,
140
            $specialToDate
141 1
        );
142 1
    }
143
144
    /**
145
     * {@inheritdoc}
146
     */
147
    public function isPartnerItem(\Iris\Transfer\Sales\Order\Item $item)
148
    {
149
        $irisPartner = $this->getPartnerService()->findBySalesOrderId($item->getFkSalesOrder());
150
        return ($irisPartner instanceof \Iris\Transfer\Partner);
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156 1
    public function setStatusToShippedOnPartner(\Iris\Transfer\Tracking\ShippedCollection $items)
157
    {
158 1
        return $this->getVentureApiClient()->setStatusToShippedOnPartner($items);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getVenture...ippedOnPartner($items); (GuzzleHttp\Message\Response) is incompatible with the return type declared by the interface Iris\SaleWrapper\Venture...tatusToShippedOnPartner 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...
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164 1
    public function setStatusToDeliveredOnPartner(\Iris\Transfer\Tracking\DeliveredCollection $items)
165
    {
166 1
        return $this->getVentureApiClient()->setStatusToDeliveredOnPartner($items);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getVenture...veredOnPartner($items); (GuzzleHttp\Message\Response) is incompatible with the return type declared by the interface Iris\SaleWrapper\Venture...tusToDeliveredOnPartner 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...
167
    }
168
169
    /**
170
     * NOTE: Not implemented yet!
171
     *
172
     * {@inheritdoc}
173
     */
174 1
    public function setStatusToCanceledOnPartner(\Iris\Transfer\Tracking\CanceledCollection $items)
175
    {
176 1
        return $this->getVentureApiClient()->setStatusToCanceledOnPartner($items);
177
    }
178
179
    /**
180
     * {@inheritdoc}
181
     */
182 1
    public function setStatusToFailedDeliveryOnPartner(\Iris\Transfer\Tracking\FailedDeliveryCollection $items)
183
    {
184 1
        return $this->getVentureApiClient()->setStatusToFailedDeliveryOnPartner($items);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getVenture...iveryOnPartner($items); (GuzzleHttp\Message\Response) is incompatible with the return type declared by the interface Iris\SaleWrapper\Venture...FailedDeliveryOnPartner 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...
185
    }
186
187
    /**
188
     * {@inheritdoc}
189
     */
190 1
    public function getName()
191
    {
192 1
        return 'venture';
193
    }
194
}
195