-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for Italy parcel points #9
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,11 @@ class FindPoints extends AbstractCommand | |
private Client $client; | ||
private Serializer $serializer; | ||
|
||
public function __construct(Client $client, Serializer $serializer) | ||
{ | ||
public function __construct( | ||
private readonly ConfigProvider $configProvider, | ||
Client $client, | ||
Serializer $serializer, | ||
) { | ||
$this->client = $client; | ||
$this->serializer = $serializer; | ||
} | ||
|
@@ -27,7 +30,7 @@ public function findPoints(FindPointsRequest $request): FindPointsResponse | |
{ | ||
$httpRequest = new HttpRequest( | ||
$request->getMethod(), | ||
new Uri(ConfigProvider::API_VERSION . $request->getRequestUrl()), | ||
new Uri($this->configProvider->apiVersion . $request->getRequestUrl()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refers to the comment above ☝️ Then the API version does not need to be appended to every request. Am I right? |
||
[ | ||
'Content-type' => 'application/json', | ||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\InpostBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('answear_inpost'); | ||
|
||
$treeBuilder->getRootNode() | ||
->children() | ||
?->scalarNode('baseUrl')->defaultNull()->end() | ||
?->scalarNode('apiVersion')->defaultNull()->end() | ||
?->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,61 @@ | ||||||||||||||||||||||
<?php | ||||||||||||||||||||||
|
||||||||||||||||||||||
declare(strict_types=1); | ||||||||||||||||||||||
|
||||||||||||||||||||||
namespace Answear\InpostBundle\Response\Struct; | ||||||||||||||||||||||
|
||||||||||||||||||||||
class ItemOperatingHours | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @var ItemOperatingHoursDay[] $sunday | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public array $sunday = []; | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @var ItemOperatingHoursDay[] $monday | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public array $monday = []; | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @var ItemOperatingHoursDay[] $tuesday | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public array $tuesday = []; | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @var ItemOperatingHoursDay[] $wednesday | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public array $wednesday = []; | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @var ItemOperatingHoursDay[] $thursday | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public array $thursday = []; | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @var ItemOperatingHoursDay[] $friday | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public array $friday = []; | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @var ItemOperatingHoursDay[] $saturday | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public array $saturday = []; | ||||||||||||||||||||||
|
||||||||||||||||||||||
public static function fromArray(array $operatingHours): self | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
$self = new self(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (!isset($operatingHours['customer'])) { | ||||||||||||||||||||||
return $self; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (!is_array($operatingHours['customer'])) { | ||||||||||||||||||||||
return $self; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+42
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
#whatever There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, the suggested code does not check whether a variable is an array |
||||||||||||||||||||||
|
||||||||||||||||||||||
foreach ($operatingHours['customer'] as $day => $hours) { | ||||||||||||||||||||||
if (!isset($self->{strtolower($day)})) { | ||||||||||||||||||||||
continue; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
foreach ($hours as $periodHours) { | ||||||||||||||||||||||
$self->{strtolower($day)}[] = ItemOperatingHoursDay::fromArray($periodHours); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return $self; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\InpostBundle\Response\Struct; | ||
|
||
class ItemOperatingHoursDay | ||
{ | ||
public function __construct( | ||
public ?int $start = null, | ||
public ?int $end = null, | ||
public ?string $startParsed = null, | ||
public ?string $endParsed = null, | ||
) { | ||
} | ||
|
||
public static function fromArray(array $day): self | ||
{ | ||
$self = new self(); | ||
|
||
if (isset($day['start'])) { | ||
$self->start = $day['start']; | ||
$self->startParsed = self::parseTime($day['start']); | ||
} | ||
|
||
if (isset($day['end'])) { | ||
$self->end = $day['end']; | ||
$self->endParsed = self::parseTime($day['end']); | ||
} | ||
|
||
return $self; | ||
} | ||
|
||
private static function parseTime(int $timestamp): string | ||
{ | ||
return (new \DateTimeImmutable())->setTimestamp($timestamp * 60)->format('H:i'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API version can be included in base url? Since we have base url in env, we can change api version dynamically.
What I mean is removing the API version env variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, it is better to keep the version as a variable and not put it in base_url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason? :D
Take a look at the variables in env that end with
_URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @olekans
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed :)