Skip to content

Commit

Permalink
Upgrade to PHPStan 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Jan 15, 2020
1 parent 1b802aa commit 94cd67c
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 28 deletions.
9 changes: 2 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"phpspec/phpspec": "^5.0",
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan-webmozart-assert": "^0.11",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12",
"phpunit/phpunit": "^8.0",
"sensiolabs/security-checker": "^5.0",
"sylius-labs/coding-standard": "^3.0",
Expand All @@ -25,11 +25,6 @@
"symfony/web-profiler-bundle": "^4.1",
"symfony/web-server-bundle": "^4.1"
},
"conflict": {
"phpstan/phpstan-webmozart-assert": "^0.11.3",
"symplify/package-builder": "~7.2",
"symplify/smart-file-system": "~7.2"
},
"autoload": {
"psr-4": {
"Sylius\\ShopApiPlugin\\": "src/"
Expand Down
5 changes: 5 additions & 0 deletions easy-coding-standard.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
imports:
- { resource: 'vendor/sylius-labs/coding-standard/easy-coding-standard.yml' }

parameters:
skip:
SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff.MissingVariable: ~
SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff.NoAssignment: ~
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ includes:

parameters:
level: 6
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false

excludes_analyse:
# Makes PHPStan crash
- src/DependencyInjection/Configuration.php
Expand All @@ -11,3 +14,11 @@ parameters:
- /^Access to an undefined property Symfony\\Component\\Validator\\Constraint::\$message\.$/
- '/Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\)/'
- '/Sylius\\Component\\Core\\Model\\(\w+), Sylius\\Component\\\w+\\Model\\\1 given\./'
- '/Method Sylius\\ShopApiPlugin\\Model\\PaginatorDetails::addToParameters\(\) has parameter \$value with no typehint specified./'
- '/Method Sylius\\ShopApiPlugin\\Command\\\w+\\\w+::__construct\(\) has parameter \$\w+ with no typehint specified./'
- '/Method Sylius\\ShopApiPlugin\\Command\\\w+\\\w+::\w+\(\) has no return typehint specified./'
- '/Method Sylius\\ShopApiPlugin\\Factory\\Customer\\CustomerViewFactoryInterface::create\(\) has no return typehint specified./'
- '/Method Sylius\\ShopApiPlugin\\Validator\\Address\\AddressExistsValidator::validate\(\) has parameter \$id with no typehint specified./'
- '/Method Sylius\\ShopApiPlugin\\Validator\\Address\\\w+::validate\(\) has no return typehint specified./'
- '/Method Sylius\\ShopApiPlugin\\Factory\\Product\\ProductAttributeValueViewResolver\\\w+::getValue\(\) has no return typehint specified./'
- '/Call to static method Webmozart\\Assert\\Assert::implementsInterface\(\) with string/'
2 changes: 1 addition & 1 deletion src/Controller/Customer/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function createValidationMessage(string $validationResults): ValidationE
return $errorMessage;
}

private function addErrorFromField(ValidationErrorView $errorMessage, $errors, $field): void
private function addErrorFromField(ValidationErrorView $errorMessage, array $errors, string $field): void
{
if (isset($errors[$field]['errors'])) {
$errorMessage->errors[$field] = $errors[$field]['errors'];
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Taxon/TaxonDetailsViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function getTaxonWithAncestors(TaxonInterface $taxon, string $localeCode
return $currentTaxonView;
}

private function buildTaxonView(TaxonInterface $taxon, $locale): TaxonView
private function buildTaxonView(TaxonInterface $taxon, string $locale): TaxonView
{
$taxonView = $this->taxonViewFactory->create($taxon, $locale);

Expand Down
2 changes: 1 addition & 1 deletion src/Handler/AddressBook/SetDefaultAddressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __invoke(SetDefaultAddress $setDefaultAddress): void
$this->customerRepository->add($customer);
}

private function assertCurrentUserIsOwner(AddressInterface $address, ShopUserInterface $user)
private function assertCurrentUserIsOwner(AddressInterface $address, ShopUserInterface $user): void
{
Assert::notNull($address->getCustomer(), 'Address is not associated with any user.');
Assert::eq($address->getCustomer()->getId(), $user->getCustomer()->getId(), 'Current user is not owner of this address.');
Expand Down
1 change: 0 additions & 1 deletion src/Mapper/AddressMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function mapExisting(AddressInterface $address, Address $addressData): Ad
{
$this->assertCountryExists($addressData->countryCode());

/** @var AddressInterface $address */
$address->setFirstName($addressData->firstName());
$address->setLastName($addressData->lastName());
$address->setCompany($addressData->company());
Expand Down
2 changes: 1 addition & 1 deletion src/Request/Cart/PutSimpleItemToCartRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PutSimpleItemToCartRequest implements RequestInterface
/** @var int */
protected $quantity;

protected function __construct($token, $productCode, $quantity)
protected function __construct(string $token, string $productCode, int $quantity)
{
$this->token = $token;
$this->productCode = $productCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PutVariantBasedConfigurableItemToCartRequest implements RequestInterface
/** @var int */
protected $quantity;

protected function __construct($token, $productCode, $variantCode, $quantity)
protected function __construct(string $token, string $productCode, string $variantCode, int $quantity)
{
$this->token = $token;
$this->productCode = $productCode;
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Cart/CartExistsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(OrderRepositoryInterface $orderRepository)
}

/** {@inheritdoc} */
public function validate($token, Constraint $constraint)
public function validate($token, Constraint $constraint): void
{
Assert::isInstanceOf($constraint, CartExists::class);

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Cart/CartItemExistsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(OrderItemRepositoryInterface $orderItemRepository)
}

/** {@inheritdoc} */
public function validate($id, Constraint $constraint)
public function validate($id, Constraint $constraint): void
{
if (null === $this->orderItemRepository->find($id)) {
$this->context->addViolation($constraint->message);
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Cart/TokenIsNotUsedValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(OrderRepositoryInterface $orderRepository)
}

/** {@inheritdoc} */
public function validate($token, Constraint $constraint)
public function validate($token, Constraint $constraint): void
{
if (null !== $this->orderRepository->findOneBy(['tokenValue' => $token])) {
$this->context->addViolation($constraint->message);
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/Cart/ValidPromotionCouponCodeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
}

/** {@inheritdoc} */
public function validate($request, Constraint $constraint)
public function validate($request, Constraint $constraint): void
{
/** @var AddCouponRequest $request */
Assert::isInstanceOf($request, AddCouponRequest::class);
Expand All @@ -59,7 +59,7 @@ public function validate($request, Constraint $constraint)
}

/** @param Constraint $constraint */
private function buildViolation(Constraint $constraint)
private function buildViolation(Constraint $constraint): void
{
$this->context
->buildViolation($constraint->message)
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/ChannelExistsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(ChannelRepositoryInterface $channelRepository)
}

/** {@inheritdoc} */
public function validate($token, Constraint $constraint)
public function validate($token, Constraint $constraint): void
{
if (null === $token || null === $this->channelRepository->findOneByCode($token)) {
$this->context->addViolation($constraint->message);
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Customer/ShopUserDoesNotExistValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(UserRepositoryInterface $userRepository)
$this->userRepository = $userRepository;
}

public function validate($email, Constraint $constraint)
public function validate($email, Constraint $constraint): void
{
if (null !== $email && null !== $this->userRepository->findOneByEmail($email)) {
$this->context->addViolation($constraint->message);
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Customer/ShopUserExistsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(UserRepositoryInterface $userRepository)
$this->userRepository = $userRepository;
}

public function validate($email, Constraint $constraint)
public function validate($email, Constraint $constraint): void
{
if (null === $email || null === $this->userRepository->findOneByEmail($email)) {
$this->context->addViolation($constraint->message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(UserRepositoryInterface $userRepository)
$this->userRepository = $userRepository;
}

public function validate($token, Constraint $constraint)
public function validate($token, Constraint $constraint): void
{
if (null === $token || 0 === strlen($token)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Product/ConfigurableProductValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(ProductRepositoryInterface $productRepository)
}

/** {@inheritdoc} */
public function validate($productCode, Constraint $constraint)
public function validate($productCode, Constraint $constraint): void
{
if (null === $productCode) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Product/ProductExistsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(ProductRepositoryInterface $productRepository)
}

/** {@inheritdoc} */
public function validate($productCode, Constraint $constraint)
public function validate($productCode, Constraint $constraint): void
{
if (null === $productCode || null === $this->productRepository->findOneByCode($productCode)) {
$this->context->addViolation($constraint->message);
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Product/ProductVariantExistsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(ProductVariantRepositoryInterface $productVariantRep
}

/** {@inheritdoc} */
public function validate($productVariantCode, Constraint $constraint)
public function validate($productVariantCode, Constraint $constraint): void
{
$product = $this->productVariantRepository->findOneBy(['code' => $productVariantCode]);

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Product/SimpleProductValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(ProductRepositoryInterface $productRepository)
}

/** {@inheritdoc} */
public function validate($productCode, Constraint $constraint)
public function validate($productCode, Constraint $constraint): void
{
if (null === $productCode) {
return;
Expand Down
4 changes: 2 additions & 2 deletions tests/Controller/AddressBook/SetDefaultAddressApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Tests\Sylius\ShopApiPlugin\Controller\AddressBook;

use PHPUnit\Framework\Assert;
use Sylius\Component\Core\Model\ShopUser;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Core\Repository\AddressRepositoryInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
Expand Down Expand Up @@ -36,7 +36,7 @@ public function it_sets_given_address_as_default(): void

/** @var UserRepositoryInterface $userRepository */
$userRepository = $this->get('sylius.repository.shop_user');
/** @var ShopUser $address */
/** @var ShopUserInterface $shopUser */
$shopUser = $userRepository->findOneBy(['username' => 'oliver@queen.com']);

Assert::assertEquals(
Expand Down

0 comments on commit 94cd67c

Please sign in to comment.