Skip to content

Commit 9218515

Browse files
minor #33770 Add types to constructors and private/final/internal methods (Batch III) (derrabus)
This PR was squashed before being merged into the 4.4 branch (closes #33770). Discussion ---------- Add types to constructors and private/final/internal methods (Batch III) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #32179, #33228 | License | MIT | Doc PR | N/A Followup to #33709, this time with: * Validator * VarDumper * Workflow * Yaml * all bridges * all bundles That should be the final batch. 😃 Commits ------- 6493902287 Add types to constructors and private/final/internal methods (Batch III)
2 parents 988eb5f + 16b236b commit 9218515

File tree

9 files changed

+30
-32
lines changed

9 files changed

+30
-32
lines changed

Constraints/AbstractComparisonValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function validate($value, Constraint $constraint)
9191
}
9292
}
9393

94-
private function getPropertyAccessor()
94+
private function getPropertyAccessor(): PropertyAccessorInterface
9595
{
9696
if (null === $this->propertyAccessor) {
9797
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();

Constraints/ExpressionValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function validate($value, Constraint $constraint)
6565
}
6666
}
6767

68-
private function getExpressionLanguage()
68+
private function getExpressionLanguage(): ExpressionLanguage
6969
{
7070
if (null === $this->expressionLanguage) {
7171
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {

Constraints/FileValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private static function moreDecimalsThan(string $double, int $numberOfDecimals):
208208
* Convert the limit to the smallest possible number
209209
* (i.e. try "MB", then "kB", then "bytes").
210210
*/
211-
private function factorizeSizes(int $size, int $limit, bool $binaryFormat)
211+
private function factorizeSizes(int $size, int $limit, bool $binaryFormat): array
212212
{
213213
if ($binaryFormat) {
214214
$coef = self::MIB_BYTES;

Constraints/IbanValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function validate($value, Constraint $constraint)
225225
}
226226
}
227227

228-
private static function toBigInt($string)
228+
private static function toBigInt(string $string): string
229229
{
230230
$chars = str_split($string);
231231
$bigInt = '';
@@ -245,7 +245,7 @@ private static function toBigInt($string)
245245
return $bigInt;
246246
}
247247

248-
private static function bigModulo97($bigInt)
248+
private static function bigModulo97(string $bigInt): int
249249
{
250250
$parts = str_split($bigInt, 7);
251251
$rest = 0;

Context/ExecutionContext.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintViolation;
1717
use Symfony\Component\Validator\ConstraintViolationList;
18+
use Symfony\Component\Validator\ConstraintViolationListInterface;
1819
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
1920
use Symfony\Component\Validator\Mapping\MemberMetadata;
2021
use Symfony\Component\Validator\Mapping\MetadataInterface;
2122
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
2223
use Symfony\Component\Validator\Util\PropertyPath;
2324
use Symfony\Component\Validator\Validator\ValidatorInterface;
2425
use Symfony\Component\Validator\Violation\ConstraintViolationBuilder;
26+
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
2527
use Symfony\Contracts\Translation\TranslatorInterface;
2628

2729
/**
@@ -200,7 +202,7 @@ public function addViolation($message, array $parameters = [])
200202
/**
201203
* {@inheritdoc}
202204
*/
203-
public function buildViolation($message, array $parameters = [])
205+
public function buildViolation($message, array $parameters = []): ConstraintViolationBuilderInterface
204206
{
205207
return new ConstraintViolationBuilder(
206208
$this->violations,
@@ -218,15 +220,15 @@ public function buildViolation($message, array $parameters = [])
218220
/**
219221
* {@inheritdoc}
220222
*/
221-
public function getViolations()
223+
public function getViolations(): ConstraintViolationListInterface
222224
{
223225
return $this->violations;
224226
}
225227

226228
/**
227229
* {@inheritdoc}
228230
*/
229-
public function getValidator()
231+
public function getValidator(): ValidatorInterface
230232
{
231233
return $this->validator;
232234
}
@@ -258,44 +260,44 @@ public function getObject()
258260
/**
259261
* {@inheritdoc}
260262
*/
261-
public function getMetadata()
263+
public function getMetadata(): ?MetadataInterface
262264
{
263265
return $this->metadata;
264266
}
265267

266268
/**
267269
* {@inheritdoc}
268270
*/
269-
public function getGroup()
271+
public function getGroup(): ?string
270272
{
271273
return $this->group;
272274
}
273275

274-
public function getConstraint()
276+
public function getConstraint(): ?Constraint
275277
{
276278
return $this->constraint;
277279
}
278280

279281
/**
280282
* {@inheritdoc}
281283
*/
282-
public function getClassName()
284+
public function getClassName(): ?string
283285
{
284286
return $this->metadata instanceof MemberMetadata || $this->metadata instanceof ClassMetadataInterface ? $this->metadata->getClassName() : null;
285287
}
286288

287289
/**
288290
* {@inheritdoc}
289291
*/
290-
public function getPropertyName()
292+
public function getPropertyName(): ?string
291293
{
292294
return $this->metadata instanceof PropertyMetadataInterface ? $this->metadata->getPropertyName() : null;
293295
}
294296

295297
/**
296298
* {@inheritdoc}
297299
*/
298-
public function getPropertyPath($subPath = '')
300+
public function getPropertyPath($subPath = ''): string
299301
{
300302
return PropertyPath::append($this->propertyPath, $subPath);
301303
}
@@ -315,7 +317,7 @@ public function markGroupAsValidated($cacheKey, $groupHash)
315317
/**
316318
* {@inheritdoc}
317319
*/
318-
public function isGroupValidated($cacheKey, $groupHash)
320+
public function isGroupValidated($cacheKey, $groupHash): bool
319321
{
320322
return isset($this->validatedObjects[$cacheKey][$groupHash]);
321323
}
@@ -331,7 +333,7 @@ public function markConstraintAsValidated($cacheKey, $constraintHash)
331333
/**
332334
* {@inheritdoc}
333335
*/
334-
public function isConstraintValidated($cacheKey, $constraintHash)
336+
public function isConstraintValidated($cacheKey, $constraintHash): bool
335337
{
336338
return isset($this->validatedConstraints[$cacheKey.':'.$constraintHash]);
337339
}
@@ -347,7 +349,7 @@ public function markObjectAsInitialized($cacheKey)
347349
/**
348350
* {@inheritdoc}
349351
*/
350-
public function isObjectInitialized($cacheKey)
352+
public function isObjectInitialized($cacheKey): bool
351353
{
352354
return isset($this->initializedObjects[$cacheKey]);
353355
}

Mapping/Cache/DoctrineCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function setCache(Cache $cache)
4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function has($class)
43+
public function has($class): bool
4444
{
4545
return $this->cache->contains($class);
4646
}

Test/ConstraintValidatorTestCase.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,22 @@ class ConstraintViolationAssertion
236236
private $constraint;
237237
private $cause;
238238

239-
public function __construct(ExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = [])
239+
public function __construct(ExecutionContextInterface $context, string $message, Constraint $constraint = null, array $assertions = [])
240240
{
241241
$this->context = $context;
242242
$this->message = $message;
243243
$this->constraint = $constraint;
244244
$this->assertions = $assertions;
245245
}
246246

247-
public function atPath($path)
247+
public function atPath(string $path)
248248
{
249249
$this->propertyPath = $path;
250250

251251
return $this;
252252
}
253253

254-
public function setParameter($key, $value)
254+
public function setParameter(string $key, $value)
255255
{
256256
$this->parameters[$key] = $value;
257257

@@ -279,14 +279,14 @@ public function setInvalidValue($invalidValue)
279279
return $this;
280280
}
281281

282-
public function setPlural($number)
282+
public function setPlural(int $number)
283283
{
284284
$this->plural = $number;
285285

286286
return $this;
287287
}
288288

289-
public function setCode($code)
289+
public function setCode(string $code)
290290
{
291291
$this->code = $code;
292292

@@ -300,7 +300,7 @@ public function setCause($cause)
300300
return $this;
301301
}
302302

303-
public function buildNextViolation($message)
303+
public function buildNextViolation(string $message): self
304304
{
305305
$assertions = $this->assertions;
306306
$assertions[] = $this;
@@ -328,7 +328,7 @@ public function assertRaised()
328328
}
329329
}
330330

331-
private function getViolation()
331+
private function getViolation(): ConstraintViolation
332332
{
333333
return new ConstraintViolation(
334334
$this->message,

Util/LegacyTranslatorProxy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ public function setLocale($locale)
5757
/**
5858
* {@inheritdoc}
5959
*/
60-
public function getLocale()
60+
public function getLocale(): string
6161
{
6262
return $this->translator->getLocale();
6363
}
6464

6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function trans($id, array $parameters = [], $domain = null, $locale = null)
68+
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
6969
{
7070
return $this->translator->trans($id, $parameters, $domain, $locale);
7171
}
7272

7373
/**
7474
* {@inheritdoc}
7575
*/
76-
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
76+
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null): string
7777
{
7878
return $this->translator->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
7979
}

Validation.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ final class Validation
2525
*
2626
* If you want to configure the validator, use
2727
* {@link createValidatorBuilder()} instead.
28-
*
29-
* @return ValidatorInterface The new validator
3028
*/
3129
public static function createValidator(): ValidatorInterface
3230
{
@@ -35,8 +33,6 @@ public static function createValidator(): ValidatorInterface
3533

3634
/**
3735
* Creates a configurable builder for validator objects.
38-
*
39-
* @return ValidatorBuilderInterface The new builder
4036
*/
4137
public static function createValidatorBuilder(): ValidatorBuilder
4238
{

0 commit comments

Comments
 (0)