Skip to content

Commit

Permalink
Allow symfony/var-exporter:^7
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Jan 19, 2024
1 parent ea0bd9f commit b5df74e
Show file tree
Hide file tree
Showing 63 changed files with 170 additions and 391 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v0.31.0

### Fixed

- Allow `symfony/var-exporter:^7`

## v0.30.1

### Fixed
Expand Down
12 changes: 3 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nette/php-generator": "^3.6.7 || ^4",
"psr/http-client": "^1",
"symfony/console": "^5 || ^6 || ^7",
"symfony/var-exporter": "^5.3 || ^6",
"symfony/var-exporter": "^5.3 || ^6 || ^7",
"thecodingmachine/safe": "^1 || ^2",
"webonyx/graphql-php": "^14.11.3 || ^15"
},
Expand All @@ -31,7 +31,7 @@
"guzzlehttp/guzzle": "^7",
"infection/infection": "~0.21",
"jangregor/phpstan-prophecy": "^1",
"mll-lab/php-cs-fixer-config": "^4.3",
"mll-lab/php-cs-fixer-config": "^5",
"mockery/mockery": "^1.4",
"nyholm/psr7": "^1.4",
"php-http/httplug": "^2",
Expand All @@ -43,7 +43,7 @@
"phpstan/phpstan-phpunit": "^1",
"phpstan/phpstan-strict-rules": "^1",
"phpunit/phpunit": "^9.5.2",
"spawnia/phpunit-assert-directory": "dev-php8 as 3.0.0",
"spawnia/phpunit-assert-directory": "^2",
"symfony/var-dumper": "^5.2.3",
"thecodingmachine/phpstan-safe-rule": "^1.1"
},
Expand All @@ -52,12 +52,6 @@
"guzzlehttp/guzzle": "Enables using the built-in default Client",
"mockery/mockery": "Used in Operation::mock()"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/simpod/phpunit-assert-directory"
}
],
"autoload": {
"psr-4": {
"Spawnia\\Sailor\\": "src/"
Expand Down
8 changes: 2 additions & 6 deletions examples/custom-types/src/CustomObjectTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ final class CustomObjectTypeConfig implements TypeConfig, InputTypeConfig, Outpu

private EndpointConfig $endpointConfig;

/**
* @var Type&NamedType
*/
/** @var Type&NamedType */
private Type $type;

/**
* @param Type&NamedType $type
*/
/** @param Type&NamedType $type */
public function __construct(EndpointConfig $endpointConfig, Type $type)
{
$this->endpointConfig = $endpointConfig;
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-types/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$myCustomEnumQueryResult = MyCustomEnumQuery::execute(
new CustomEnum(CustomEnum::A)
);
assert(CustomEnum::B === $myCustomEnumQueryResult->data->withCustomEnum->value);
assert($myCustomEnumQueryResult->data->withCustomEnum->value === CustomEnum::B);

$foo = 'foo';
$myCustomObjectQueryResult = MyCustomObjectQuery::execute(
Expand Down
4 changes: 2 additions & 2 deletions examples/input/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

require __DIR__ . '/../vendor/autoload.php';

$result = \Spawnia\Sailor\Input\Operations\TakeSomeInput::execute();
$result = Spawnia\Sailor\Input\Operations\TakeSomeInput::execute();

assert(42 === $result->data->takeSomeInput);
assert($result->data->takeSomeInput === 42);
6 changes: 3 additions & 3 deletions examples/php-keywords/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$switch = $result->data->print;
assert($switch instanceof _Switch);

assert(_abstract::_class === $switch->for);
assert(42 === $switch->int);
assert(69 === $switch->as);
assert($switch->for === _abstract::_class);
assert($switch->int === 42);
assert($switch->as === 69);
2 changes: 1 addition & 1 deletion examples/polymorphic/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

assert($userOrPost instanceof UserOrPost\Node\User);
assert($userOrPost->id === $id);
assert('blarg' === $userOrPost->name);
assert($userOrPost->name === 'blarg');
4 changes: 2 additions & 2 deletions examples/simple/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

require __DIR__ . '/../vendor/autoload.php';

$result = \Spawnia\Sailor\Simple\Operations\MyObjectQuery::execute();
$result = Spawnia\Sailor\Simple\Operations\MyObjectQuery::execute();

assert(42 === $result->data->singleObject->value);
assert($result->data->singleObject->value === 42);
18 changes: 5 additions & 13 deletions sailor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public function makeClient(): Spawnia\Sailor\Client
{
return new \Spawnia\Sailor\Client\Guzzle(
return new Spawnia\Sailor\Client\Guzzle(
'https://example.com/graphql',
[
'headers' => [
Expand All @@ -29,33 +29,25 @@ public function makeClient(): Spawnia\Sailor\Client
);
}

/**
* The namespace the generated classes will be created in.
*/
/** The namespace the generated classes will be created in. */
public function namespace(): string
{
return 'Vendor\\ExampleApi';
}

/**
* Path to the directory where the generated classes will be put.
*/
/** Path to the directory where the generated classes will be put. */
public function targetPath(): string
{
return __DIR__ . '/generated/ExampleApi';
}

/**
* Where to look for .graphql files containing operations.
*/
/** Where to look for .graphql files containing operations. */
public function searchPath(): string
{
return __DIR__ . '/src';
}

/**
* The location of the schema file that describes the endpoint.
*/
/** The location of the schema file that describes the endpoint. */
public function schemaPath(): string
{
return __DIR__ . '/example.graphql';
Expand Down
8 changes: 2 additions & 6 deletions src/BelongsToEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

interface BelongsToEndpoint
{
/**
* Path to the config file of the endpoint.
*/
/** Path to the config file of the endpoint. */
public static function config(): string;

/**
* Name of the endpoint this class belongs to.
*/
/** Name of the endpoint this class belongs to. */
public static function endpoint(): string;
}
4 changes: 1 addition & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

interface Client
{
/**
* Execute a GraphQL query against an endpoint and return a Response.
*/
/** Execute a GraphQL query against an endpoint and return a Response. */
public function request(string $query, \stdClass $variables = null): Response;
}
4 changes: 1 addition & 3 deletions src/Client/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class Guzzle implements Client

protected GuzzleClient $guzzle;

/**
* @param array<string, mixed> $config
*/
/** @param array<string, mixed> $config */
public function __construct(string $uri, array $config = [])
{
$this->uri = $uri;
Expand Down
4 changes: 2 additions & 2 deletions src/Codegen/AddTypename.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ protected static function purgeRedundant(SelectionSetNode $selectionSetNode): vo

foreach ($selections as $i => $selection) {
if ($selection instanceof FieldNode) {
if (Introspection::TYPE_NAME_FIELD_NAME === $selection->name->value) {
if ($selection->name->value === Introspection::TYPE_NAME_FIELD_NAME) {
unset($selections[$i]);
}

$subSelectionSet = $selection->selectionSet;
if (null !== $subSelectionSet) {
if ($subSelectionSet !== null) {
static::ensurePresent($subSelectionSet);
}
} elseif ($selection instanceof InlineFragmentNode) {
Expand Down
4 changes: 1 addition & 3 deletions src/Codegen/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

interface ClassGenerator
{
/**
* @return iterable<ClassType>
*/
/** @return iterable<ClassType> */
public function generate(): iterable;
}
2 changes: 1 addition & 1 deletion src/Codegen/DirectoryFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function documents(): array

// When installing from source, the examples might end up in the critical path,
// so we exclude them from the search.
if (false !== mb_strpos($path, 'vendor/spawnia/sailor/')) {
if (mb_strpos($path, 'vendor/spawnia/sailor/') !== false) {
continue;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Codegen/EnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public function __construct(EndpointConfig $endpointConfig, EnumType $enumType)
$this->enumType = $enumType;
}

/**
* @return iterable<ClassType>
*/
/** @return iterable<ClassType> */
public function generate(): iterable
{
$class = $this->makeClass();
Expand Down
6 changes: 2 additions & 4 deletions src/Codegen/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ public static function escapeClassName(string $name): string
: $name;
}

/**
* TODO remove with PHP 8.
*/
/** TODO remove with PHP 8. */
public static function escapeNamespaceName(string $name): string
{
return static::escapeClassName($name);
}

public static function escapeMemberConstantName(string $name): string
{
return 'class' === \strtolower($name)
return \strtolower($name) === 'class'
? "_{$name}"
: $name;
}
Expand Down
12 changes: 3 additions & 9 deletions src/Codegen/FoldFragments.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ class FoldFragments
{
protected DocumentNode $document;

/**
* @var array<string, OperationDefinitionNode>
*/
/** @var array<string, OperationDefinitionNode> */
protected array $operations = [];

/**
* @var array<string, FragmentDefinitionNode>
*/
/** @var array<string, FragmentDefinitionNode> */
protected array $fragments = [];

public function __construct(DocumentNode $document)
Expand Down Expand Up @@ -61,9 +57,7 @@ public function modify(): DocumentNode
]);
}

/**
* @return NodeList<Node&SelectionNode>
*/
/** @return NodeList<Node&SelectionNode> */
protected function extractFields(SelectionSetNode $selectionSet): NodeList
{
/** @var array<int, Node&SelectionNode> $selections */
Expand Down
20 changes: 7 additions & 13 deletions src/Codegen/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(EndpointConfig $endpointConfig, string $configFile,
public function generate(): iterable
{
$parsedDocuments = $this->parsedDocuments();
if ([] === $parsedDocuments) {
if ($parsedDocuments === []) {
return [];
}

Expand Down Expand Up @@ -80,7 +80,7 @@ protected function makeFile(ClassType $classType): File
$file = new File();

$phpNamespace = $classType->getNamespace();
if (null === $phpNamespace) {
if ($phpNamespace === null) {
throw new \Exception('Generated classes must have a namespace.');
}
$namespace = $phpNamespace->getName();
Expand Down Expand Up @@ -109,9 +109,7 @@ protected function targetDirectory(string $namespace): string
return $this->endpointConfig->targetPath() . $pathInTarget;
}

/**
* @see https://stackoverflow.com/a/2638272
*/
/** @see https://stackoverflow.com/a/2638272 */
protected function configPath(string $directory): string
{
$from = explode('/', $directory);
Expand All @@ -136,7 +134,7 @@ protected function configPath(string $directory): string

public static function after(string $subject, string $search): string
{
if ('' === $search) {
if ($search === '') {
return $subject;
}

Expand Down Expand Up @@ -187,14 +185,12 @@ public static function parseDocuments(array $documents): array
return $parsed;
}

/**
* @param array<string, \GraphQL\Language\AST\DocumentNode> $parsed
*/
/** @param array<string, \GraphQL\Language\AST\DocumentNode> $parsed */
public static function validateDocuments(array $parsed): void
{
foreach ($parsed as $path => $documentNode) {
foreach ($documentNode->definitions as $definition) {
if ($definition instanceof OperationDefinitionNode && null === $definition->name) {
if ($definition instanceof OperationDefinitionNode && $definition->name === null) {
throw new Error("Found unnamed operation definition in {$path}.", $definition);
}
}
Expand All @@ -210,9 +206,7 @@ protected function schema(): Schema
return BuildSchema::build($schemaString);
}

/**
* @return array<string, \GraphQL\Language\AST\DocumentNode>
*/
/** @return array<string, \GraphQL\Language\AST\DocumentNode> */
protected function parsedDocuments(): array
{
$documents = $this->endpointConfig
Expand Down
4 changes: 1 addition & 3 deletions src/Codegen/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

class Merger
{
/**
* @param array<string, DocumentNode> $documents
*/
/** @param array<string, DocumentNode> $documents */
public static function combine(array $documents): DocumentNode
{
$root = array_pop($documents);
Expand Down

0 comments on commit b5df74e

Please sign in to comment.