Skip to content

Commit

Permalink
[Psalm] Treat MismatchingDocblockReturnType as errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Nov 14, 2019
1 parent cb7c915 commit 2a96518
Show file tree
Hide file tree
Showing 87 changed files with 561 additions and 75 deletions.
125 changes: 125 additions & 0 deletions etc/psalm/ZendPriorityQueueStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

// This stub is created to support Psalm generics.

/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Stdlib;

use Countable;
use IteratorAggregate;
use Serializable;

/**
* @psalm-template T
* @template-extends IteratorAggregate<int, T>
* @template-extends ArrayAccess<int|null, T>
*/
class PriorityQueue implements Countable, IteratorAggregate, Serializable
{
const EXTR_DATA = 0x00000001;
const EXTR_PRIORITY = 0x00000002;
const EXTR_BOTH = 0x00000003;

/**
* @param mixed $data
* @param int $priority
*
* @return PriorityQueue
*
* @psalm-param T $data
* @psalm-return PriorityQueue<T>
*/
public function insert($data, $priority = 1) { }

/**
* @param mixed $datum
*
* @return bool False if the item was not found, true otherwise.
*
* @psalm-param T $datum
*/
public function remove($datum) { }

/**
* @return bool
*/
public function isEmpty() { }

/**
* @return int
*/
public function count() { }

/**
* @return mixed
*/
public function top() { }

/**
* @return mixed
*/
public function extract() { }

/**
* @return SplPriorityQueue
*
* @psalm-return SplPriorityQueue<T>
*/
public function getIterator() { }

/**
* @return string
*/
public function serialize() { }

/**
* @param string $data
*
* @return void
*/
public function unserialize($data) { }

/**
* @param int $flag
*
* @return array
*/
public function toArray($flag = self::EXTR_DATA) { }

/**
* @param string $class
*
* @return PriorityQueue
*
* @psalm-return PriorityQueue<T>
*/
public function setInternalQueueClass($class) { }

/**
* @param mixed $datum
*
* @return bool
*
* @psalm-param T $datum
*/
public function contains($datum) { }

/**
* @param int $priority
*
* @return bool
*/
public function hasPriority($priority) { }

/**
* @return void
*/
public function __clone() { }
}
5 changes: 4 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@

<!-- Custom -->

<MismatchingDocblockReturnType errorLevel="info" />
<!-- remove after guzzlehttp-release -->
<!-- see https://github.com/guzzle/guzzle/pull/2273 -->
<InvalidCatch errorLevel="info" />

</issueHandlers>

<stubs>
<file name="etc/psalm/ZendPriorityQueueStub.php" />
</stubs>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ChannelBundle/SyliusChannelBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/CoreBundle/SyliusCoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function validate($order, Constraint $constraint): void

foreach ($shipments as $shipment) {
if (!$this->methodEligibilityChecker->isEligible($shipment, $shipment->getMethod())) {
Assert::isInstanceOf($shipment, ShipmentInterface::class);

$this->context->addViolation(
$constraint->message,
['%shippingMethodName%' => $shipment->getMethod()->getName()]
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/CurrencyBundle/SyliusCurrencyBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/CustomerBundle/SyliusCustomerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/LocaleBundle/SyliusLocaleBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/OrderBundle/SyliusOrderBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/PaymentBundle/SyliusPaymentBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function transform($value): array

return array_combine(
array_map(
/** @psalm-return array-key */
function (ProductOptionValueInterface $productOptionValue): string {
return (string) $productOptionValue->getOptionCode();
},
Expand Down Expand Up @@ -78,7 +77,7 @@ public function reverseTransform($value): ?ProductVariantInterface
*
* @throws TransformationFailedException
*/
private function matches(array $optionValues): ?ProductVariantInterface
private function matches(array $optionValues): ProductVariantInterface
{
foreach ($this->product->getVariants() as $variant) {
foreach ($optionValues as $optionValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ final class ProductsToProductAssociationsTransformer implements DataTransformerI
/** @var RepositoryInterface */
private $productAssociationTypeRepository;

/** @var Collection<array-key, ProductAssociationInterface> */
/**
* @var Collection|ProductAssociationInterface[]
*
* @psalm-var Collection<array-key, ProductAssociationInterface>
*/
private $productAssociations;

public function __construct(
Expand Down Expand Up @@ -79,7 +83,9 @@ public function reverseTransform($values): ?Collection
return null;
}

/** @var Collection<array-key, ProductAssociationInterface> $productAssociations */
/**
* @psalm-var Collection<array-key, ProductAssociationInterface> $productAssociations
*/
$productAssociations = new ArrayCollection();
foreach ($values as $productAssociationTypeCode => $productCodes) {
if (null === $productCodes) {
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ProductBundle/SyliusProductBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class PromotionSubject implements ResourceInterface, PromotionSubjectInterface
/** @var int */
private $id;

/** @var Collection|PromotionInterface[] */
/**
* @var Collection|PromotionInterface[]
*
* @psalm-var Collection<array-key, PromotionInterface>
*/
protected $promotions;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ReviewBundle/SyliusReviewBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ShippingBundle/SyliusShippingBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function check(ResourceControllerEvent $event): void
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);

/** @var ArrayCollection<array-key, PromotionInterface> $previousPromotions */
$previousPromotions = new ArrayCollection($order->getPromotions()->toArray());
$oldTotal = $order->getTotal();

Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/TaxationBundle/SyliusTaxationBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function build(ContainerBuilder $container): void
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/TaxonomyBundle/SyliusTaxonomyBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/UserBundle/SyliusUserBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getSupportedDrivers(): array
}

/**
* {@inheritdoc}
* @psalm-suppress MismatchingDocblockReturnType https://github.com/vimeo/psalm/issues/2345
*/
protected function getModelNamespace(): string
{
Expand Down
7 changes: 6 additions & 1 deletion src/Sylius/Component/Addressing/Model/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ class Country implements CountryInterface
*/
protected $code;

/** @var Collection|ProvinceInterface[] */
/**
* @var Collection|ProvinceInterface[]
*
* @psalm-var Collection<array-key, ProvinceInterface>
*/
protected $provinces;

public function __construct()
{
/** @var ArrayCollection<array-key, ProvinceInterface> $this->provinces */
$this->provinces = new ArrayCollection();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Component/Addressing/Model/CountryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function getName(?string $locale = null): ?string;

/**
* @return Collection|ProvinceInterface[]
*
* @psalm-return Collection<array-key, ProvinceInterface>
*/
public function getProvinces(): Collection;

Expand Down
Loading

0 comments on commit 2a96518

Please sign in to comment.