8000 minor #58566 Reduce common control flows (alexandre-daubois) · symfony/symfony@7f53a39 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f53a39

Browse files
committed
minor #58566 Reduce common control flows (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- Reduce common control flows | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Commits ------- d71b4fa Reduce common control flows
2 parents c360931 + d71b4fa commit 7f53a39

File tree

13 files changed

+24
-49
lines changed

13 files changed

+24
-49
lines changed

src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ public function testVerbosityMapping($verbosity, $level, $isHandling, array $map
6868

6969
$realOutput = $this->getMockBuilder(Output::class)->onlyMethods(['doWrite'])->getMock();
7070
$realOutput->setVerbosity($verbosity);
71-
if ($realOutput->isDebug()) {
72-
$log = "16:21:54 $levelName [app] My info message\n";
73-
} else {
74-
$log = "16:21:54 $levelName [app] My info message\n";
75-
}
71+
$log = "16:21:54 $levelName [app] My info message\n";
7672
$realOutput
7773
->expects($isHandling ? $this->once() : $this->never())
7874
->method('doWrite')

src/Symfony/Component/Console/Completion/CompletionInput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ public function bind(InputDefinition $definition): void
123123
if ($this->currentIndex >= \count($this->tokens)) {
124124
if (!isset($this->arguments[$argumentName]) || $this->definition->getArgument($argumentName)->isArray()) {
125125
$this->completionName = $argumentName;
126-
$this->completionValue = '';
127126
} else {
128127
// we've reached the end
129128
$this->completionType = self::TYPE_NONE;
130129
$this->completionName = null;
131-
$this->completionValue = '';
132130
}
131+
132+
$this->completionValue = '';
133133
}
134134
}
135135

src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ public function testContextReplacement()
151151

