Skip to content

Commit 52d62be

Browse files
committed
coding style
1 parent a9a4048 commit 52d62be

27 files changed

+649
-503
lines changed

tests/PhpGenerator/ClassType.addMember.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Assert::same('', $method->getBody());
2525
// duplicity
2626
$class = new ClassType('Example');
2727
$class->addMember(new Nette\PhpGenerator\Method('foo'));
28-
Assert::exception(function () use ($class) {
29-
$class->addMember(new Nette\PhpGenerator\Method('FOO'));
30-
}, Nette\InvalidStateException::class, "Cannot add member 'FOO', because it already exists.");
28+
Assert::exception(
29+
fn() => $class->addMember(new Nette\PhpGenerator\Method('FOO')),
30+
Nette\InvalidStateException::class,
31+
"Cannot add member 'FOO', because it already exists.",
32+
);

tests/PhpGenerator/ClassType.from.bodies.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ Assert::exception(function () {
1515
}, Nette\InvalidStateException::class, 'Source code of PDO not found.');
1616

1717

18-
Assert::exception(function () {
19-
ClassType::from(new class {
18+
Assert::exception(
19+
fn() => ClassType::from(new class {
2020
public function f()
2121
{
2222
}
23-
}, withBodies: true);
24-
}, Nette\NotSupportedException::class, 'The $withBodies parameter cannot be used for anonymous functions.');
23+
}, withBodies: true),
24+
Nette\NotSupportedException::class,
25+
'The $withBodies parameter cannot be used for anonymous functions.',
26+
);
2527

2628

2729
$res = ClassType::from(Abc\Class7::class, withBodies: true);

tests/PhpGenerator/ClassType.phpt

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Assert::true($p->isPublic());
8888
$m = $class->addMethod('getHandle')
8989
->addComment('Returns file handle.')
9090
->addComment('@return resource')
91-
->setFinal(true)
91+
->setFinal()
9292
->setBody('return $this->?;', ['handle']);
9393

9494
Assert::same($m, $class->getMethod('getHandle'));
@@ -102,9 +102,9 @@ Assert::same('public', $m->getVisibility());
102102
Assert::same('return $this->handle;', $m->getBody());
103103

104104
$m = $class->addMethod('getSections')
105-
->setStatic(true)
105+
->setStatic()
106106
->setVisibility('protected')
107-
->setReturnReference(true)
107+
->setReturnReference()
108108
->addBody('$mode = ?;', [123])
109109
->addBody('return self::$sections;');
110110
$m->addParameter('mode', new Literal('self::ORDER'));
@@ -120,19 +120,19 @@ Assert::true($m->isProtected());
120120
Assert::false($m->isPublic());
121121

122122
$method = $class->addMethod('show')
123-
->setAbstract(true);
123+
->setAbstract();
124124

125125
$method->addParameter('foo');
126126
$method->removeParameter('foo');
127127

128128
$method->addParameter('item');
129129

130130
$method->addParameter('res', null)
131-
->setReference(true)
131+
->setReference()
132132
->setType(Type::union(Type::Array, 'null'));
133133

134134
$method->addParameter('bar', null)
135-
->setNullable(true)
135+
->setNullable()
136136
->setType('stdClass|string');
137137

138138
$class->addTrait('foo');
@@ -168,37 +168,48 @@ $method->setParameters(array_values($parameters));
168168
Assert::same($parameters, $method->getParameters());
169169

170170

171-
Assert::exception(function () {
172-
$class = new ClassType;
173-
$class->addMethod('method')->setVisibility('unknown');
174-
}, Nette\InvalidArgumentException::class, 'Argument must be public|protected|private.');
171+
Assert::exception(
172+
fn() => (new ClassType)->addMethod('method')->setVisibility('unknown'),
173+
Nette\InvalidArgumentException::class,
174+
'Argument must be public|protected|private.',
175+
);
175176

176177

177178
// duplicity
178179
$class = new ClassType('Example');
179180
$class->addConstant('a', 1);
180-
Assert::exception(function () use ($class) {
181-
$class->addConstant('a', 1);
182-
}, Nette\InvalidStateException::class, "Cannot add constant 'a', because it already exists.");
181+
Assert::exception(
182+
fn() => $class->addConstant('a', 1),
183+
Nette\InvalidStateException::class,
184+
"Cannot add constant 'a', because it already exists.",
185+
);
183186

