Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #115

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand All @@ -19,20 +19,20 @@ jobs:
extensions: mbstring
php-version: 8.3

- run: composer install --no-interaction --no-progress --no-suggest
- uses: ramsey/composer-install@v3

- run: composer normalize

- run: git pull

- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Normalize composer.json

php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand All @@ -42,12 +42,12 @@ jobs:
extensions: mbstring
php-version: 8.3

- run: composer install --no-interaction --no-progress --no-suggest
- uses: ramsey/composer-install@v3

- run: vendor/bin/php-cs-fixer fix

- run: git pull

- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply php-cs-fixer changes
29 changes: 13 additions & 16 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -25,15 +25,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: mbstring
php-version: 8.3

- run: composer install --no-interaction --no-progress
- uses: ramsey/composer-install@v3

- run: vendor/bin/phpstan analyse --configuration=phpstan.neon

Expand All @@ -49,28 +49,24 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4
dependencies:
- lowest
- locked
- highest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: mbstring
php-version: ${{ matrix.php-version }}

- if: matrix.dependencies == 'lowest'
run: composer update --prefer-lowest --no-interaction --no-progress

- if: matrix.dependencies == 'locked'
run: composer install --no-interaction --no-progress

- if: matrix.dependencies == 'highest'
run: composer update --no-interaction --no-progress
- uses: ramsey/composer-install@v3
with:
dependency-versions: "${{ matrix.dependencies }}"

- run: vendor/bin/phpunit

Expand All @@ -89,7 +85,7 @@ jobs:
- polymorphic

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -105,16 +101,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
coverage: pcov
extensions: mbstring
php-version: 8.3

- run: composer install --no-interaction --no-progress
- uses: ramsey/composer-install@v3

- run: vendor/bin/phpunit --coverage-clover=build/logs/clover.xml

- uses: codecov/codecov-action@v2
# Not using v4 due to the breaking changes described in https://github.com/codecov/codecov-action/releases/tag/v4.0.0
- uses: codecov/codecov-action@v3
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Allow `thecodingmachine/safe` v3 as dependency

## v0.35.0

### Changed
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"psr/http-client": "^1",
"symfony/console": "^5 || ^6 || ^7",
"symfony/var-exporter": "^5.3 || ^6 || ^7",
"thecodingmachine/safe": "^1 || ^2",
"thecodingmachine/safe": "^1 || ^2 || ^3",
"webonyx/graphql-php": "^14.11.3 || ^15"
},
"require-dev": {
Expand All @@ -30,20 +30,20 @@
"ergebnis/composer-normalize": "^2.13",
"friendsofphp/php-cs-fixer": "~3.63.0",
"guzzlehttp/guzzle": "^7",
"jangregor/phpstan-prophecy": "^1",
"jangregor/phpstan-prophecy": "^1 || ^2",
"mll-lab/php-cs-fixer-config": "^5",
"mockery/mockery": "^1.4",
"nyholm/psr7": "^1.4",
"php-http/httplug": "^2",
"php-http/mock-client": "^1.4",
"phpstan/extension-installer": "^1",
"phpstan/phpstan": "^1",
"phpstan/phpstan-mockery": "^1",
"phpstan/phpstan-phpunit": "^1",
"phpstan/phpstan-strict-rules": "^1",
"phpunit/phpunit": "^9.5.2 || ^10 || ^11",
"phpstan/phpstan": "^1 || ^2",
"phpstan/phpstan-mockery": "^1 || ^2",
"phpstan/phpstan-phpunit": "^1 || ^2",
"phpstan/phpstan-strict-rules": "^1 || ^2",
"phpunit/phpunit": "^9.5.2 || ^10 || ^11 || ^12",
"spawnia/phpunit-assert-directory": "^2",
"symfony/var-dumper": "^5.2.3",
"symfony/var-dumper": "^5.2.3 || ^6 || ^7",
"thecodingmachine/phpstan-safe-rule": "^1.1"
},
"suggest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public function fromGraphQL($value): \Spawnia\Sailor\CustomTypes\Types\BenSampoE
public function toGraphQL($value): string
{
if (! $value instanceof \Spawnia\Sailor\CustomTypes\Types\BenSampoEnum) {
throw new \InvalidArgumentException('Expected instanceof Spawnia\Sailor\CustomTypes\Types\BenSampoEnum, got: '.gettype($value));
$actualType = gettype($value);
throw new \InvalidArgumentException("Expected instanceof Spawnia\Sailor\CustomTypes\Types\BenSampoEnum, got {$actualType}.");
}

// @phpstan-ignore-next-line generated enum values are always strings
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
parameters:
level: max
level: 8
paths:
- examples/custom-types/expected
- examples/input/expected
Expand Down
9 changes: 2 additions & 7 deletions src/Codegen/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,8 @@ public static function parseDocuments(array $documents): array
try {
$parsed[$path] = Parser::parse($content);
} catch (SyntaxError $error) {
throw new Error(
// Inform the user which file the error occurred in.
"Failed to parse {$path}: {$error->getMessage()}.",
null,
$error->getSource(),
$error->getPositions()
);
// Inform the user which file the error occurred in.
throw new Error("Failed to parse {$path}: {$error->getMessage()}.", null, $error->getSource(), $error->getPositions());
}
}

