Skip to content
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

Replaced all Location typehints to LocationInterface #54

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Controller/LocationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace CoopTilleuls\SyliusClickNCollectPlugin\Controller;

use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location;
use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface;
use Doctrine\Persistence\ObjectRepository;
use JMS\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __invoke(string $shippingMethodCode): JsonResponse
}

// TODO: do this at the SQL layer in a repository, at the same do a proper JOIN...
$locations = $shippingMethod->getLocations()->filter(function (Location $p) {
$locations = $shippingMethod->getLocations()->filter(function (LocationInterface $p) {
return $p->isEnabled();
});

Expand Down
6 changes: 3 additions & 3 deletions src/Form/Extension/ShipmentTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace CoopTilleuls\SyliusClickNCollectPlugin\Form\Extension;

use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location;
use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface;
use Doctrine\Persistence\ObjectRepository;
use Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShipmentType;
use Symfony\Component\Form\AbstractTypeExtension;
Expand Down Expand Up @@ -41,9 +41,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder->create('location', HiddenType::class, [
'required' => false,
'attr' => ['class' => 'click_n_collect_location'],
])->addModelTransformer(new CallbackTransformer(function (?Location $location): string {
])->addModelTransformer(new CallbackTransformer(function (?LocationInterface $location): string {
return $location ? (string) $location->getCode() : '';
}, function (?string $code): ?Location {
}, function (?string $code): ?LocationInterface {
if ('' === $code || null === $code) {
return null;
}
Expand Down
14 changes: 12 additions & 2 deletions src/Form/Extension/ShippingMethodTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace CoopTilleuls\SyliusClickNCollectPlugin\Form\Extension;

use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location;
use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface;
use Doctrine\ORM\EntityRepository;
use Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
Expand All @@ -25,11 +25,21 @@
*/
final class ShippingMethodTypeExtension extends AbstractTypeExtension
{
/**
* @var class-string<LocationInterface>
*/
private string $locationDataClass;

public function __construct(string $locationDataClass)
{
$this->locationDataClass = $locationDataClass;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('locations', EntityType::class, [
'class' => Location::class,
'class' => $this->locationDataClass,
'required' => false,
'multiple' => true,
'expanded' => true,
Expand Down
3 changes: 1 addition & 2 deletions src/Repository/CollectionTimeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace CoopTilleuls\SyliusClickNCollectPlugin\Repository;

use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location;
use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface;
use Doctrine\ORM\EntityManagerInterface;

Expand Down Expand Up @@ -82,7 +81,7 @@ public function isSlotFull(LocationInterface $location, \DateTimeInterface $coll
/**
* {@inheritdoc}
*/
public function findShipments(Location $location, \DateTimeInterface $start, \DateTimeInterface $end): array
public function findShipments(LocationInterface $location, \DateTimeInterface $start, \DateTimeInterface $end): array
{
return $this->entityManager->createQuery(<<<DQL
SELECT s
Expand Down
3 changes: 1 addition & 2 deletions src/Repository/CollectionTimeRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace CoopTilleuls\SyliusClickNCollectPlugin\Repository;

use CoopTilleuls\SyliusClickNCollectPlugin\Entity\ClickNCollectShipmentInterface;
use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location;
use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface;

/**
Expand All @@ -41,5 +40,5 @@ public function isSlotFull(LocationInterface $location, \DateTimeInterface $coll
*
* @return ClickNCollectShipmentInterface[]
*/
public function findShipments(Location $location, \DateTimeInterface $start, \DateTimeInterface $end): array;
public function findShipments(LocationInterface $location, \DateTimeInterface $start, \DateTimeInterface $end): array;
}
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</service>

<service id="coop_tilleuls_click_n_collect.form.extension.type.shipping_method" class="CoopTilleuls\SyliusClickNCollectPlugin\Form\Extension\ShippingMethodTypeExtension">
<argument>%coop_tilleuls_click_n_collect.model.location.class%</argument>
<tag name="form.type_extension" />
</service>

Expand Down