Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 394ae7f

Browse filesBrowse files
minor #49348 Add PHP types to private methods and functions (wouterj)
This PR was merged into the 6.3 branch. Discussion ---------- Add PHP types to private methods and functions | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Ref #47551, continues #49342 | License | MIT | Doc PR | - This PR adds real PHP types to private, internal or final (excluding ``@final``) methods based on Psalm's type inference. Many more return types are missing still, but let's do them in other contributions. This change can result in BC breaks in multiple ways, so we should carefully review the changes: * A method may wrongly be considered "safe" by Psalter. If the method is unsafe (e.g. ``@final``, but not yet real `final`), we should instead add a PHPdoc return type (see #49349) * Psalm may not infer the correct set of return types. If an unexpected type is returned, this will result in a PHP error. Commits ------- 384c9a6 Add PHP types to private methods and functions
2 parents 69b2149 + 384c9a6 commit 394ae7f
Copy full SHA for 394ae7f

File tree

Expand file treeCollapse file tree

70 files changed

+294
-342
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

70 files changed

+294
-342
lines changed

‎.github/expected-missing-return-types.diff

Copy file name to clipboardExpand all lines: .github/expected-missing-return-types.diff
+49-71Lines changed: 49 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ index 18f7ba0fb0..7f37cb6d9b 100644
252252
+ protected function start(string $name): TraceableAdapterEvent
253253
{
254254
$this->calls[] = $event = new TraceableAdapterEvent();
255+
diff --git a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
256+
index 2ee96e9b37..f49ed24f68 100644
257+
--- a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
258+
+++ b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
259+
@@ -81,5 +81,5 @@ trait FilesystemCommonTrait
260+
* @return bool
261+
*/
262+
- protected function doUnlink(string $file)
263+
+ protected function doUnlink(string $file): bool
264+
{
265+
return @unlink($file);
255266
diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php b/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php
256267
index 7cda0bc7d8..b2311826f4 100644
257268
--- a/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php
@@ -350,7 +361,7 @@ index e3ca1d49c4..526d350484 100644
350361
+ public function locate(string $name, string $currentPath = null, bool $first = true): string|array;
351362
}
352363
diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php
353-
index 30034e55a5..d6a57be190 100644
364+
index 3f06f0c38c..ce0fd1d76d 100644
354365
--- a/src/Symfony/Component/Config/Loader/FileLoader.php
355366
+++ b/src/Symfony/Component/Config/Loader/FileLoader.php
356367
@@ -67,5 +67,5 @@ abstract class FileLoader extends Loader
@@ -552,7 +563,7 @@ index 2762cdf05c..737334268a 100644
552563
+ public function getName(): string;
553564
}
554565
diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php
555-
index 893b3192e9..94822ed191 100644
566+
index 7d31794be3..1c311aded2 100644
556567
--- a/src/Symfony/Component/Console/Helper/Table.php
557568
+++ b/src/Symfony/Component/Console/Helper/Table.php
558569
@@ -193,5 +193,5 @@ class Table
@@ -609,6 +620,17 @@ index 74d885d131..3de806a60e 100644
609620
+ protected function getErrorOutput(): OutputInterface
610621
{
611622
if (!$this->output instanceof ConsoleOutputInterface) {
623+
diff --git a/src/Symfony/Component/CssSelector/Parser/Reader.php b/src/Symfony/Component/CssSelector/Parser/Reader.php
624+
index 7f6ae7a600..d79db02567 100644
625+
--- a/src/Symfony/Component/CssSelector/Parser/Reader.php
626+
+++ b/src/Symfony/Component/CssSelector/Parser/Reader.php
627+
@@ -57,5 +57,5 @@ class Reader
628+
* @return int|false
629+
*/
630+
- public function getOffset(string $string): int|bool
631+
+ public function getOffset(string $string): int|false
632+
{
633+
$position = strpos($this->source, $string, $this->position);
612634
diff --git a/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php b/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php
613635
index b4e982c457..521a9531f8 100644
614636
--- a/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php
@@ -853,30 +875,8 @@ index 479aeef880..272954c082 100644
853875
- public function getFunctions();
854876
+ public function getFunctions(): array;
855877
}
856-
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/ArrayNode.php b/src/Symfony/Component/ExpressionLanguage/Node/ArrayNode.php
857-
index e1a3169b00..e5dc5bfe21 100644
858-
--- a/src/Symfony/Component/ExpressionLanguage/Node/ArrayNode.php
859-
+++ b/src/Symfony/Component/ExpressionLanguage/Node/ArrayNode.php
860-
@@ -45,5 +45,5 @@ class ArrayNode extends Node
861-
}
862-
863-
- public function evaluate(array $functions, array $values)
864-
+ public function evaluate(array $functions, array $values): mixed
865-
{
866-
$result = [];
867-
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php
868-
index 0b31c66ded..e798ef8f2f 100644
869-
--- a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php
870-
+++ b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php
871-
@@ -93,5 +93,5 @@ class BinaryNode extends Node
872-
}
873-
874-
- public function evaluate(array $functions, array $values)
875-
+ public function evaluate(array $functions, array $values): mixed
876-
{
877-
$operator = $this->attributes['operator'];
878878
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php b/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php
879-
index ba78a2848e..f805b5655e 100644
879+
index fec02abaae..7d02544275 100644
880880
--- a/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php
881881
+++ b/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php
882882
@@ -41,5 +41,5 @@ class ConditionalNode extends Node
@@ -886,17 +886,6 @@ index ba78a2848e..f805b5655e 100644
886886
+ public function evaluate(array $functions, array $values): mixed
887887
{
888888
if ($this->nodes['expr1']->evaluate($functions, $values)) {
889-
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/ConstantNode.php b/src/Symfony/Component/ExpressionLanguage/Node/ConstantNode.php
890-
index 869e350dc9..f1c1ad5bd3 100644
891-
--- a/src/Symfony/Component/ExpressionLanguage/Node/ConstantNode.php
892-
+++ b/src/Symfony/Component/ExpressionLanguage/Node/ConstantNode.php
893-
@@ -39,5 +39,5 @@ class ConstantNode extends Node
894-
}
895-
896-
- public function evaluate(array $functions, array $values)
897-
+ public function evaluate(array $functions, array $values): mixed
898-
{
899-
return $this->attributes['value'];
900889
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php b/src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php
901890
index 06078da305..cc11697293 100644
902891
--- a/src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php
@@ -915,28 +904,6 @@ index 06078da305..cc11697293 100644
915904
+ public function toArray(): array
916905
{
917906
$array = [];
918-
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php
919-
index e9b10c3295..7aefd9bb84 100644
920-
--- a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php
921-
+++ b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php
922-
@@ -66,5 +66,5 @@ class GetAttrNode extends Node
923-
}
924-
925-
- public function evaluate(array $functions, array $values)
926-
+ public function evaluate(array $functions, array $values): mixed
927-
{
928-
switch ($this->attributes['type']) {
929-
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/NameNode.php b/src/Symfony/Component/ExpressionLanguage/Node/NameNode.php
930-
index e017e967a1..8ea5bcf28c 100644
931-
--- a/src/Symfony/Component/ExpressionLanguage/Node/NameNode.php
932-
+++ b/src/Symfony/Component/ExpressionLanguage/Node/NameNode.php
933-
@@ -34,5 +34,5 @@ class NameNode extends Node
934-
}
935-
936-
- public function evaluate(array $functions, array $values)
937-
+ public function evaluate(array $functions, array $values): mixed
938-
{
939-
return $values[$this->attributes['name']];
940907
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/Node.php b/src/Symfony/Component/ExpressionLanguage/Node/Node.php
941908
index eb5046c9bf..ef142d3787 100644
942909
--- a/src/Symfony/Component/ExpressionLanguage/Node/Node.php
@@ -969,17 +936,6 @@ index eb5046c9bf..ef142d3787 100644
969936
+ protected function isHash(array $value): bool
970937
{
971938
$expectedKey = 0;
972-
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/NullCoalesceNode.php b/src/Symfony/Component/ExpressionLanguage/Node/NullCoalesceNode.php
973-
index 3e59ef8676..b6371df241 100644
974-
--- a/src/Symfony/Component/ExpressionLanguage/Node/NullCoalesceNode.php
975-
+++ b/src/Symfony/Component/ExpressionLanguage/Node/NullCoalesceNode.php
976-
@@ -37,5 +37,5 @@ class NullCoalesceNode extends Node
977-
}
978-
979-
- public function evaluate(array $functions, array $values)
980-
+ public function evaluate(array $functions, array $values): mixed
981-
{
982-
if ($this->nodes['expr1'] instanceof GetAttrNode) {
983939
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php b/src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php
984940
index 9e30d848eb..ee82938d8a 100644
985941
--- a/src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php
@@ -1392,6 +1348,17 @@ index d894b7e74c..f0d6d32f0a 100644
13921348
+ protected function guessRoute(Request $request, string|object|array $controller): string
13931349
{
13941350
return 'n/a';
1351+
diff --git a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php
1352+
index fcb100859f..8bf3ef09d5 100644
1353+
--- a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php
1354+
+++ b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php
1355+
@@ -53,5 +53,5 @@ class FileLinkFormatter
1356+
* @return string|false
1357+
*/
1358+
- public function format(string $file, int $line): string|bool
1359+
+ public function format(string $file, int $line): string|false
1360+
{
1361+
if ($fmt = $this->getFileLinkFormat()) {
13951362
diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php
13961363
index 3650d1700d..055b57fc77 100644
13971364
--- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php
@@ -1978,6 +1945,17 @@ index 69ac3d6ec4..d96c7d038d 100644
19781945
+ public function getMessageKey(): string
19791946
{
19801947
return 'An authentication exception occurred.';
1948+
diff --git a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
1949+
index b4ffa1dcd4..dd3c58a6d0 100644
1950+
--- a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
1951+
+++ b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
1952+
@@ -98,5 +98,5 @@ class InMemoryUserProvider implements UserProviderInterface
1953+
* @return InMemoryUser change return type on 7.0
1954+
*/
1955+
- private function getUser(string $username): UserInterface
1956+
+ private function getUser(string $username): InMemoryUser
1957+
{
1958+
if (!isset($this->users[strtolower($username)])) {
19811959
diff --git a/src/Symfony/Component/Security/Core/User/UserProviderInterface.php b/src/Symfony/Component/Security/Core/User/UserProviderInterface.php
19821960
index ec90d413fa..9f1401aa91 100644
19831961
--- a/src/Symfony/Component/Security/Core/User/UserProviderInterface.php
@@ -2286,7 +2264,7 @@ index 1749dd78d2..250b46bdd3 100644
22862264
{
22872265
return $this->class;
22882266
diff --git a/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php b/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php
2289-
index edac8395df..f3998dc4dd 100644
2267+
index 1b2457707f..5811aa8106 100644
22902268
--- a/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php
22912269
+++ b/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php
22922270
@@ -295,5 +295,5 @@ abstract class ConstraintValidatorTestCase extends TestCase
@@ -3192,7 +3170,7 @@ index dba7c3dcfb..dce66ea6b9 100644
31923170
{
31933171
return $this->places;
31943172
diff --git a/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php b/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php
3195-
index cfe1c09b6e..de62f635f9 100644
3173+
index 06340a61bb..2654d15b9a 100644
31963174
--- a/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php
31973175
+++ b/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php
31983176
@@ -80,5 +80,5 @@ class ParentTestService

‎src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private function addTaggedServices(ContainerBuilder $container): array
124124
return $listenerRefs;
125125
}
126126

127-
private function getEventManagerDef(ContainerBuilder $container, string $name)
127+
private function getEventManagerDef(ContainerBuilder $container, string $name): Definition
128128
{
129129
if (!isset($this->eventManagers[$name])) {
130130
$this->eventManagers[$name] = $container->getDefinition(sprintf($this->managerTemplate, $name));

‎src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function validate(mixed $entity, Constraint $constraint)
193193
->addViolation();
194194
}
195195

196-
private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class, mixed $value)
196+
private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class, mixed $value): string
197197
{
198198
if (!\is_object($value) || $value instanceof \DateTimeInterface) {
199199
return $this->formatValue($value, self::PRETTY_DATE);

‎src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private function displayDeprecations($groups, $configuration)
354354
}
355355
}
356356

357-
private static function getPhpUnitErrorHandler()
357+
private static function getPhpUnitErrorHandler(): callable
358358
{
359359
if (!$eh = self::$errorHandler) {
360360
if (class_exists(Handler::class)) {

‎src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php
+17-53Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,15 @@ private function __construct(array $thresholds = [], $regex = '', $verboseOutput
154154
$this->logFile = $logFile;
155155
}
156156

157-
/**
158-
* @return bool
159-
*/
160-
public function isEnabled()
157+
public function isEnabled(): bool
161158
{
162159
return $this->enabled;
163160
}
164161

165162
/**
166163
* @param DeprecationGroup[] $deprecationGroups
167-
*
168-
* @return bool
169164
*/
170-
public function tolerates(array $deprecationGroups)
165+
public function tolerates(array $deprecationGroups): bool
171166
{
172167
$grandTotal = 0;
173168

@@ -229,10 +224,7 @@ public function toleratesForGroup(string $groupName, array $deprecationGroups):
229224
return true;
230225
}
231226

232-
/**
233-
* @return bool
234-
*/
235-
public function isBaselineDeprecation(Deprecation $deprecation)
227+
public function isBaselineDeprecation(Deprecation $deprecation): bool
236228
{
237229
if ($deprecation->isLegacy()) {
238230
return false;
@@ -260,20 +252,17 @@ public function isBaselineDeprecation(Deprecation $deprecation)
260252
return $result;
261253
}
262254

263-
/**
264-
* @return bool
265-
*/
266-
public function isGeneratingBaseline()
255+
public function isGeneratingBaseline(): bool
267256
{
268257
return $this->generateBaseline;
269258
}
270259

271-
public function getBaselineFile()
260+
public function getBaselineFile(): string
272261
{
273262
return $this->baselineFile;
274263
}
275264

276-
public function writeBaseline()
265+
public function writeBaseline(): void
277266
{
278267
$map = [];
279268
foreach ($this->baselineDeprecations as $location => $messages) {
@@ -290,47 +279,37 @@ public function writeBaseline()
290279

291280
/**
292281
* @param string $message
293-
*
294-
* @return bool
295282
*/
296-
public function shouldDisplayStackTrace($message)
283+
public function shouldDisplayStackTrace($message): bool
297284
{
298285
return '' !== $this->regex && preg_match($this->regex, $message);
299286
}
300287

301-
/**
302-
* @return bool
303-
*/
304-
public function isInRegexMode()
288+
public function isInRegexMode(): bool
305289
{
306290
return '' !== $this->regex;
307291
}
308292

309-
/**
310-
* @return bool
311-
*/
312-
public function verboseOutput($group)
293+
public function verboseOutput($group): bool
313294
{
314295
return $this->verboseOutput[$group];
315296
}
316297

317-
public function shouldWriteToLogFile()
298+
public function shouldWriteToLogFile(): bool
318299
{
319300
return null !== $this->logFile;
320301
}
321302

322-
public function getLogFile()
303+
public function getLogFile(): ?string
323304
{
324305
return $this->logFile;
325306
}
326307

327308
/**
328309
* @param string $serializedConfiguration an encoded string, for instance
329310
* max[total]=1234&max[indirect]=42
330-
*
331-
* @return self
332311
*/
333-
public static function fromUrlEncodedString($serializedConfiguration)
312+
public static function fromUrlEncodedString($serializedConfiguration): self
334313
{
335314
parse_str($serializedConfiguration, $normalizedConfiguration);
336315
foreach (array_keys($normalizedConfiguration) as $key) {
@@ -376,29 +355,20 @@ public static function fromUrlEncodedString($serializedConfiguration)
376355
);
377356
}
378357

379-
/**
380-
* @return self
381-
*/
382-
public static function inDisabledMode()
358+
public static function inDisabledMode(): self
383359
{
384360
$configuration = new self();
385361
$configuration->enabled = false;
386362

387363
return $configuration;
388364
}
389365

390-
/**
391-
* @return self
392-
*/
393-
public static function inStrictMode()
366+
public static function inStrictMode(): self
394367
{
395368
return new self(['total' => 0]);
396369
}
397370

398-
/**
399-
* @return self
400-
*/
401-
public static function inWeakMode()
371+
public static function inWeakMode(): self
402372
{
403373
$verboseOutput = [];
404374
foreach (['unsilenced', 'direct', 'indirect', 'self', 'other'] as $group) {
@@ -408,18 +378,12 @@ public static function inWeakMode()
408378
return new self([], '', $verboseOutput);
409379
}
410380

411-
/**
412-
* @return self
413-
*/
414-
public static function fromNumber($upperBound)
381+
public static function fromNumber($upperBound): self
415382
{
416383
return new self(['total' => $upperBound]);
417384
}
418385

419-
/**
420-
* @return self
421-
*/
422-
public static function fromRegex($regex)
386+
public static function fromRegex($regex): self
423387
{
424388
return new self([], $regex);
425389
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.