Skip to content

Commit 69786f7

Browse files
spawniaStyleCIBot
authored andcommitted
Apply fixes from StyleCI
1 parent b37150e commit 69786f7

File tree

3 files changed

+48
-47
lines changed

3 files changed

+48
-47
lines changed

src/Regex.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class Regex extends ScalarType
2020
* @return string
2121
*/
2222
abstract protected function regex(): string;
23-
23+
2424
/**
2525
* This factory method allows you to create a Regex scalar in a one-liner.
2626
*
@@ -29,7 +29,7 @@ abstract protected function regex(): string;
2929
*
3030
* @return Regex
3131
*/
32-
public static function make(string $name, string $regex): Regex
32+
public static function make(string $name, string $regex): self
3333
{
3434
$regexClass = new class() extends Regex {
3535
/**
@@ -44,13 +44,13 @@ protected function regex(): string
4444
return $this->regex;
4545
}
4646
};
47-
47+
4848
$regexClass->name = $name;
4949
$regexClass->regex = $regex;
50-
50+
5151
return $regexClass;
5252
}
53-
53+
5454
/**
5555
* Serializes an internal value to include in a response.
5656
*
@@ -74,7 +74,7 @@ public function serialize($value): string
7474

7575
return $stringValue;
7676
}
77-
77+
7878
/**
7979
* Parses an externally provided value (query variable) to use as an input.
8080
*
@@ -88,20 +88,21 @@ public function parseValue($value): string
8888
{
8989
if (!canBeString($value)) {
9090
$safeValue = Utils::printSafe($value);
91-
91+
9292
throw new Error("The given value {$safeValue} can not be serialized.");
9393
}
94-
94+
9595
$stringValue = strval($value);
96-
97-
if(!$this->matchesRegex($stringValue)){
96+
97+
if (!$this->matchesRegex($stringValue)) {
9898
$safeValue = Utils::printSafeJson($stringValue);
99+
99100
throw new Error("The given value {$safeValue} did not match the regex {$this->regex()}");
100101
}
101102

102103
return $value;
103104
}
104-
105+
105106
/**
106107
* Parses an externally provided literal value (hardcoded in GraphQL query) to use as an input.
107108
*
@@ -122,14 +123,15 @@ public function parseLiteral($valueNode, array $variables = null): string
122123
if (!$valueNode instanceof StringValueNode) {
123124
throw new Error("Query error: Can only parse strings got: {$valueNode->kind}", [$valueNode]);
124125
}
125-
126+
126127
$value = $valueNode->value;
127-
128-
if(!$this->matchesRegex($value)){
128+
129+
if (!$this->matchesRegex($value)) {
129130
$safeValue = Utils::printSafeJson($value);
131+
130132
throw new Error("The given value {$safeValue} did not match the regex {$this->regex()}", [$valueNode]);
131133
}
132-
134+
133135
return $value;
134136
}
135137

tests/Foo.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Tests;
46

57
use MLL\GraphQLScalars\Regex;

tests/RegexTest.php

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ public function regexClassProvider()
1717
{
1818
return [
1919
[
20-
new class() extends Regex
21-
{
20+
new class() extends Regex {
2221
public $name = 'Foo';
23-
22+
2423
/**
2524
* Return the Regex that the values are validated against.
2625
*
@@ -35,98 +34,96 @@ protected function regex(): string
3534
},
3635
],
3736
[
38-
new Foo
37+
new Foo(),
3938
],
4039
[
41-
Regex::make('Foo', '/foo/')
42-
]
40+
Regex::make('Foo', '/foo/'),
41+
],
4342
];
4443
}
45-
44+
4645
/**
4746
* @dataProvider regexClassProvider
4847
*/
4948
public function testCreateNamedRegexClass(Regex $regex)
5049
{
5150
$this->assertSame('Foo', $regex->name);
5251
}
53-
52+
5453
/**
5554
* @dataProvider regexClassProvider
5655
*/
5756
public function testSerializeThrowsIfUnserializableValueIsGiven(Regex $regex)
5857
{
5958
$this->expectException(InvariantViolation::class);
60-
59+
6160
$regex->serialize(
62-
new class()
63-
{
61+
new class() {
6462
}
6563
);
6664
}
67-
65+
6866
/**
6967
* @dataProvider regexClassProvider
7068
*/
7169
public function testSerializeThrowsIfRegexIsNotMatched(Regex $regex)
7270
{
7371
$this->expectException(InvariantViolation::class);
7472
$this->expectExceptionMessageRegExp('/did not match the regex/');
75-
73+
7674
$regex->serialize('bar');
7775
}
78-
76+
7977
/**
8078
* @dataProvider regexClassProvider
8179
*/
8280
public function testSerializePassesWhenRegexMatches(Regex $regex)
8381
{
8482
$serializedResult = $regex->serialize('foo');
85-
83+
8684
$this->assertSame('foo', $serializedResult);
8785
}
88-
89-
86+
9087
/**
9188
* @dataProvider regexClassProvider
9289
*/
9390
public function testSerializePassesForStringableObject(Regex $regex)
9491
{
9592
$serializedResult = $regex->serialize(
96-
new class()
97-
{
93+
new class() {
9894
public function __toString(): string
9995
{
10096
return 'Contains foo right?';
10197
}
10298
}
10399
);
104-
100+
105101
$this->assertSame('Contains foo right?', $serializedResult);
106102
}
107-
103+
108104
/**
109105
* @dataProvider regexClassProvider
110106
*/
111107
public function testParseValueThrowsIfValueCantBeString(Regex $regex)
112108
{
113109
$this->expectException(Error::class);
114110
$this->expectExceptionMessageRegExp('/can not be serialized/');
115-
116-
$regex->parseValue(new class{});
111+
112+
$regex->parseValue(new class() {
113+
});
117114
}
118-
115+
119116
/**
120117
* @dataProvider regexClassProvider
121118
*/
122119
public function testParseValueThrowsIfValueDoesNotMatch(Regex $regex)
123120
{
124121
$this->expectException(Error::class);
125122
$this->expectExceptionMessageRegExp('/did not match the regex/');
126-
123+
127124
$regex->parseValue('');
128125
}
129-
126+
130127
/**
131128
* @dataProvider regexClassProvider
132129
*/
@@ -137,29 +134,29 @@ public function testParseValuePassesOnMatch(Regex $regex)
137134
$regex->parseValue('foo')
138135
);
139136
}
140-
137+
141138
/**
142139
* @dataProvider regexClassProvider
143140
*/
144141
public function testParseLiteralThrowsIfNotString(Regex $regex)
145142
{
146143
$this->expectException(Error::class);
147-
$this->expectExceptionMessageRegExp('/'. NodeKind::INT.'/');
148-
144+
$this->expectExceptionMessageRegExp('/'.NodeKind::INT.'/');
145+
149146
$regex->parseLiteral(new IntValueNode([]));
150147
}
151-
148+
152149
/**
153150
* @dataProvider regexClassProvider
154151
*/
155152
public function testParseLiteralThrowsIfValueDoesNotMatch(Regex $regex)
156153
{
157154
$this->expectException(Error::class);
158155
$this->expectExceptionMessageRegExp('/did not match the regex/');
159-
156+
160157
$regex->parseLiteral(new StringValueNode(['value' => 'asdf']));
161158
}
162-
159+
163160
/**
164161
* @dataProvider regexClassProvider
165162
*/

0 commit comments

Comments
 (0)