Skip to content

Commit d71f1fc

Browse files
committed
add type declarations where possible
1 parent 9d8d5a8 commit d71f1fc

File tree

75 files changed

+276
-629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+276
-629
lines changed

Context/Context.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ final class Context
2323
private $attributes = array();
2424
private $version;
2525
private $groups;
26-
private $maxDepth;
2726
private $isMaxDepthEnabled;
2827
private $serializeNull;
2928

@@ -56,20 +55,14 @@ public function getAttributes(): array
5655
return $this->attributes;
5756
}
5857

59-
/**
60-
* Sets the normalization version.
61-
*/
6258
public function setVersion(string $version): self
6359
{
6460
$this->version = $version;
6561

6662
return $this;
6763
}
6864

69-
/**
70-
* @return string|int|null
71-
*/
72-
public function getVersion()
65+
public function getVersion(): ?string
7366
{
7467
return $this->version;
7568
}
@@ -125,7 +118,7 @@ public function setGroups(array $groups = null): self
125118
return $this;
126119
}
127120

128-
public function enableMaxDepth()
121+
public function enableMaxDepth(): self
129122
{
130123
$this->isMaxDepthEnabled = true;
131124

@@ -173,7 +166,7 @@ public function getExclusionStrategies(): array
173166
*
174167
* Notice: This method only applies to the JMS serializer adapter.
175168
*/
176-
public function addExclusionStrategy(ExclusionStrategyInterface $exclusionStrategy)
169+
public function addExclusionStrategy(ExclusionStrategyInterface $exclusionStrategy): void
177170
{
178171
$this->exclusionStrategies[] = $exclusionStrategy;
179172
}

Controller/ControllerTrait.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,25 @@ protected function getViewHandler()
4040
}
4141

4242
/**
43-
* @param int $statusCode
44-
*
4543
* @return View
4644
*/
47-
protected function view($data = null, $statusCode = null, array $headers = [])
45+
protected function view($data = null, ?int $statusCode = null, array $headers = [])
4846
{
4947
return View::create($data, $statusCode, $headers);
5048
}
5149

5250
/**
53-
* @param string $url
54-
* @param int $statusCode
55-
*
5651
* @return View
5752
*/
58-
protected function redirectView($url, $statusCode = Response::HTTP_FOUND, array $headers = [])
53+
protected function redirectView(string $url, int $statusCode = Response::HTTP_FOUND, array $headers = [])
5954
{
6055
return View::createRedirect($url, $statusCode, $headers);
6156
}
6257

6358
/**
64-
* @param string $route
65-
* @param int $statusCode
66-
*
6759
* @return View
6860
*/
69-
protected function routeRedirectView($route, array $parameters = [], $statusCode = Response::HTTP_CREATED, array $headers = [])
61+
protected function routeRedirectView(string $route, array $parameters = [], int $statusCode = Response::HTTP_CREATED, array $headers = [])
7062
{
7163
return View::createRouteRedirect($route, $parameters, $statusCode, $headers);
7264
}

Controller/ExceptionController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpFoundation\Response;
1919
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
20-
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
2120