152152
public function testObjectCastToString()
153153
{
154-
if (method_exists($this, 'createPartialMock')) {
155-
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
156-
} else {
157-
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
158-
}
154+
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
159155
$dummy->method('__toString')->willReturn('DUMMY');
160156

161157
$this->getLogger()->warning($dummy);

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,16 +1139,15 @@ private function addNewInstance(Definition $definition, string $return = '', ?st
11391139
{
11401140
$tail = $return ? str_repeat(')', substr_count($return, '(') - substr_count($return, ')')).";\n" : '';
11411141

1142+
$arguments = [];
11421143
if (BaseServiceLocator::class === $definition->getClass() && $definition->hasTag($this->serviceLocatorTag)) {
1143-
$arguments = [];
11441144
foreach ($definition->getArgument(0) as $k => $argument) {
11451145
$arguments[$k] = $argument->getValues()[0];
11461146
}
11471147

11481148
return $return.$this->dumpValue(new ServiceLocatorArgument($arguments)).$tail;
11491149
}
11501150

1151-
$arguments = [];
11521151
foreach ($definition->getArguments() as $i => $value) {
11531152
$arguments[] = (\is_string($i) ? $i.': ' : '').$this->dumpValue($value);
11541153
}

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,16 +421,14 @@ private function initialize(): void
421421
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
422422

423423
$fieldNodes = $xpath->query(\sprintf('( descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)] )[( not(ancestor::template) or ancestor::turbo-stream )]', $formId));
424-
foreach ($fieldNodes as $node) {
425-
$this->addField($node);
426-
}
427424
} else {
428425
// do the xpath query with $this->node as the context node, to only find descendant elements
429426
// however, descendant elements with form attribute are not part of this form
430427
$fieldNodes = $xpath->query('( descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)] )[( not(ancestor::template) or ancestor::turbo-stream )]', $this->node);
431-
foreach ($fieldNodes as $node) {
432-
$this->addField($node);
433-
}
428+
}
429+
430+
foreach ($fieldNodes as $node) {
431+
$this->addField($node);
434432
}
435433

436434
if ($this->baseHref && '' !== $this->node->getAttribute('action')) {

src/Symfony/Component/Form/Extension/DataCollector/FormDataExtractor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,13 @@ public function extractSubmittedData(FormInterface $form): array
103103
continue;
104104
}
105105

106+
$errorData['trace'][] = $cause;
106107
if ($cause instanceof \Exception) {
107-
$errorData['trace'][] = $cause;
108108
$cause = $cause->getPrevious();
109109

110110
continue;
111111
}
112112

113-
$errorData['trace'][] = $cause;
114-
115113
break;
116114
}
117115

src/Symfony/Component/HttpFoundation/Tests/RequestMatcher/SchemeRequestMatcherTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ public function test(string $requestScheme, array|string $matcherScheme, bool $i
2525
$httpRequest = Request::create('');
2626
$httpsRequest = Request::create('', 'get', [], [], [], ['HTTPS' => 'on']);
2727

28+
$matcher = new SchemeRequestMatcher($matcherScheme);
2829
if ($isMatch) {
2930
if ('https' === $requestScheme) {
30-
$matcher = new SchemeRequestMatcher($matcherScheme);
3131
$this->assertFalse($matcher->matches($httpRequest));
3232
$this->assertTrue($matcher->matches($httpsRequest));
3333
} else {
34-
$matcher = new SchemeRequestMatcher($matcherScheme);
3534
$this->assertFalse($matcher->matches($httpsRequest));
3635
$this->assertTrue($matcher->matches($httpRequest));
3736
}
3837
} else {
39-
$matcher = new SchemeRequestMatcher($matcherScheme);
4038
$this->assertFalse($matcher->matches($httpRequest));
4139
$this->assertFalse($matcher->matches($httpsRequest));
4240
}

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
121121
) {
122122
if ($response->headers->has('Content-Type') && str_contains($response->headers->get('Content-Type') ?? '', 'html')) {
123123
$dumper = new HtmlDumper('php://output', $this->charset);
124-
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
125124
} else {
126125
$dumper = new CliDumper('php://output', $this->charset);
127-
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
128126
}
129127

128+
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
129+
130130
foreach ($this->data as $dump) {
131131
$this->doDump($dumper, $dump['data'], $dump['name'], $dump['file'], $dump['line'], $dump['label'] ?? '');
132132
}
@@ -235,12 +235,12 @@ public function __destruct()
235235

236236
if ($this->webMode) {
237237
$dumper = new HtmlDumper('php://output', $this->charset);
238-
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
239238
} else {
240239
$dumper = new CliDumper('php://output', $this->charset);
241-
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
242240
}
243241

242+
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
243+
244244
foreach ($this->data as $i => $dump) {
245245
$this->data[$i] = null;
246246
$this->doDump($dumper, $dump['data'], $dump['name'], $dump['file'], $dump['line'], $dump['label'] ?? '');

src/Symfony/Component/HttpKernel/Tests/Log/LoggerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ public function testContextReplacement()
129129

130130
public function testObjectCastToString()
131131
{
132-
if (method_exists($this, 'createPartialMock')) {
133-
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
134-
} else {
135-
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
136-
}
132+
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
137133
$dummy->expects($this->atLeastOnce())
138134
->method('__toString')
139135
->wi 10000 llReturn('DUMMY');

src/Symfony/Component/Messenger/Middleware/RouterContextMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public function __construct(
3030

3131
public function handle(Envelope $envelope, StackInterface $stack): Envelope
3232
{
33+
$context = $this->router->getContext();
34+
3335
if (!$envelope->last(ConsumedByWorkerStamp::class) || !$contextStamp = $envelope->last(RouterContextStamp::class)) {
34-
$context = $this->router->getContext();
3536
$envelope = $envelope->with(new RouterContextStamp(
3637
$context->getBaseUrl(),
3738
$context->getMethod(),
@@ -46,7 +47,6 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
4647
return $stack->next()->handle($envelope, $stack);
4748
}
4849

49-
$context = $this->router->getContext();
5050
$currentBaseUrl = $context->getBaseUrl();
5151
$currentMethod = $context->getMethod();
5252
$currentHost = $context->getHost();

src/Symfony/Component/Serializer/Command/DebugCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,14 @@ private function dumpSerializerDataForClass(InputInterface $input, OutputInterfa
7575
];
7676
}
7777

78+
$io->section($title);
79+
7880
if (!$rows) {
79-
$io->section($title);
8081
$io->text('No Serializer data were found for this class.');
8182

8283
return;
8384
}
8485

85-
$io->section($title);
86-
8786
$table = new Table($output);
8887
$table->setHeaders(['Property', 'Options']);
8988
$table->setRows($rows);

src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
133133
$metadata->addPropertyConstraint($property, new Type(['type' => 'scalar']));
134134
}
135135
}
136-
137-
if (!$nullable && !$hasNotBlankConstraint && !$hasNotNullConstraint) {
138-
$metadata->addPropertyConstraint($property, new NotNull());
139-
}
140136
} else {
141137
if ($hasTypeConstraint) {
142138
continue;
@@ -157,10 +153,10 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
157153
if (null !== $typeConstraint = $this->getTypeConstraint($type)) {
158154
$metadata->addPropertyConstraint($property, $typeConstraint);
159155
}
156+
}
160157

161-
if (!$nullable && !$hasNotBlankConstraint && !$hasNotNullConstraint) {
162-
$metadata->addPropertyConstraint($property, new NotNull());
163-
}
158+
if (!$nullable && !$hasNotBlankConstraint && !$hasNotNullConstraint) {
159+
$metadata->addPropertyConstraint($property, new NotNull());
164160
}
165161
}
166162

src/Symfony/Component/VarExporter/Internal/Hydrator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,16 @@ public static function getPropertyScopes($class): array
260260
continue;
261261
}
262262
$name = $property->name;
263+
$readonlyScope = null;
263264

264265
if (\ReflectionProperty::IS_PRIVATE & $flags) {
265-
$readonlyScope = null;
266266
if ($flags & \ReflectionProperty::IS_READONLY) {
267267
$readonlyScope = $class;
268268
}
269269
$propertyScopes["\0$class\0$name"] = $propertyScopes[$name] = [$class, $name, $readonlyScope, $property];
270270

271271
continue;
272272
}
273-
$readonlyScope = null;
274273
if ($flags & \ReflectionProperty::IS_READONLY) {
275274
$readonlyScope = $property->class;
276275
}

0 commit comments

Comments
 (0)
0