Skip to content

Commit

Permalink
Appease PHPStan Level 8 without breaking BC
Browse files Browse the repository at this point in the history
Annotate AuthInterface

Just use array<mixed> for now

Improve Typehints on SelectionSets

Fix getResults return type

Annotate QueryError properties

Use array<mixed> because we don't know what
a user may choose to add into the array
if they are using the QueryError themselves
in a custom implementation of the QueryBuilderInterface

Annotate Client

Add Typehints to Client

Remove unused imports

Move QueryTest to tests/Unit

Improve Variable->__toString()

Remove unused imports
  • Loading branch information
charjr committed Aug 12, 2024
1 parent 6a94da6 commit 9615e75
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
12 changes: 5 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ class Client
/** @var array<string|array<string>> */
protected array $httpHeaders;

/**
* @var array<mixed>
*/
/** @var array<mixed> */
protected array $options;

/**
* Client constructor.
*
* @param array<string,string|array<string>> $authorizationHeaders
* @param array<string, string|array<string>> $authorizationHeaders
* @param array<string,mixed> $httpOptions
*/
public function __construct(
Expand Down Expand Up @@ -68,9 +66,9 @@ public function runQuery(
bool $resultsAsArray = false,
array $variables = []
): Results {
$query = $query instanceof QueryBuilderInterface ?
$query->getQuery() :
$query;
if ($query instanceof QueryBuilderInterface) {
$query = $query->getQuery();
}

return $this->runRawQuery((string) $query, $resultsAsArray, $variables);
}
Expand Down
20 changes: 10 additions & 10 deletions src/QueryBuilder/AbstractQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class AbstractQueryBuilder implements QueryBuilderInterface
/** @var Variable[] */
private array $variables = [];

/** @var array<InlineFragment|Query|string> */
/** @var array<string|InlineFragment|Query|QueryBuilderInterface> */
private array $selectionSet = [];

/** @var array<null|scalar|array<mixed>|Stringable|BackedEnum> */
Expand Down Expand Up @@ -44,16 +44,16 @@ public function getQuery(): Query
}

protected function selectField(
InlineFragment|Query|QueryBuilderInterface|string $selection,
): self {
$this->selectionSet[] = $selection instanceof QueryBuilderInterface ?
$selection->getQuery() :
$selection;
InlineFragment|Query|QueryBuilderInterface|string $selectedField,
): AbstractQueryBuilder {
$this->selectionSet[] = $selectedField;

return $this;
}

/** @param null|array<mixed>|scalar|BackedEnum|Stringable $value */
/**
* @param null|array<mixed>|scalar|BackedEnum|Stringable $value
*/
protected function setArgument(
string $name,
null|bool|float|int|string|array|Stringable|BackedEnum $value
Expand All @@ -65,13 +65,13 @@ protected function setArgument(
return $this;
}

/** @param null|scalar|array<?scalar>|RawObject $defaultValue */
/** @param null|array<mixed>|scalar|BackedEnum|Stringable $defaultValue */
protected function setVariable(
string $name,
string $type,
bool $isRequired = false,
null|bool|float|int|string|array|RawObject $defaultValue = null
): self {
null|bool|float|int|string|array|Stringable|BackedEnum $defaultValue = null,
): AbstractQueryBuilder {
$this->variables[] = new Variable(
$name,
$type,
Expand Down
7 changes: 3 additions & 4 deletions src/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
use BackedEnum;
use GraphQL\InlineFragment;
use GraphQL\Query;
use GraphQL\RawObject;
use Stringable;

class QueryBuilder extends AbstractQueryBuilder
{
public function selectField(
InlineFragment | Query | QueryBuilderInterface | string $selection
InlineFragment|Query|QueryBuilderInterface|string $selectedField,
): AbstractQueryBuilder {
return parent::selectField($selection);

Check failure on line 15 in src/QueryBuilder/QueryBuilder.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Undefined variable: $selection

Check failure on line 15 in src/QueryBuilder/QueryBuilder.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Undefined variable: $selection

Check failure on line 15 in src/QueryBuilder/QueryBuilder.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Undefined variable: $selection

Check failure on line 15 in src/QueryBuilder/QueryBuilder.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Undefined variable: $selection

Check failure on line 15 in src/QueryBuilder/QueryBuilder.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.4, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Undefined variable: $selection
}
Expand All @@ -24,12 +23,12 @@ public function setArgument(
return parent::setArgument($name, $value);
}

/** @param null|scalar|array<?scalar>|RawObject $defaultValue */
/** @param null|array<mixed>|scalar|BackedEnum|Stringable $defaultValue */
public function setVariable(
string $name,
string $type,
bool $isRequired = false,
null|bool|float|int|string|array|RawObject $defaultValue = null,
null|bool|float|int|string|array|Stringable|BackedEnum $defaultValue = null,
): AbstractQueryBuilder {
return parent::setVariable($name, $type, $isRequired, $defaultValue);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getData()
/**
* Returns entire parsed results in the requested format
*
* @return array<?scalar>|object
* @return null|array<?scalar>|object
*/
public function getResults(): null|array|object
{
Expand Down
3 changes: 1 addition & 2 deletions src/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

final readonly class Variable implements \Stringable
{
/** @param null|scalar|array<mixed>|RawObject $defaultValue */
public function __construct(
public string $name,
public string $type,
public bool $nonNullable = false,
public null|bool|float|int|string|array|RawObject $defaultValue = null,
public mixed $defaultValue = null
) {
}

Expand Down

0 comments on commit 9615e75

Please sign in to comment.