Skip to content

Commit 9d78ee9

Browse files
authored
Merge pull request #2 from lamoda/support_for_api_for_codes_orderting_added
Added support for OMS api for codes ordering
2 parents 31fd3dc + 89a40fa commit 9d78ee9

14 files changed

+452
-14
lines changed

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@ language: php
22

33
php:
44
- 7.2
5+
- 7.3
6+
- 7.4snapshot
57
- nightly
6-
8+
env:
9+
matrix:
10+
- DEPENDENCIES=high
11+
- DEPENDENCIES=low
12+
global:
13+
- DEFAULT_COMPOSER_FLAGS="--prefer-dist --no-interaction --no-ansi --no-progress --no-suggest"
714
sudo: false
815

916
matrix:
1017
fast_finish: true
1118
allow_failures:
1219
- php: nightly
20+
- php: 7.4snapshot
1321

1422
before_install:
1523
- travis_retry composer self-update
1624

1725
install:
18-
- composer --prefer-dist install
26+
- if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi
27+
- if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<directory>./tests/</directory>
3030
<directory>./src/V1/</directory>
3131
<directory>./src/V2/Dto</directory>
32+
<directory>./src/Exception</directory>
3233
</exclude>
3334
</whitelist>
3435
</filter>

src/Exception/OmsClientExceptionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
namespace Lamoda\OmsClient\Exception;
66

7-
interface OmsClientExceptionInterface
7+
interface OmsClientExceptionInterface extends \Throwable
88
{
99
}

src/Impl/Serializer/SymfonySerializerAdapter.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ public function __construct(SymfonySerializer $serializer)
2121

2222
public function deserialize(string $class, $data): object
2323
{
24-
return $this->serializer->deserialize($data, $class, 'json');
24+
$result = $this->serializer->deserialize($data, $class, 'json');
25+
assert(is_object($result));
26+
27+
return $result;
28+
}
29+
30+
public function serialize(object $data): string
31+
{
32+
$result = $this->serializer->serialize($data, 'json');
33+
assert(is_string($result));
34+
35+
return $result;
2536
}
2637
}

src/Impl/Serializer/SymfonySerializerAdapterFactory.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,45 @@
99
use Symfony\Component\Serializer\Encoder\JsonEncoder;
1010
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
1111
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
12+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
1213
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1314
use Symfony\Component\Serializer\Serializer;
1415

1516
final class SymfonySerializerAdapterFactory
1617
{
17-
public static function create(): SerializerInterface
18+
public const SYMFONY_VERSION_LESS_THAN_42 = 'symfony_version_less_42';
19+
public const SYMFONY_VERSION_GREATER_OR_EQUAL_42 = 'symfony_version_greater_or_equal_42';
20+
21+
public static function create(string $symfonyVersion = self::SYMFONY_VERSION_LESS_THAN_42): SerializerInterface
1822
{
1923
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
20-
$normalizer = new ObjectNormalizer($classMetadataFactory);
21-
$encoder = new JsonEncoder();
2224

23-
$symfonySerializer = new Serializer([$normalizer], [$encoder]);
25+
$symfonySerializer = new Serializer([
26+
self::createDateTimeNormalizer($symfonyVersion),
27+
new ObjectNormalizer($classMetadataFactory),
28+
], [
29+
new JsonEncoder(),
30+
]);
2431

2532
return new SymfonySerializerAdapter($symfonySerializer);
2633
}
34+
35+
private static function createDateTimeNormalizer(string $symfonyVersion): DateTimeNormalizer
36+
{
37+
// @codeCoverageIgnoreStart
38+
switch ($symfonyVersion) {
39+
case self::SYMFONY_VERSION_LESS_THAN_42:
40+
return new DateTimeNormalizer('Y-m-d');
41+
case self::SYMFONY_VERSION_GREATER_OR_EQUAL_42:
42+
return new DateTimeNormalizer([
43+
'datetime_format' => 'Y-m-d'
44+
]);
45+
}
46+
47+
throw new \InvalidArgumentException(sprintf(
48+
'Given $symfonyVersion is invalid - "%s"',
49+
$symfonyVersion
50+
));
51+
// @codeCoverageIgnoreEnd
52+
}
2753
}

