8000 Replace more docblocks by type-hints · symfony/symfony@eab1f27 · GitHub
[go: up one dir, main page]

Skip to content

Commit eab1f27

Browse files
Replace more docblocks by type-hints
1 parent d222648 commit eab1f27

File tree

9 files changed

+100
-428
lines changed

9 files changed

+100
-428
lines changed

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,11 @@
2626
*/
2727
class ProxyDumper implements DumperInterface
2828
{
29-
/**
30-
* @var string
31-
*/
3229
private $salt;
33-
34-
/**
35-
* @var LazyLoadingValueHolderGenerator
36-
*/
3730
private $proxyGenerator;
38-
39-
/**
40-
* @var BaseGeneratorStrategy
41-
*/
4231
private $classGenerator;
4332

44-
/**
45-
* @param string $salt
46-
*/
47-
public function __construct($salt = '')
33+
public function __construct(string $salt = '')
4834
{
4935
$this->salt = $salt;
5036
$this->proxyGenerator = new LazyLoadingValueHolderGenerator();

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Lines changed: 24 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Controller;
1313

14+
use Doctrine\Common\Persistence\ManagerRegistry;
1415
use Psr\Container\ContainerInterface;
1516
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1617
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -23,10 +24,9 @@
2324
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2425
use Symfony\Component\Security\Csrf\CsrfToken;
2526
use Symfony\Component\Form\Extension\Core\Type\FormType;
26-
use Symfony\Component\Form\Form;
27-
use Symfony\Component\Form\FormBuilder;
27+
use Symfony\Component\Form\FormInterface;
28+
use Symfony\Component\Form\FormBuilderInterface;
2829
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
29-
use Doctrine\Bundle\DoctrineBundle\Registry;
3030

3131
/**
3232
* Common features needed in controllers.
@@ -42,45 +42,33 @@ trait ControllerTrait
4242
/**
4343
* Returns true if the service id is defined.
4444
*
45-
* @param string $id The service id
46-
*
47-
* @return bool true if the service id is defined, false otherwise
48-
*
4945
* @final since version 3.4
5046
*/
51-
protected function has($id)
47+
protected function has(string $id): bool
5248
{
5349
return $this->container->has($id);
5450
}
5551

5652
/**
5753
* Gets a container service by its id.
5854
*
59-
* @param string $id The service id
60-
*
6155
* @return object The service
6256
*
6357
* @final since version 3.4
6458
*/
65-
protected function get($id)
59+
protected function get(string $id)
6660
{
6761
return $this->container->get($id);
6862
}
6963

7064
/**
7165
* Generates a URL from the given parameters.
7266
*
73-
* @param string $route The name of the route
74-
* @param mixed $parameters An array of parameters
75-
* @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
76-
*
77-
* @return string The generated URL
78-
*
7967
* @see UrlGeneratorInterface
8068
*
8169
* @final since version 3.4
8270
*/
83-
protected function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
71+
protected function generateUrl(string $route, array $parameters = array(), int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
8472
{
8573
return $this->container->get('router')->generate($route, $parameters, $referenceType);
8674
}
@@ -89,14 +77,10 @@ protected function generateUrl($route, $parameters = array(), $referenceType = U
8977
* Forwards the request to another controller.
9078
*
9179
* @param string $controller The controller name (a string like BlogBundle:Post:index)
92-
* @param array $path An array of path parameters
93-
* @param array $query An array of query parameters
94-
*
95-
* @return Response A Response instance
9680
*
9781
* @final since version 3.4
9882
*/
99-
protected function forward($controller, array $path = array(), array $query = array())
83+
protected function forward(string $controller, array $path = array(), array $query = array()): Response
10084
{
10185
$request = $this->container->get('request_stack')->getCurrentRequest();
10286
$path['_forwarded'] = $request->attributes;
@@ -109,47 +93,29 @@ protected function forward($controller, array $path = array(), array $query = ar
10993
/**
11094
* Returns a RedirectResponse to the given URL.
11195
*
112-
* @param string $url The URL to redirect to
113-
* @param int $status The status code to use for the Response
114-
*
115-
* @return RedirectResponse
116-
*
11796
* @final since version 3.4
11897
*/
119-
protected function redirect($url, $status = 302)
98+
protected function redirect(string $url, int $status = 302): RedirectResponse
12099
{
121100
return new RedirectResponse($url, $status);
122101
}
123102

124103
/**
125104
* Returns a RedirectResponse to the given route with the given parameters.
126105
*
127-
* @param string $route The name of the route
128-
* @param array $parameters An array of parameters
129-
* @param int $status The status code to use for the Response
130-
*
131-
* @return RedirectResponse
132-
*
133106
* @final since version 3.4
134107
*/
135-
protected function redirectToRoute($route, array $parameters = array(), $status = 302)
108+
protected function redirectToRoute(string $route, array $parameters = array(), int $status = 302): RedirectResponse
136109
{
137110
return $this->redirect($this->generateUrl($route, $parameters), $status);
138111
}
139112

140113
/**
141114
* Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
142115
*
143-
* @param mixed $data The response data
144-
* @param int $status The status code to use for the Response
145-
* @param array $headers Array of extra headers to add
146-
* @param array $context Context to pass to serializer when using serializer component
147-
*
148-
* @return JsonResponse
149-
*
150116
* @final since version 3.4
151117
*/
152-
protected function json($data, $status = 200, $headers = array(), $context = array())
118+
protected function json($data, int $status = 200, array $headers = array(), array $context = array()): JsonResponse
153119
{
154120
if ($this->container->has('serializer')) {
155121
$json = $this->container->get('serializer')->serialize($data, 'json', array_merge(array(
@@ -165,15 +131,11 @@ protected function json($data, $status = 200, $headers = array(), $context = arr
165131
/**
166132
* Returns a BinaryFileResponse object with original or customized file name and disposition header.
167133
*
168-
* @param \SplFileInfo|string $file File object or path to file to be sent as response
169-
* @param string|null $fileName File name to be sent to response or null (will use original file name)
170-
* @param string $disposition Disposition of response ("attachment" is default, other type is "inline")
171-
*
172-
* @return BinaryFileResponse
134+
* @param \SplFileInfo|string $file File object or path to file to be sent as response
173135
*
174136
* @final since version 3.4
175137
*/
176-
protected function file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
138+
protected function file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
177139
{
178140
$response = new BinaryFileResponse($file);
179141
$response->setContentDisposition($disposition, null === $fileName ? $response->getFile()->getFilename() : $fileName);
@@ -184,14 +146,11 @@ protected function file($file, $fileName = null, $disposition = ResponseHeaderBa
184146
/**
185147
* Adds a flash message to the current session for type.
186148
*
187-
* @param string $type The type
188-
* @param string $message The message
189-
*
190149
* @throws \LogicException
191150
*
192151
* @final since version 3.4
193152
*/
194-
protected function addFlash($type, $message)
153+
protected function addFlash(string $type, string $message)
195154
{
196155
if (!$this->container->has('session')) {
197156
throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
@@ -203,16 +162,11 @@ protected function addFlash($type, $message)
203162
/**
204163
* Checks if the attributes are granted against the current authentication token and optionally supplied subject.
205164
*
206-
* @param mixed $attributes The attributes
207-
* @param mixed $subject The subject
208-
*
209-
* @return bool
210-
*
211165
* @throws \LogicException
212166
*
213167
* @final since version 3.4
214168
*/
215-
protected function isGranted($attributes, $subject = null)
169+
protected function isGranted($attributes, $subject = null): bool
216170
{
217171
if (!$this->container->has('security.authorization_checker')) {
218172
throw new \LogicException('The SecurityBundle is not registered in your application.');
@@ -225,15 +179,11 @@ protected function isGranted($attributes, $subject = null)
225179
* Throws an exception unless the attributes are granted against the current authentication token and optionally
226180
* supplied subject.
227181
*
228-
* @param mixed $attributes The attributes
229-
* @param mixed $subject The subject
230-
* @param string $message The message passed to the exception
231-
*
232182
* @throws AccessDeniedException
233183
*
234184
* @final since version 3.4
235185
*/
236-
protected function denyAccessUnlessGranted($attributes, $subject = null, $message = 'Access Denied.')
186+
protected function denyAccessUnlessGranted($attributes, $subject = null, string $message = 'Access Denied.')
237187
{
238188
if (!$this->isGranted($attributes, $subject)) {
239189
$exception = $this->createAccessDeniedException($message);
@@ -247,14 +197,9 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, $messag
247197
/**
248198
* Returns a rendered view.
249199
*
250-
* @param string $view The view name
251-
* @param array $parameters An array of parameters to pass to the view
252-
*
253-
* @return string The rendered view
254-
*
255200
* @final since version 3.4
256201
*/
257-
protected function renderView($view, array $parameters = array())
202+
protected function renderView(string $view, array $parameters = array()): string
258203
{
259204
if ($this->container->has('templating')) {
260205
return $this->container->get('templating')->render($view, $parameters);
@@ -270,15 +215,9 @@ protected function renderView($view, array $parameters = array())
270215
/**
271216
* Renders a view.
272217
*
273-
* @param string $view The view name
274-
* @param array $parameters An array of parameters to pass to the view
275-
* @param Response $response A response instance
276-
*
277-
* @return Response A Response instance
278-
*
279218
* @final since version 3.4
280219
*/
281-
protected function render($view, array $parameters = array(), Response $response = null)
220+
protected function render(string $view, array $parameters = array(), Response $response = null): Response
282221
{
283222
if ($this->container->has('templating')) {
284223
$content = $this->container->get('templating')->render($view, $parameters);
@@ -300,15 +239,9 @@ protected function render($view, array $parameters = array(), Response $response
300239
/**
301240
* Streams a view.
302241
*
303-
* @param string $view The view name
304-
* @param array $parameters An array of parameters to pass to the view
305-
* @param StreamedResponse $response A response instance
306-
*
307-
* @return StreamedResponse A StreamedResponse instance
308-
*
309242
* @final since version 3.4
310243
*/
311-
protected function stream($view, array $parameters = array(), StreamedResponse $response = null)
244+
protected function stream(string $view, array $parameters = array(), StreamedResponse $response = null): StreamedResponse
312245
{
313246
if ($this->container->has('templating')) {
314247
$templating = $this->container->get('templating');
@@ -342,14 +275,9 @@ protected function stream($view, array $parameters = array(), StreamedResponse $
342275
*
343276
* throw $this->createNotFoundException('Page not found!');
344277
*
345-
* @param string $message A message
346-
* @param \Exception|null $previous The previous exception
347-
*
348-
* @return NotFoundHttpException
349-
*
350278
* @final since version 3.4
351279
*/
352-
protected function createNotFoundException($message = 'Not Found', \Exception $previous = null)
280+
protected function createNotFoundException(string $message = 'Not Found', \Exception $previous = null): NotFoundHttpException
353281
{
354282
return new NotFoundHttpException($message, $previous);
355283
}
@@ -361,59 +289,41 @@ protected function createNotFoundException($message = 'Not Found', \Exception $p
361289
*
362290
* throw $this->createAccessDeniedException('Unable to access this page!');
363291
*
364-
* @param string $message A message
365-
* @param \Exception|null $previous The previous exception
366-
*
367-
* @return AccessDeniedException
368-
*
369292
* @final since version 3.4
370293
*/
371-
protected function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
294+
protected function createAccessDeniedException(string $message = 'Access Denied.', \Exception $previous = null): AccessDeniedException
372295
{
373296
return new AccessDeniedException($message, $previous);
374297
}
375298

376299
/**
377300
* Creates and returns a Form instance from the type of the form.
378301
*
379-
* @param string $type The fully qualified class name of the form type
380-
* @param mixed $data The initial data for the form
381-
* @param array $options Options for the form
382-
*
383-
* @return Form
384-
*
385302
* @final since version 3.4
386303
*/
387-
protected function createForm($type, $data = null, array $options = array())
304+
protected function createForm(string $type, $data = null, array $options = array()): FormInterface
388305
{
389306
return $this->container->get('form.factory')->create($type, $data, $options);
390307
}
391308

392309
/**
393310
* Creates and returns a form builder instance.
394311
*
395-
* @param mixed $data The initial data for the form
396-
* @param array $options Options for the form
397-
*
398-
* @return FormBuilder
399-
*
400312
* @final since version 3.4
401313
*/
402-
protected function createFormBuilder($data = null, array $options = array())
314+
protected function createFormBuilder($data = null, array $options = array()): FormBuilderInterface
403315
{
404316
return $this->container->get('form.factory')->createBuilder(FormType::class, $data, $options);
405317
}
406318

407319
/**
408320
* Shortcut to return the Doctrine Registry service.
409321
*
410-
* @return Registry
411-
*
412322
* @throws \LogicException If DoctrineBundle is not available
413323
*
414324
* @final since version 3.4
415325
*/
416-
protected function getDoctrine()
326+
protected function getDoctrine(): ManagerRegistry
417327
{
418328
if (!$this->container->has('doctrine')) {
419329
throw new \LogicException('The DoctrineBundle is not registered in your application.');
@@ -457,11 +367,9 @@ protected function getUser()
457367
* @param string $id The id used when generating the token
458368
* @param string $token The actual token sent with the request that should be validated
459369
*
460-
* @return bool
461-
*
462370
* @final since version 3.4
463371
*/
464-
protected function isCsrfTokenValid($id, $token)
372+
protected function isCsrfTokenValid(string $id, string $token): bool
465373
{
466374
if (!$this->container->has('security.csrf.token_manager')) {
467375
throw new \LogicException('CSRF protection is not enabled in your application.');

0 commit comments

Comments
 (0)
0