184187
$class->addProperty('a');
185-
Assert::exception(function () use ($class) {
186-
$class->addProperty('a');
187-
}, Nette\InvalidStateException::class, "Cannot add property 'a', because it already exists.");
188+
Assert::exception(
189+
fn() => $class->addProperty('a'),
190+
Nette\InvalidStateException::class,
191+
"Cannot add property 'a', because it already exists.",
192+
);
188193

189194
$class->addMethod('a');
190-
Assert::exception(function () use ($class) {
191-
$class->addMethod('a');
192-
}, Nette\InvalidStateException::class, "Cannot add method 'a', because it already exists.");
193-
194-
Assert::exception(function () use ($class) {
195-
$class->addMethod('A');
196-
}, Nette\InvalidStateException::class, "Cannot add method 'A', because it already exists.");
195+
Assert::exception(
196+
fn() => $class->addMethod('a'),
197+
Nette\InvalidStateException::class,
198+
"Cannot add method 'a', because it already exists.",
199+
);
200+
201+
Assert::exception(
202+
fn() => $class->addMethod('A'),
203+
Nette\InvalidStateException::class,
204+
"Cannot add method 'A', because it already exists.",
205+
);
197206

198207
$class->addTrait('A');
199-
Assert::exception(function () use ($class) {
200-
$class->addTrait('A');
201-
}, Nette\InvalidStateException::class, "Cannot add trait 'A', because it already exists.");
208+
Assert::exception(
209+
fn() => $class->addTrait('A'),
210+
Nette\InvalidStateException::class,
211+
"Cannot add trait 'A', because it already exists.",
212+
);
202213

203214

204215
// remove members

tests/PhpGenerator/ClassType.validate.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ require __DIR__ . '/../bootstrap.php';
1111

1212
Assert::exception(function () {
1313
$class = new ClassType('A');
14-
$class->setFinal(true)->setAbstract(true);
14+
$class->setFinal()->setAbstract();
1515
$class->validate();
1616
}, Nette\InvalidStateException::class, "Class 'A' cannot be abstract and final at the same time.");
1717

1818
Assert::exception(function () {
1919
$class = new ClassType('A');
20-
$class->setAbstract(true)->setFinal(true);
20+
$class->setAbstract()->setFinal();
2121
$class->validate();
2222
}, Nette\InvalidStateException::class, "Class 'A' cannot be abstract and final at the same time.");
2323

2424
Assert::exception(function () {
2525
$class = new ClassType;
26-
$class->setAbstract(true);
26+
$class->setAbstract();
2727
$class->validate();
2828
}, Nette\InvalidStateException::class, 'Anonymous class cannot be abstract or final.');

tests/PhpGenerator/Closure.from.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ $closure = #[ExampleAttribute] function (stdClass $a, $b = null) {};
1212

1313
$function = Closure::from($closure);
1414
same(
15-
'#[ExampleAttribute] function (stdClass $a, $b = null) {
16-
}',
15+
<<<'XX'
16+
#[ExampleAttribute] function (stdClass $a, $b = null) {
17+
}
18+
XX,
1719
(string) $function,
1820
);

tests/PhpGenerator/Closure.long.phpt

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,44 @@ for ($name = 'abcde'; $name < 'abcdu'; $name++) {
1717
}
1818