src/Serializer/SerializerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
interface SerializerInterface
88
{
99
public function deserialize(string $class, $data): object;
10+
11+
public function serialize(object $data): string;
1012
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Lamoda\OmsClient\V2\Dto;
6+
7+
abstract class CreateOrderForEmissionICRequest
8+
{
9+
/**
10+
* @var OrderProduct[]
11+
*/
12+
private $products;
13+
14+
/**
15+
* @param OrderProduct[] $products
16+
*/
17+
public function __construct(array $products)
18+
{
19+
$this->products = $products;
20+
}
21+
22+
final public function getProducts(): array
23+
{
24+
return $this->products;
25+
}
26+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Lamoda\OmsClient\V2\Dto;
6+
7+
use DateTimeInterface;
8+
9+
final class CreateOrderForEmissionICRequestLight extends CreateOrderForEmissionICRequest
10+
{
11+
public const RELEASE_METHOD_TYPE_PRODUCTION = 'PRODUCTION';
12+
public const RELEASE_METHOD_TYPE_IMPORT = 'IMPORT';
13+
public const RELEASE_METHOD_TYPE_REMAINS = 'REMAINS';
14+
15+
public const CREATE_METHOD_TYPE_SELF_MADE = 'SELF_MADE';
16+
public const CREATE_METHOD_TYPE_CEM = 'CEM';
17+
18+
/**
19+
* @var string
20+
*/
21+
private $contactPerson;
22+
/**
23+
* @var string
24+
*/
25+
private $releaseMethodType;
26+
/**
27+
* @var string
28+
*/
29+
private $createMethodType;
30+
/**
31+
* @var string
32+
*/
33+
private $productionOrderId;
34+
/**
35+
* @var string
36+
*/
37+
private $contractNumber;
38+
/**
39+
* @var DateTimeInterface
40+
*/
41+
private $contractDate;
42+
43+
/**
44+
* CreateOrderForEmissionICRequestLight constructor.
45+
* @param string $contactPerson
46+
* @param string $releaseMethodType
47+
* @param string $createMethodType
48+
* @param string $productionOrderId
49+
* @param string $contractNumber
50+
* @param DateTimeInterface $contractDate
51+
* @param OrderProduct[] $products
52+
*/
53+
public function __construct(
54+
string $contactPerson,
55+
string $releaseMethodType,
56+
string $createMethodType,
57+
string $productionOrderId,
58+
string $contractNumber,
59+
DateTimeInterface $contractDate,
60+
array $products
61+
) {
62+
parent::__construct($products);
63+
64+
$this->contactPerson = $contactPerson;
65+
$this->releaseMethodType = $releaseMethodType;
66+
$this->createMethodType = $createMethodType;
67+
$this->productionOrderId = $productionOrderId;
68+
$this->contractNumber = $contractNumber;
69+
$this->contractDate = $contractDate;
70+
}
71+
72+
public function getContactPerson(): string
73+
{
74+
return $this->contactPerson;
75+
}
76+
77+
public function getReleaseMethodType(): string
78+
{
79+
return $this->releaseMethodType;
80+
}
81+
82+
public function getCreateMethodType(): string
83+
{
84+
return $this->createMethodType;
85+
}
86+
87+
public function getProductionOrderId(): string
88+
{
89+
return $this->productionOrderId;
90+
}
91+
92+
public function getContractNumber(): string
93+
{
94+
return $this->contractNumber;
95+
}
96+
97+
public function getContractDate(): DateTimeInterface
98+
{
99+
return $this->contractDate;
100+
}
101+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Lamoda\OmsClient\V2\Dto;
6+
7+
final class CreateOrderForEmissionICResponse
8+
{
9+
/**
10+
* @var string
11+
*/
12+
private $omsId;
13+
/**
14+
* @var string
15+
*/
16+
private $orderId;
17+
/**
18+
* @var int
19+
*/
20+
private $expectedCompletionTime;
21+
22+
public function __construct(string $omsId, string $orderId, int $expectedCompletionTime)
23+
{
24+
$this->omsId = $omsId;
25+
$this->orderId = $orderId;
26+
$this->expectedCompletionTime = $expectedCompletionTime;
27+
}
28+
29+
public function getOmsId(): string
30+
{
31+
return $this->omsId;
32+
}
33+
34+
public function getOrderId(): string
35+
{
36+
return $this->orderId;
37+
}
38+
39+
public function getExpectedCompletionTime(): int
40+
{
41+
return $this->expectedCompletionTime;
42+
}
43+
}

src/V2/Dto/OrderProduct.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Lamoda\OmsClient\V2\Dto;
6+
7+
abstract class OrderProduct
8+
{
9+
public const SERIAL_NUMBER_TYPE_SELF_MADE = 'SELF_MADE';
10+
public const SERIAL_NUMBER_TYPE_OPERATOR = 'OPERATOR';
11+
12+
/**
13+
* @var string
14+
*/
15+
private $gtin;
16+
/**
17+
* @var int
18+
*/
19+
private $quantity;
20+
/**
21+
* @var string
22+
*/
23+
private $serialNumberType;
24+
/**
25+
* @var string[] | null
26+
*/
27+
private $serialNumbers;
28+
/**
29+
* @var integer
30+
*/
31+
private $templateId;
32+
33+
public function __construct(string $gtin, int $quantity, string $serialNumberType, int $templateId)
34+
{
35+
$this->gtin = $gtin;
36+
$this->quantity = $quantity;
37+
$this->serialNumberType = $serialNumberType;
38+
$this->templateId = $templateId;
39+
}
40+
41+
public function getGtin(): string
42+
{
43+
return $this->gtin;
44+
}
45+
46+
public function getQuantity(): int
47+
{
48+
return $this->quantity;
49+
}
50+
51+
public function getSerialNumberType(): string
52+
{
53+
return $this->serialNumberType;
54+
}
55+
56+
public function getTemplateId(): int
57+
{
58+
return $this->templateId;
59+
}
60+
61+
public function getSerialNumbers(): ?array
62+
{
63+
return $this->serialNumbers;
64+
}
65+
66+
public function setSerialNumbers(?array $serialNumbers): void
67+
{
68+
$this->serialNumbers = $serialNumbers;
69+
}
70+
}

0 commit comments

Comments
 (0)