Skip to content

Commit

Permalink
Code style update:
Browse files Browse the repository at this point in the history
- upgrade BitBag coding standard to the newest version
- add php stan and ecs to build
- php stan and ecs fixes (updated OS headers)
- add promotion constructor where missing
- add message handler attribute instead of interfaces
- remove unused service properties
  • Loading branch information
marekrzytki committed May 13, 2024
1 parent f02f2c1 commit 2daf8e4
Show file tree
Hide file tree
Showing 165 changed files with 1,494 additions and 1,555 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ jobs:
name: Validate database schema
run: (cd tests/Application && bin/console doctrine:schema:validate)

-
name: Run ECS
run: vendor/bin/ecs

-
name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon

-
name: Run PHPSpec
run: vendor/bin/phpspec run --ansi -f progress --no-interaction
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require-dev": {
"behat/behat": "^3.7",
"behat/mink-selenium2-driver": "~1.6.0",
"bitbag/coding-standard": "^1.0.1",
"bitbag/coding-standard": "^3.0.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"gedmo/doctrine-extensions": "^3.9",
Expand Down
17 changes: 7 additions & 10 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/bitbag/coding-standard/ecs.php');
return static function (ECSConfig $config): void {

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/src',
__DIR__ . '/tests',
]);
};
putenv('ALLOW_BITBAG_OS_HEADER=1');

