Skip to content

Commit

Permalink
Fix PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
a-melnikov committed Aug 5, 2022
1 parent d0635a0 commit c51b2d9
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 264 deletions.
268 changes: 24 additions & 244 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Definition/Resolver/AliasedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface AliasedInterface
* For instance:
* array('myMethod' => 'myAlias')
*
* @return array<string,string>
* @return array<string|int,string>
*/
public static function getAliases(): array;
}
16 changes: 10 additions & 6 deletions src/Error/UserErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Overblog\GraphQLBundle\Error;

use Exception;
use GraphQL\Error\UserError as WebonyxUserError;
use InvalidArgumentException;
use RuntimeException;
use function is_object;
Expand All @@ -13,9 +14,12 @@

class UserErrors extends RuntimeException
{
/** @var UserError[] */
/** @var WebonyxUserError[] */
private array $errors = [];

/**
* @param array<WebonyxUserError|string> $errors
*/
public function __construct(
array $errors,
string $message = '',
Expand All @@ -27,7 +31,7 @@ public function __construct(
}

/**
* @param UserError[]|string[] $errors
* @param WebonyxUserError[]|string[] $errors
*/
public function setErrors(array $errors): void
{
Expand All @@ -37,14 +41,14 @@ public function setErrors(array $errors): void
}

/**
* @param string|\GraphQL\Error\UserError $error
* @param string|WebonyxUserError $error
*/
public function addError($error): self
{
if (is_string($error)) {
$error = new UserError($error);
} elseif (!is_object($error) || !$error instanceof \GraphQL\Error\UserError) {
throw new InvalidArgumentException(sprintf('Error must be string or instance of %s.', \GraphQL\Error\UserError::class));
} elseif (!is_object($error) || !$error instanceof WebonyxUserError) {
throw new InvalidArgumentException(sprintf('Error must be string or instance of %s.', WebonyxUserError::class));
}

$this->errors[] = $error;
Expand All @@ -53,7 +57,7 @@ public function addError($error): self
}

/**
* @return UserError[]
* @return WebonyxUserError[]
*/
public function getErrors(): array
{
Expand Down
12 changes: 6 additions & 6 deletions src/Generator/ConfigBuilder/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use GraphQL\Type\Definition\Type;
use Murtukov\PHPCodeGenerator\ArrowFunction;
use Murtukov\PHPCodeGenerator\Closure;
use Murtukov\PHPCodeGenerator\Collection as MurtucovCollection;
use Murtukov\PHPCodeGenerator\GeneratorInterface;
use Murtukov\PHPCodeGenerator\Literal;
use Murtukov\PHPCodeGenerator\PhpFile;
Expand All @@ -24,6 +23,9 @@
use Overblog\GraphQLBundle\Generator\ResolveInstructionBuilder;
use Overblog\GraphQLBundle\Generator\TypeGenerator;
use Overblog\GraphQLBundle\Generator\ValidationRulesBuilder;
use function array_key_exists;
use function in_array;
use function is_string;

class FieldsBuilder implements ConfigBuilderInterface
{
Expand Down Expand Up @@ -71,15 +73,13 @@ public function build(TypeConfig $typeConfig, Collection $builder, PhpFile $phpF
* 'resolve' => {@see \Overblog\GraphQLBundle\Generator\ResolveInstructionBuilder::build()},
* 'complexity' => {@see buildComplexity},
* ]
* </code>
*
* @return GeneratorInterface|Collection|string
* </code>.
*
* @throws GeneratorException
*
* @internal
*/
protected function buildField(FieldConfig $fieldConfig, TypeConfig $typeConfig, PhpFile $phpFile): MurtucovCollection
protected function buildField(FieldConfig $fieldConfig, TypeConfig $typeConfig, PhpFile $phpFile): Collection
{
// TODO(any): modify `InputValidator` and `TypeDecoratorListener` to support it before re-enabling this
// see https://github.com/overblog/GraphQLBundle/issues/973
Expand Down Expand Up @@ -179,7 +179,7 @@ protected function buildAccess($access)
* 'description' => 'Some fancy description.',
* 'defaultValue' => 'admin',
* ]
* </code>
* </code>.
*
* @throws GeneratorException
*
Expand Down
4 changes: 1 addition & 3 deletions src/Validator/Mapping/ObjectMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public function __construct(ValidationNode $object)
}

/**
* @param string $property
*
* @return $this|ObjectMetadata
*/
public function addPropertyConstraint($property, Constraint $constraint): self
public function addPropertyConstraint(string $property, Constraint $constraint): self
{
if (!isset($this->properties[$property])) {
$this->properties[$property] = new PropertyMetadata($property);
Expand Down
2 changes: 1 addition & 1 deletion tests/Config/Parser/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

abstract class TestCase extends WebTestCase
{
/** @var ContainerBuilder|MockObject */
/** @var ContainerBuilder & MockObject */
protected $containerBuilder;

public function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GraphQLServicesPassTest extends TestCase
*/
public function testInvalidAlias($invalidAlias): void
{
/** @var ContainerBuilder|MockObject $container */
/** @var ContainerBuilder & MockObject $container */
$container = $this->getMockBuilder(ContainerBuilder::class)
->onlyMethods(['findTaggedServiceIds', 'findDefinition'])
->getMock();
Expand Down
4 changes: 2 additions & 2 deletions tests/EventListener/TypeDecoratorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ private function decorate(array $types, array $map): void
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|ResolverMap
* @return \PHPUnit\Framework\MockObject\MockObject & ResolverMap
*/
private function createResolverMapMock(array $map = [])
private function createResolverMapMock(array $map = []): ResolverMap
{
$resolverMap = $this->getMockBuilder(ResolverMap::class)->setMethods(['map'])->getMock();
$resolverMap->expects($this->any())->method('map')->willReturn($map);
Expand Down

0 comments on commit c51b2d9

Please sign in to comment.