OrderRepository::findOrders()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.439
c 0
b 0
f 0
cc 6
eloc 21
nc 8
nop 3
1
<?php
2
3
namespace ThreePlCentral\Order;
4
5
use DateTime;
6
use ThreePlCentral\ThreePlCentral;
7
use ThreePlCentral\RequestFactory;
8
9
class OrderRepository
10
{
11
    public static function findOrders(ThreePlCentral $threepl, DateTime $beginDate, DateTime $endDate)
12
    {
13
        $request = RequestFactory::create(
14
            $threepl,
15
            'POST',
16
            'http://www.JOI.com/schemas/ViaSub.WMS/FindOrders'
17
        );
18
19
        $request->setTemplate(__DIR__ . '/../Request/findOrders.xml');
20
21
        $response = $request->fetch([
22
            'BeginDate' => $beginDate->format('Y-m-d'),
23
            'EndDate' => $endDate->format('Y-m-d')
24
        ]);
25
26
        $result = $response->json();
27
        if (!is_array($result)) {
28
            $result = [$result];
29
        }
30
31
        $finalOrders = [];
32
        foreach ($result as $item) {
33
            $entity = new OrderEntity();
34
            foreach ($item as $key => $value) {
35
                $method = "set{$key}";
36
                if (is_string($value) && method_exists($entity, $method)) {
37
                    call_user_func([$entity, $method], $value);
38
                }
39
            }
40
            $finalOrders[] = $entity;
41
        }
42
43
        return $finalOrders;
44
    }
45
}
46