Skip to content

Commit

Permalink
Did some refactorings after review
Browse files Browse the repository at this point in the history
  • Loading branch information
rs2487 committed Sep 24, 2020
1 parent 2002b20 commit cb1a297
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Controller/Content/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\MessageBusInterface;
use Webmozart\Assert\Assert;

abstract class ContentController implements ClassResourceInterface
{
Expand Down Expand Up @@ -108,8 +109,11 @@ abstract protected function handlePublish(string $resourceId, string $locale): v

abstract protected function getResourceKey(): string;

public function getLocale(Request $request)
public function getLocale(Request $request): string
{
return $request->query->get('locale') ?? '';
$locale = $request->query->get('locale');
Assert::notNull($locale);

return $locale;
}
}
8 changes: 6 additions & 2 deletions Controller/Product/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Webmozart\Assert\Assert;

class ProductController implements ClassResourceInterface, SecuredControllerInterface
{
Expand Down Expand Up @@ -78,8 +79,11 @@ public function getSecurityContext()
return SyliusConsumerAdmin::PRODUCT_SECURITY_CONTEXT;
}

public function getLocale(Request $request)
public function getLocale(Request $request): string
{
return $request->query->get('locale') ?? '';
$locale = $request->query->get('locale');
Assert::notNull($locale);

return $locale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\SyliusConsumerBundle\Tests\Functional\Model\Product\Handler;

use Sulu\Bundle\SyliusConsumerBundle\Model\Product\Message\SynchronizeProductMessage;
use Sulu\Bundle\SyliusConsumerBundle\Model\Product\ProductInformation;
use Sulu\Bundle\SyliusConsumerBundle\Tests\Functional\Traits\DimensionTrait;
use Sulu\Bundle\SyliusConsumerBundle\Tests\Functional\Traits\ProductInformationTrait;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
Expand Down Expand Up @@ -41,6 +42,7 @@ public function testSynchronizeProductCreate()

$messageBus->dispatch($message);

/** @var ProductInformation|null $result */
$result = $this->findProductInformationByCode(ExampleSynchronizeProductMessage::getCode(), 'de');
$this->assertNotNull($result);

Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Traits/ProductInformationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function createProductInformation(string $productId, string $locale):
]
);

/** @var ProductInterface $product */
/** @var ProductInterface|null $product */
$product = $this->getEntityManager()->find(Product::class, $productId);
if (!$product instanceof ProductInterface) {
throw new \RuntimeException('Product not fount');
Expand All @@ -54,7 +54,7 @@ protected function createProductInformationLive(string $productId, string $local
]
);

/** @var ProductInterface $product */
/** @var ProductInterface|null $product */
$product = $this->getEntityManager()->find(Product::class, $productId);
if (!$product instanceof ProductInterface) {
throw new \RuntimeException('Product not fount');
Expand Down
7 changes: 5 additions & 2 deletions Tests/Functional/Traits/ProductTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ protected function createProduct(string $code): Product
return $product;
}

protected function findProduct(string $code): ?object
protected function findProduct(string $code): ?Product
{
return $this->getEntityManager()->find(Product::class, $code);
/** @var Product $product */
$product = $this->getEntityManager()->find(Product::class, $code);

return $product;
}

/**
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-doctrine": "^0.11",
"phpstan/phpstan-symfony": "^0.11",
"phpstan/phpstan-webmozart-assert": "0.11.3",
"phpunit/phpunit": "^8.2",
"symfony/browser-kit": "^4.3",
"symfony/dotenv": "^4.3",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ includes:
- vendor/jangregor/phpstan-prophecy/src/extension.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
level: 7
Expand Down

0 comments on commit cb1a297

Please sign in to comment.