Skip to content

Commit 24f29fa

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Replace switch statement with match expression
2 parents a2f22b8 + caa1ad7 commit 24f29fa

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

bundles/prepend_extension.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,16 @@ in case a specific other bundle is not registered::
6565
// disable AcmeGoodbyeBundle in bundles
6666
$config = ['use_acme_goodbye' => false];
6767
foreach ($container->getExtensions() as $name => $extension) {
68-
switch ($name) {
69-
case 'acme_something':
70-
case 'acme_other':
71-
// set use_acme_goodbye to false in the config of
72-
// acme_something and acme_other
73-
//
74-
// note that if the user manually configured
75-
// use_acme_goodbye to true in config/services.yaml
76-
// then the setting would in the end be true and not false
77-
$container->prependExtensionConfig($name, $config);
78-
break;
79-
}
68+
match ($name) {
69+
// set use_acme_goodbye to false in the config of
70+
// acme_something and acme_other
71+
//
72+
// note that if the user manually configured
73+
// use_acme_goodbye to true in config/services.yaml
74+
// then the setting would in the end be true and not false
75+
'acme_something', 'acme_other' => $container->prependExtensionConfig($name, $config),
76+
default => null
77+
};
8078
}
8179
}
8280

form/type_guesser.rst

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,21 @@ With this knowledge, you can implement the ``guessType()`` method of the
105105
}
106106

107107
// otherwise, base the type on the @var annotation
108-
switch ($annotations['var']) {
109-
case 'string':
110-
// there is a high confidence that the type is text when
111-
// @var string is used
112-
return new TypeGuess(TextType::class, [], Guess::HIGH_CONFIDENCE);
113-
114-
case 'int':
115-
case 'integer':
116-
// integers can also be the id of an entity or a checkbox (0 or 1)
117-
return new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE);
118-
119-
case 'float':
120-
case 'double':
121-
case 'real':
122-
return new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE);
123-
124-
case 'boolean':
125-
case 'bool':
126-
return new TypeGuess(CheckboxType::class, [], Guess::HIGH_CONFIDENCE);
127-
128-
default:
129-
// there is a very low confidence that this one is correct
130-
return new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE);
131-
}
108+
return match($annotations['var']) {
109+
// there is a high confidence that the type is text when
110+
// @var string is used
111+
'string' => new TypeGuess(TextType::class, [], Guess::HIGH_CONFIDENCE),
112+
113+
// integers can also be the id of an entity or a checkbox (0 or 1)
114+
'int', 'integer' => new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE),
115+
116+
'float', 'double', 'real' => new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE),
117+
118+
'boolean', 'bool' => new TypeGuess(CheckboxType::class, [], Guess::HIGH_CONFIDENCE),
119+
120+
// there is a very low confidence that this one is correct
121+
default => new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE)
122+
};
132123
}
133124

134125
protected function readPhpDocAnnotations(string $class, string $property): array

security/voters.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,11 @@ would look like this::
153153
/** @var Post $post */
154154
$post = $subject;
155155

156-
switch ($attribute) {
157-
case self::VIEW:
158-
return $this->canView($post, $user);
159-
case self::EDIT:
160-
return $this->canEdit($post, $user);
161-
}
162-
163-
throw new \LogicException('This code should not be reached!');
156+
return match($attribute) {
157+
self::VIEW => $this->canView($post, $user),
158+
self::EDIT => $this->canEdit($post, $user),
159+
default => throw new \LogicException('This code should not be reached!')
160+
};
164161
}
165162

166163
private function canView(Post $post, User $user): bool

0 commit comments

Comments
 (0)