Skip to content

Commit ee23c04

Browse files
spawniaStyleCIBot
authored andcommitted
Apply fixes from StyleCI
1 parent 48c4a05 commit ee23c04

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

src/Email.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Email extends StringScalar
1111
{
1212
/** @var string */
1313
public $description = 'A valid RFC 5321 compliant email.';
14-
14+
1515
/**
1616
* Check if the given string is a valid email.
1717
*
@@ -21,9 +21,9 @@ class Email extends StringScalar
2121
*/
2222
protected function isValid(string $stringValue): bool
2323
{
24-
return (new EmailValidator)->isValid(
24+
return (new EmailValidator())->isValid(
2525
$stringValue,
26-
new RFCValidation
26+
new RFCValidation()
2727
);
2828
}
2929
}

src/Regex.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class Regex extends ScalarType
1919
* @return string
2020
*/
2121
abstract protected function regex(): string;
22-
22+
2323
/**
2424
* This factory method allows you to create a Regex scalar in a one-liner.
2525
*
@@ -82,7 +82,7 @@ public function serialize($value): string
8282
public function parseValue($value): string
8383
{
8484
$stringValue = assertString($value, Error::class);
85-
85+
8686
if (!$this->matchesRegex($stringValue)) {
8787
$safeValue = Utils::printSafeJson($stringValue);
8888

@@ -110,7 +110,7 @@ public function parseValue($value): string
110110
public function parseLiteral($valueNode, array $variables = null): string
111111
{
112112
$value = assertStringLiteral($valueNode);
113-
113+
114114
if (!$this->matchesRegex($value)) {
115115
$safeValue = Utils::printSafeJson($value);
116116

src/StringScalar.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ abstract class StringScalar extends ScalarType
2020
* @return bool
2121
*/
2222
abstract protected function isValid(string $stringValue): bool;
23-
23+
2424
/**
2525
* @param string $name The name that the scalar type will have in the schema.
2626
* @param string|null $description A description for the type.
2727
* @param callable $isValid A function that returns a boolean whether a given string is valid.
2828
*
2929
* @return StringScalar
3030
*/
31-
public static function make(string $name, string $description = null, callable $isValid): StringScalar
31+
public static function make(string $name, string $description = null, callable $isValid): self
3232
{
3333
$instance = new class() extends StringScalar {
3434
/**
@@ -43,14 +43,14 @@ protected function isValid(string $stringValue): bool
4343
return call_user_func($this->isValid, $stringValue);
4444
}
4545
};
46-
46+
4747
$instance->name = $name;
4848
$instance->description = $description;
4949
$instance->isValid = $isValid;
50-
50+
5151
return $instance;
5252
}
53-
53+
5454
/**
5555
* Serializes an internal value to include in a response.
5656
*
@@ -68,7 +68,7 @@ public function serialize($value): string
6868

6969
return $stringValue;
7070
}
71-
71+
7272
/**
7373
* Parses an externally provided value (query variable) to use as an input.
7474
*
@@ -81,15 +81,16 @@ public function serialize($value): string
8181
public function parseValue($value): string
8282
{
8383
$stringValue = assertString($value, Error::class);
84-
85-
if(!$this->isValid($stringValue)) {
84+
85+
if (!$this->isValid($stringValue)) {
8686
$safeValue = Utils::printSafeJson($stringValue);
87+
8788
throw new Error("The given string {$safeValue} is not a valid {$this->tryInferName()}.");
8889
}
8990

9091
return $stringValue;
9192
}
92-
93+
9394
/**
9495
* Parses an externally provided literal value (hardcoded in GraphQL query) to use as an input.
9596
*
@@ -108,9 +109,10 @@ public function parseValue($value): string
108109
public function parseLiteral($valueNode, array $variables = null): string
109110
{
110111
$stringValue = assertStringLiteral($valueNode);
111-
112-
if(!$this->isValid($stringValue)) {
112+
113+
if (!$this->isValid($stringValue)) {
113114
$safeValue = Utils::printSafeJson($stringValue);
115+
114116
throw new Error("The given string {$safeValue} is not a valid {$this->tryInferName()}.", $valueNode);
115117
}
116118

src/utils.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ function canBeString($value): bool
2525
/**
2626
* @param $valueNode
2727
*
28-
* @return string
2928
* @throws Error
29+
*
30+
* @return string
3031
*/
3132
function assertStringLiteral($valueNode): string
3233
{
3334
if (!$valueNode instanceof StringValueNode) {
3435
throw new Error("Query error: Can only parse strings got: {$valueNode->kind}", [$valueNode]);
3536
}
36-
37+
3738
return $valueNode->value;
3839
}
3940

@@ -49,9 +50,9 @@ function assertString($value, string $exceptionClass): string
4950
{
5051
if (!canBeString($value)) {
5152
$safeValue = Utils::printSafe($value);
52-
53+
5354
throw new $exceptionClass("The given value {$safeValue} can not be serialized.");
5455
}
55-
56+
5657
return strval($value);
5758
}

tests/EmailTest.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
use GraphQL\Error\Error;
88
use GraphQL\Error\InvariantViolation;
9-
use GraphQL\Language\AST\IntValueNode;
10-
use GraphQL\Language\AST\NodeKind;
119
use GraphQL\Language\AST\StringValueNode;
1210
use MLL\GraphQLScalars\Email;
13-
use MLL\GraphQLScalars\Regex;
1411

1512
class EmailTest extends \PHPUnit\Framework\TestCase
1613
{
@@ -19,7 +16,7 @@ public function testSerializeThrowsIfUnserializableValueIsGiven()
1916
$this->expectException(InvariantViolation::class);
2017
$this->expectExceptionMessageRegExp('/^The given value .* can not be serialized\./');
2118

22-
(new Email)->serialize(
19+
(new Email())->serialize(
2320
new class() {
2421
}
2522
);
@@ -29,13 +26,13 @@ public function testSerializeThrowsIfEmailIsInvalid()
2926
{
3027
$this->expectException(InvariantViolation::class);
3128
$this->expectExceptionMessage('The given string foo is not a valid Email.');
32-
33-
(new Email)->serialize('foo');
29+
30+
(new Email())->serialize('foo');
3431
}
3532

3633
public function testSerializePassesWhenEmailIsInvalid()
3734
{
38-
$serializedResult = (new Email)->serialize('foo@bar');
35+
$serializedResult = (new Email())->serialize('foo@bar');
3936

4037
$this->assertSame('foo@bar', $serializedResult);
4138
}
@@ -45,14 +42,14 @@ public function testParseValueThrowsIfEmailIsInvalid()
4542
$this->expectException(Error::class);
4643
$this->expectExceptionMessage('The given string "foo" is not a valid Email.');
4744

48-
(new Email)->parseValue('foo');
45+
(new Email())->parseValue('foo');
4946
}
5047

5148
public function testParseValuePassesIfEmailIsValid()
5249
{
5350
$this->assertSame(
5451
'foo@bar',
55-
(new Email)->parseValue('foo@bar')
52+
(new Email())->parseValue('foo@bar')
5653
);
5754
}
5855

@@ -61,14 +58,14 @@ public function testParseLiteralThrowsIfNotValidEmail()
6158
$this->expectException(Error::class);
6259
$this->expectExceptionMessage('The given string "foo" is not a valid Email.');
6360

64-
(new Email)->parseLiteral(new StringValueNode(['value' => 'foo']));
61+
(new Email())->parseLiteral(new StringValueNode(['value' => 'foo']));
6562
}
66-
63+
6764
public function testParseLiteralPassesIfEmailIsValid()
6865
{
6966
$this->assertSame(
7067
'foo@bar',
71-
(new Email)->parseLiteral(new StringValueNode(['value' => 'foo@bar']))
68+
(new Email())->parseLiteral(new StringValueNode(['value' => 'foo@bar']))
7269
);
7370
}
7471
}

0 commit comments

Comments
 (0)