1919
same(
20-
'function (
21-
$abcde,
22-
$abcdf,
23-
$abcdg,
24-
$abcdh,
25-
$abcdi,
26-
$abcdj,
27-
$abcdk,
28-
$abcdl,
29-
$abcdm,
30-
$abcdn,
31-
$abcdo,
32-
$abcdp,
33-
$abcdq,
34-
$abcdr,
35-
$abcds,
36-
$abcdt,
37-
) use (
38-
$abcde,
39-
$abcdf,
40-
$abcdg,
41-
$abcdh,
42-
$abcdi,
43-
$abcdj,
44-
$abcdk,
45-
$abcdl,
46-
$abcdm,
47-
$abcdn,
48-
$abcdo,
49-
$abcdp,
50-
$abcdq,
51-
$abcdr,
52-
$abcds,
53-
$abcdt,
54-
) {
55-
return null;
56-
}',
20+
<<<'XX'
21+
function (
22+
$abcde,
23+
$abcdf,
24+
$abcdg,
25+
$abcdh,
26+
$abcdi,
27+
$abcdj,
28+
$abcdk,
29+
$abcdl,
30+
$abcdm,
31+
$abcdn,
32+
$abcdo,
33+
$abcdp,
34+
$abcdq,
35+
$abcdr,
36+
$abcds,
37+
$abcdt,
38+
) use (
39+
$abcde,
40+
$abcdf,
41+
$abcdg,
42+
$abcdh,
43+
$abcdi,
44+
$abcdj,
45+
$abcdk,
46+
$abcdl,
47+
$abcdm,
48+
$abcdn,
49+
$abcdo,
50+
$abcdp,
51+
$abcdq,
52+
$abcdr,
53+
$abcds,
54+
$abcdt,
55+
) {
56+
return null;
57+
}
58+
XX,
5759
(string) $function,
5860
);

tests/PhpGenerator/Closure.phpt

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ require __DIR__ . '/../bootstrap.php';
1111

1212
$function = new Closure;
1313
$function
14-
->setReturnReference(true)
14+
->setReturnReference()
1515
->setBody('return $a + $b;');
1616

1717
$function->addParameter('a');
1818
$function->addParameter('b');
1919
$function->addUse('this');
2020
$function->addUse('vars')
21-
->setReference(true);
21+
->setReference();
2222

2323
same(
24-
'function &($a, $b) use ($this, &$vars) {
25-
return $a + $b;
26-
}',
24+
<<<'XX'
25+
function &($a, $b) use ($this, &$vars) {
26+
return $a + $b;
27+
}
28+
XX,
2729
(string) $function,
2830
);
2931

@@ -36,9 +38,11 @@ Assert::type(Nette\PhpGenerator\Parameter::class, $uses[1]);
3638
$uses = $function->setUses([$uses[0]]);
3739

3840
same(
39-
'function &($a, $b) use ($this) {
40-
return $a + $b;
41-
}',
41+
<<<'XX'
42+
function &($a, $b) use ($this) {
43+
return $a + $b;
44+
}
45+
XX,
4246
(string) $function,
4347
);
4448

@@ -58,9 +62,11 @@ $function
5862
->addUse('this');
5963

6064
same(
61-
'function () use ($this): array {
62-
return [];
63-
}',
65+
<<<'XX'
66+
function () use ($this): array {
67+
return [];
68+
}
69+
XX,
6470
(string) $function,
6571
);
6672

@@ -71,8 +77,10 @@ $function->setBody('return $a + $b;');
7177
$function->addAttribute('ExampleAttribute');
7278

7379
same(
74-
'#[ExampleAttribute] function () {
75-
return $a + $b;
76-
}',
80+
<<<'XX'
81+
#[ExampleAttribute] function () {
82+
return $a + $b;
83+
}
84+
XX,
7785
(string) $function,
7886
);

tests/PhpGenerator/Dumper.dump().phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ Assert::same(
207207
$dumper->dump(new DateTimeImmutable('2016-06-22 20:52:43.1234', new DateTimeZone('Europe/Prague'))),
208208
);
209209
same(
210-
"\\Nette\\PhpGenerator\\Dumper::createObject(\\TestDateTime::class, [
211-
'date' => '2016-06-22 20:52:43.123400',
212-
'timezone_type' => 3,
213-
'timezone' => 'Europe/Prague',
214-
])",
210+
<<<'XX'
211+
\Nette\PhpGenerator\Dumper::createObject(\TestDateTime::class, [
212+
'date' => '2016-06-22 20:52:43.123400',
213+
'timezone_type' => 3,
214+
'timezone' => 'Europe/Prague',
215+
])
216+
XX,
215217
$dumper->dump(new TestDateTime('2016-06-22 20:52:43.1234', new DateTimeZone('Europe/Prague'))),
216218
);

0 commit comments

Comments
 (0)