2221
/**
2322
* Custom ExceptionController that uses the view layer and supports HTTP response status code mapping.
@@ -38,12 +37,9 @@ public function __construct(
3837
$this->showException = $showException;
3938
}
4039

41-
/**
42-
* @param \Throwable $exception
43-
*/
44-
public function showAction(Request $request, $exception, DebugLoggerInterface $logger = null)
40+
public function showAction(Request $request, \Throwable $exception): Response
4541
{
46-
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
42+
$this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
4743

4844
$view = new View($exception, $this->getStatusCode($exception), $exception instanceof HttpExceptionInterface ? $exception->getHeaders() : []);
4945

Decoder/ContainerDecoderProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct(ContainerInterface $container, array $decoders)
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function supports($format)
38+
public function supports(string $format): bool
3939
{
4040
return isset($this->decoders[$format]);
4141
}
4242

4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function getDecoder($format)
46+
public function getDecoder(string $format): DecoderInterface
4747
{
4848
if (!$this->supports($format)) {
4949
throw new \InvalidArgumentException(sprintf("Format '%s' is not supported by ContainerDecoderProvider.", $format));

Decoder/DecoderInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ interface DecoderInterface
2121
/**
2222
* Decodes a string into PHP data.
2323
*
24-
* @param string $data
25-
*
2624
* @return mixed False in case the content could not be decoded
2725
*/
28-
public function decode($data);
26+
public function decode(string $data);
2927
}

Decoder/DecoderProviderInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ interface DecoderProviderInterface
2121
/**
2222
* Checks if a certain format is supported.
2323
*
24-
* @param string $format
25-
*
2624
* @return bool
2725
*/
28-
public function supports($format);
26+
public function supports(string $format);
2927

3028
/**
3129
* Provides decoders, possibly lazily.
3230
*
33-
* @param string $format
34-
*
3531
* @return DecoderInterface
3632
*/
37-
public function getDecoder($format);
33+
public function getDecoder(string $format);
3834
}

Decoder/JsonDecoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class JsonDecoder implements DecoderInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function decode($data)
24+
public function decode(string $data)
2525
{
2626
return @json_decode($data, true);
2727
}

Decoder/JsonToFormDecoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class JsonToFormDecoder implements DecoderInterface
2121
/**
2222
* Makes data decoded from JSON application/x-www-form-encoded compliant.
2323
*/
24-
private function xWwwFormEncodedLike(array &$data)
24+
private function xWwwFormEncodedLike(array &$data): void
2525
{
2626
foreach ($data as $key => &$value) {
2727
if (is_array($value)) {
@@ -43,7 +43,7 @@ private function xWwwFormEncodedLike(array &$data)
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function decode($data)
46+
public function decode(string $data)
4747
{
4848
$decodedData = @json_decode($data, true);
4949
if ($decodedData) {

Decoder/XmlDecoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct()
3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function decode($data)
36+
public function decode(string $data)
3737
{
3838
try {
3939
return $this->encoder->decode($data, 'xml');

DependencyInjection/Compiler/ConfigurationCheckPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
final class ConfigurationCheckPass implements CompilerPassInterface
2727
{
28-
public function process(ContainerBuilder $container)
28+
public function process(ContainerBuilder $container): void
2929
{
3030
if ($container->has('fos_rest.converter.request_body') && !($container->has('sensio_framework_extra.converter.listener') || $container->has(ParamConverterListener::class))) {
3131
throw new \RuntimeException('You need to enable the parameter converter listeners in SensioFrameworkExtraBundle when using the FOSRestBundle RequestBodyParamConverter');

DependencyInjection/Compiler/FormatListenerRulesPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
final class FormatListenerRulesPass implements CompilerPassInterface
2626
{
27-
public function process(ContainerBuilder $container)
27+
public function process(ContainerBuilder $container): void
2828
{
2929
if (!$container->hasDefinition('fos_rest.format_listener')) {
3030
return;
@@ -57,7 +57,7 @@ public function process(ContainerBuilder $container)
5757
$container->setParameter('fos_rest.format_listener.rules', null);
5858
}
5959

60-
private function addRule(array $rule, ContainerBuilder $container)
60+
private function addRule(array $rule, ContainerBuilder $container): void
6161
{
6262
$matcher = $this->createRequestMatcher(
6363
$container,
@@ -76,7 +76,7 @@ private function addRule(array $rule, ContainerBuilder $container)
7676
->addMethodCall('add', [$matcher, $rule]);
7777
}
7878

79-
private function createRequestMatcher(ContainerBuilder $container, $path = null, $host = null, $methods = null, array $attributes = array())
79+
private function createRequestMatcher(ContainerBuilder $container, ?string $path = null, ?string $host = null, ?array $methods = null, array $attributes = array()): Reference
8080
{
8181
$arguments = [$path, $host, $methods, null, $attributes];
8282
$serialized = serialize($arguments);

DependencyInjection/Compiler/HandlerRegistryDecorationPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
class HandlerRegistryDecorationPass implements CompilerPassInterface
3333
{
34-
public function process(ContainerBuilder $container)
34+
public function process(ContainerBuilder $container): void
3535
{
3636
if (!$container->has('fos_rest.serializer.jms_handler_registry')) {
3737
return;

DependencyInjection/Compiler/JMSFormErrorHandlerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
final class JMSFormErrorHandlerPass implements CompilerPassInterface
2828
{
29-
public function process(ContainerBuilder $container)
29+
public function process(ContainerBuilder $container): void
3030
{
3131
if (!$container->has('jms_serializer.form_error_handler')) {
3232
return;

DependencyInjection/Compiler/JMSHandlersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
final class JMSHandlersPass implements CompilerPassInterface
2626
{
27-
public function process(ContainerBuilder $container)
27+
public function process(ContainerBuilder $container): void
2828
{
2929
if ($container->has('jms_serializer.handler_registry')) {
3030
// the public alias prevents the handler registry definition from being removed

DependencyInjection/Compiler/SerializerConfigurationPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
final class SerializerConfigurationPass implements CompilerPassInterface
2828
{
29-
public function process(ContainerBuilder $container)
29+
public function process(ContainerBuilder $container): void
3030
{
3131
if ($container->has('fos_rest.serializer')) {
3232
$class = $container->getParameterBag()->resolveValue(

DependencyInjection/Configuration.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
*/
3232
final class Configuration implements ConfigurationInterface
3333
{
34-
/**
35-
* Default debug mode value.
36-
*
37-
* @var bool
38-
*/
3934
private $debug;
4035

4136
public function __construct(bool $debug)
@@ -188,7 +183,7 @@ public function getConfigTreeBuilder(): TreeBuilder
188183
return $treeBuilder;
189184
}
190185

191-
private function addViewSection(ArrayNodeDefinition $rootNode)
186+
private function addViewSection(ArrayNodeDefinition $rootNode): void
192187
{
193188
$rootNode
194189
->children()
@@ -274,7 +269,7 @@ private function addViewSection(ArrayNodeDefinition $rootNode)
274269
->end();
275270
}
276271

277-
private function addBodyListenerSection(ArrayNodeDefinition $rootNode)
272+
private function addBodyListenerSection(ArrayNodeDefinition $rootNode): void
278273
{
279274
$decodersDefaultValue = ['json' => 'fos_rest.decoder.json'];
280275
if (class_exists(XmlEncoder::class)) {
@@ -315,7 +310,7 @@ private function addBodyListenerSection(ArrayNodeDefinition $rootNode)
315310
->end();
316311
}
317312

318-
private function addFormatListenerSection(ArrayNodeDefinition $rootNode)
313+
private function addFormatListenerSection(ArrayNodeDefinition $rootNode): void
319314
{
320315
$rootNode
321316
->children()
@@ -369,7 +364,7 @@ private function addFormatListenerSection(ArrayNodeDefinition $rootNode)
369364
->end();
370365
}
371366

372-
private function addVersioningSection(ArrayNodeDefinition $rootNode)
367+
private function addVersioningSection(ArrayNodeDefinition $rootNode): void
373368
{
374369
$rootNode
375370
->children()
@@ -419,7 +414,7 @@ private function addVersioningSection(ArrayNodeDefinition $rootNode)
419414
->end();
420415
}
421416

422-
private function addExceptionSection(ArrayNodeDefinition $rootNode)
417+
private function addExceptionSection(ArrayNodeDefinition $rootNode): void
423418
{
424419
$rootNode
425420
->children()
@@ -486,7 +481,7 @@ private function addExceptionSection(ArrayNodeDefinition $rootNode)
486481
->end();
487482
}
488483

489-
private function testExceptionExists(string $exception)
484+
private function testExceptionExists(string $exception): void
490485
{
491486
if (!is_subclass_of($exception, \Exception::class) && !is_a($exception, \Exception::class, true)) {
492487
throw new InvalidConfigurationException(sprintf('FOSRestBundle exception mapper: Could not load class "%s" or the class does not extend from "%s". Most probably this is a configuration problem.', $exception, \Exception::class));

0 commit comments

Comments
 (0)