Expand Down
23 changes: 9 additions & 14 deletions src/Introspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,15 @@ protected function fetchIntrospectionResult(Client $client, bool $directiveIsRep
);

if (isset($response->errors)) {
throw new ResultErrorsException(
array_map(
function (\stdClass $raw): Error {
$parsed = $this->endpointConfig->parseError($raw);
$parsed->configFile = $this->configFile;
$parsed->endpointName = $this->endpointName;

return $parsed;
},
$response->errors
),
$this->configFile,
$this->endpointName
);
$parsedErrors = array_map(function (\stdClass $raw): Error {
$parsed = $this->endpointConfig->parseError($raw);
$parsed->configFile = $this->configFile;
$parsed->endpointName = $this->endpointName;

return $parsed;
}, $response->errors);

throw new ResultErrorsException($parsedErrors, $this->configFile, $this->endpointName);
}

return $response;
Expand Down
3 changes: 2 additions & 1 deletion src/Type/BenSampoEnumTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ protected function decorateTypeConverterClass(Type $type, ClassType $class, Meth
$toGraphQL->setReturnType('string');
$toGraphQL->setBody(<<<PHP
if (! \$value instanceof \\{$customEnumClass}) {
throw new \InvalidArgumentException('Expected instanceof {$customEnumClass}, got: '.gettype(\$value));
\$actualType = gettype(\$value);
throw new \InvalidArgumentException("Expected instanceof {$customEnumClass}, got {\$actualType}.");
}

// @phpstan-ignore-next-line generated enum values are always strings
Expand Down
11 changes: 6 additions & 5 deletions src/Type/EnumTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function generateClasses(): iterable

public function enumClassName(): string
{
return $this->endpointConfig->typesNamespace() . '\\' . Escaper::escapeClassName($this->enumType->name);
$namespace = $this->endpointConfig->typesNamespace();
$className = Escaper::escapeClassName($this->enumType->name);

return "{$namespace}\\{$className}";
}

protected function makeEnumClass(): ClassType
Expand All @@ -66,10 +69,8 @@ protected function decorateEnumClass(ClassType $class): ClassType
{
foreach ($this->enumType->getValues() as $value) {
$name = $value->name;
$class->addConstant(
Escaper::escapeMemberConstantName($name),
$name
);
$escapedName = Escaper::escapeMemberConstantName($name);
$class->addConstant($escapedName, $name);
}

return $class;
Expand Down
7 changes: 5 additions & 2 deletions src/Type/InputObjectTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ public function __construct(EndpointConfig $endpointConfig, Schema $schema, Inpu
/** @return class-string<ObjectLike> */
public function className(): string
{
// @phpstan-ignore-next-line Method Spawnia\Sailor\Codegen\InputGenerator::className() should return class-string<Spawnia\Sailor\Type\Input> but returns string.
return $this->endpointConfig->typesNamespace() . '\\' . Escaper::escapeClassName($this->inputObjectType->name);
$namespace = $this->endpointConfig->typesNamespace();
$className = Escaper::escapeClassName($this->inputObjectType->name);

// @phpstan-ignore return.type (class-string not inferred)
return "{$namespace}\\{$className}";
}

public function typeConverter(): string
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Convert/FloatConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Spawnia\Sailor\Convert\FloatConverter;
use Spawnia\Sailor\Convert\TypeConverter;

final class FloatConverterTest extends TypeConverterTest
final class FloatConverterTest extends TypeConverterTestCase
{
public function testAcceptsInt(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Convert/IDConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Spawnia\Sailor\Convert\IDConverter;
use Spawnia\Sailor\Convert\TypeConverter;

final class IDConverterTest extends TypeConverterTest
final class IDConverterTest extends TypeConverterTestCase
{
public function testFromInt(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spawnia\Sailor\Tests\TestCase;

/** @phpstan-import-type StdClassJsonValue from Json */
abstract class TypeConverterTest extends TestCase
abstract class TypeConverterTestCase extends TestCase
{
/**
* @dataProvider internalExternal
Expand Down
4 changes: 2 additions & 2 deletions tests/generate-and-approve-examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
Examples::generate($example);

$expectedPath = Examples::expectedPath($example);
shell_exec("rm -rf {$expectedPath}");
shell_exec("rm -rf {$expectedPath}"); // @phpstan-ignore theCodingMachineSafe.function (we want to ignore errors)

$generatedPath = Examples::generatedPath($example);
// Using -R over --recursive for macOS compatibility
shell_exec("cp -R {$generatedPath} {$expectedPath}");
shell_exec("cp -R {$generatedPath} {$expectedPath}"); // @phpstan-ignore theCodingMachineSafe.function (we want to ignore errors)
}