OrderRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B findOrders() 0 34 6
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