$config->import('vendor/bitbag/coding-standard/ecs.php');
$config->paths(['src', 'tests/Integration', 'tests/Behat', 'tests/Functional']);
};
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- vendor/bitbag/coding-standard/phpstan.neon
parameters:
level: 8
excludePaths:
- src/Exception
- tests/Integration
- tests/Functional
paths:
- src
- tests
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public function it_adds_product_to_wishlist(
$wishlistManager->persist($wishlistProduct)->shouldBeCalled();
$wishlistManager->flush()->shouldBeCalled();

$addProductToWishlist = new AddProductToWishlist(1);
$addProductToWishlist->setWishlist($wishlist->getWrappedObject());
$addProductToWishlist = new AddProductToWishlist(1, $wishlist->getWrappedObject());

$this->__invoke($addProductToWishlist);
}
Expand All @@ -82,8 +81,7 @@ public function it_doesnt_add_product_to_wishlist_if_product_isnt_found(
$wishlistManager->persist($wishlistProduct)->shouldNotBeCalled();
$wishlistManager->flush()->shouldNotBeCalled();

$addProductToWishlist = new AddProductToWishlist(1);
$addProductToWishlist->setWishlist($wishlist->getWrappedObject());
$addProductToWishlist = new AddProductToWishlist(1, $wishlist->getWrappedObject());

$this
->shouldThrow(ProductNotFoundException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function it_adds_product_variant_to_wishlist(
$wishlistManager->persist($wishlist)->shouldBeCalled();
$wishlistManager->flush()->shouldBeCalled();

$addProductVariantToWishlist = new AddProductVariantToWishlist(1);
$addProductVariantToWishlist->setWishlist($wishlist->getWrappedObject());
$addProductVariantToWishlist = new AddProductVariantToWishlist(1, $wishlist->getWrappedObject());

$this->__invoke($addProductVariantToWishlist);
}
Expand All @@ -81,8 +80,7 @@ public function it_doesnt_add_product_variant_to_wishlist_if_variant_isnt_found(
$wishlistManager->persist($wishlistProduct)->shouldNotBeCalled();
$wishlistManager->flush()->shouldNotBeCalled();

$addProductVariantToWishlist = new AddProductVariantToWishlist(1);
$addProductVariantToWishlist->setWishlist($wishlist->getWrappedObject());
$addProductVariantToWishlist = new AddProductVariantToWishlist(1, $wishlist->getWrappedObject());

$this
->shouldThrow(ProductVariantNotFoundException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ public function it_exports_wishlist_to_csv(
): void {
$wishlistProducts = new ArrayCollection([$wishlistItem->getWrappedObject()]);

$headers = [
'variantId',
'productId',
'variantCode',
];

$file->fputcsv($headers)->shouldBeCalled();
$file->fputcsv(ExportWishlistToCsvHandler::CSV_HEADERS)->shouldBeCalled();

$wishlistItem->getCartItem()->willReturn($addToCartCommand);
$addToCartCommand->getCartItem()->willReturn($orderItem);
Expand Down
19 changes: 17 additions & 2 deletions spec/Controller/Action/AddProductVariantToWishlistActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand Down Expand Up @@ -52,8 +53,22 @@ public function it_is_initializable(): void
$this->shouldHaveType(AddProductVariantToWishlistAction::class);
}

public function it_throws_404_when_product_is_not_found(Request $request, ProductVariantRepositoryInterface $productVariantRepository): void
{
public function it_throws_404_when_wishlist_is_not_found(
Request $request,
WishlistRepositoryInterface $wishlistRepository
): void {
$wishlistRepository->find(1)->willReturn(null);

$this->shouldThrow(ResourceNotFoundException::class)->during('__invoke', [1, $request]);
}

public function it_throws_404_when_product_is_not_found(
Request $request,
ProductVariantRepositoryInterface $productVariantRepository,
WishlistRepositoryInterface $wishlistRepository,
WishlistInterface $wishlist
): void {
$wishlistRepository->find(1)->willReturn($wishlist);
$request->get('variantId')->willReturn(1);
$productVariantRepository->find(1)->willReturn(null);

Expand Down
11 changes: 6 additions & 5 deletions src/BitBagSyliusWishlistPlugin.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand Down Expand Up @@ -33,7 +34,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(
new SyliusMessageBusPolyfillPass(),
PassConfig::TYPE_BEFORE_OPTIMIZATION,
1
1,
);
}
}
30 changes: 19 additions & 11 deletions src/Checker/ProductProcessingChecker.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusWishlistPlugin\Checker;

use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;

final class ProductProcessingChecker implements ProductProcessingCheckerInterface
{
public function __construct(
private ProductQuantityCheckerInterface $productQuantityChecker
private readonly ProductQuantityCheckerInterface $productQuantityChecker,
) {
}

public function canBeProcessed(WishlistItemInterface $wishlistProduct): bool
public function canBeProcessed(WishlistItemInterface $wishlistItem): bool
{
$cartItem = $wishlistProduct->getCartItem()->getCartItem();
/** @var ?AddToCartCommandInterface $addToCartCommand */
$addToCartCommand = $wishlistItem->getCartItem();

return $this->isInStock($wishlistProduct) && $this->productQuantityChecker->hasPositiveQuantity($cartItem);
if (null === $addToCartCommand) {
return false;
}

$cartItem = $addToCartCommand->getCartItem();

return $this->isInStock($wishlistItem) && $this->productQuantityChecker->hasPositiveQuantity($cartItem);
}

private function isInStock(WishlistItem $wishlistProduct): bool
private function isInStock(WishlistItemInterface $wishlistItem): bool
{
if (0 < $wishlistProduct->getOrderItemQuantity()) {
if (0 < $wishlistItem->getOrderItemQuantity()) {
return true;
}

Expand Down
11 changes: 6 additions & 5 deletions src/Checker/ProductProcessingCheckerInterface.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand All @@ -14,5 +15,5 @@

interface ProductProcessingCheckerInterface
{
public function canBeProcessed(WishlistItemInterface $wishlistProduct): bool;
public function canBeProcessed(WishlistItemInterface $wishlistItem): bool;
}
9 changes: 5 additions & 4 deletions src/Checker/ProductQuantityChecker.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand Down
9 changes: 5 additions & 4 deletions src/Checker/ProductQuantityCheckerInterface.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand Down
11 changes: 6 additions & 5 deletions src/Command/Wishlist/AddProductToSelectedWishlist.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand All @@ -17,7 +18,7 @@ final class AddProductToSelectedWishlist implements AddProductToSelectedWishlist
{
public function __construct(
private WishlistInterface $wishlist,
private ProductInterface $product
private ProductInterface $product,
) {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand Down
16 changes: 6 additions & 10 deletions src/Command/Wishlist/AddProductToWishlist.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand All @@ -14,13 +15,8 @@

final class AddProductToWishlist implements WishlistTokenValueAwareInterface
{
public int $productId;

private WishlistInterface $wishlist;

public function __construct(int $productId)
public function __construct(public int $productId, private WishlistInterface $wishlist)
{
$this->productId = $productId;
}

public function getWishlist(): WishlistInterface
Expand Down
16 changes: 6 additions & 10 deletions src/Command/Wishlist/AddProductVariantToWishlist.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

Expand All @@ -14,13 +15,8 @@

final class AddProductVariantToWishlist implements WishlistTokenValueAwareInterface
{
public int $productVariantId;

private WishlistInterface $wishlist;

public function __construct(int $productVariantId)
public function __construct(public int $productVariantId, private WishlistInterface $wishlist)
{
$this->productVariantId = $productVariantId;
}

public function getWishlist(): WishlistInterface
Expand Down
Loading

0 comments on commit 2daf8e4

Please sign in to comment.