Skip to content

Commit 9233549

Browse files
minor symfony#24611 Remove some visual debt by adding type hints on final methods/classes (nicolas-grekas)
This PR was merged into the 4.0-dev branch. Discussion ---------- Remove some visual debt by adding type hints on final methods/classes | Q | A | ------------- | --- | Branch? | 4.0 | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 5eab353 Remove some visual debt by adding type hints on final methods/classes
2 parents ec0867f + 5eab353 commit 9233549

Some content is hidden

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

49 files changed

+101
-403
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
103103
$io->table(array(), $rows);
104104
}
105105

106-
private static function formatPath($path, $baseDir = null)
106+
private static function formatPath(string $path, string $baseDir = null): string
107107
{
108108
return null !== $baseDir ? preg_replace('~^'.preg_quote($baseDir, '~').'~', '.', $path) : $path;
109109
}
110110

111-
private static function formatFileSize($path)
111+
private static function formatFileSize(string $path): string
112112
{
113113
if (is_file($path)) {
114114
$size = filesize($path) ?: 0;
@@ -122,14 +122,14 @@ private static function formatFileSize($path)
122122
return Helper::formatMemory($size);
123123
}
124124

125-
private static function isExpired($date)
125+
private static function isExpired(string $date): bool
126126
{
127127
$date = \DateTime::createFromFormat('m/Y', $date);
128128

129129
return false !== $date && new \DateTime() > $date->modify('last day of this month 23:59:59');
130130
}
131131

132-
private static function getDotEnvVars()
132+
private static function getDotEnvVars(): array
133133
{
134134
$vars = array();
135135
foreach (explode(',', getenv('SYMFONY_DOTENV_VARS')) as $name) {

src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
185185
* Try to create relative symlink.
186186
*
187187
* Falling back to absolute symlink and finally hard copy.
188-
*
189-
* @param string $originDir
190-
* @param string $targetDir
191-
*
192-
* @return string
193188
*/
194-
private function relativeSymlinkWithFallback($originDir, $targetDir)
189+
private function relativeSymlinkWithFallback(string $originDir, string $targetDir): string
195190
{
196191
try {
197192
$this->symlink($originDir, $targetDir, true);
@@ -207,13 +202,8 @@ private function relativeSymlinkWithFallback($originDir, $targetDir)
207202
* Try to create absolute symlink.
208203
*
209204
* Falling back to hard copy.
210-
*
211-
* @param string $originDir
212-
* @param string $targetDir
213-
*
214-
* @return string
215205
*/
216-
private function absoluteSymlinkWithFallback($originDir, $targetDir)
206+
private function absoluteSymlinkWithFallback(string $originDir, string $targetDir): string
217207
{
218208
try {
219209
$this->symlink($originDir, $targetDir);
@@ -229,13 +219,9 @@ private function absoluteSymlinkWithFallback($originDir, $targetDir)
229219
/**
230220
* Creates symbolic link.
231221
*
232-
* @param string $originDir
233-
* @param string $targetDir
234-
* @param bool $relative
235-
*
236222
* @throws IOException if link can not be created
237223
*/
238-
private function symlink($originDir, $targetDir, $relative = false)
224+
private function symlink(string $originDir, string $targetDir, bool $relative = false)
239225
{
240226
if ($relative) {
241227
$originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir)));
@@ -248,13 +234,8 @@ private function symlink($originDir, $targetDir, $relative = false)
248234

249235
/**
250236
* Copies origin to target.
251-
*
252-
* @param string $originDir
253-
* @param string $targetDir
254-
*
255-
* @return string
256237
*/
257-
private function hardCopy($originDir, $targetDir)
238+
private function hardCopy(string $originDir, string $targetDir): string
258239
{
259240
$this->filesystem->mkdir($targetDir, 0777);
260241
// We use a custom iterator to ignore VCS files

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
117117
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
118118
}
119119

120-
private function warmupCache(InputInterface $input, OutputInterface $output, $realCacheDir, $oldCacheDir)
120+
private function warmupCache(InputInterface $input, OutputInterface $output, string $realCacheDir, string $oldCacheDir)
121121
{
122122
$io = new SymfonyStyle($input, $output);
123123

@@ -145,12 +145,7 @@ private function warmupCache(InputInterface $input, OutputInterface $output, $re
145145
$this->filesystem->rename($warmupDir, $realCacheDir);
146146
}
147147

148-
/**
149-
* @param string $warmupDir
150-
* @param string $realCacheDir
151-
* @param bool $enableOptionalWarmers
152-
*/
153-
private function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = true)
148+
private function warmup(string $warmupDir, string $realCacheDir, bool $enableOptionalWarmers = true)
154149
{
155150
// create a temporary kernel
156151
$kernel = $this->getApplication()->getKernel();

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Style\SymfonyStyle;
1919
use Symfony\Component\Console\Exception\LogicException;
20+
use Symfony\Component\DependencyInjection\ContainerBuilder;
2021
use Symfony\Component\Yaml\Yaml;
2122

2223
/**
@@ -112,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
112113
$io->writeln(Yaml::dump($config, 10));
113114
}
114115

115-
private function compileContainer()
116+
private function compileContainer(): ContainerBuilder
116117
{
117118
$kernel = clone $this->getApplication()->getKernel();
118119
$kernel->boot();
@@ -128,13 +129,11 @@ private function compileContainer()
128129
/**
129130
* Iterate over configuration until the last step of the given path.
130131
*
131-
* @param array $config A bundle configuration
132-
*
133132
* @throws LogicException If the configuration does not exist
134133
*
135134
* @return mixed
136135
*/
137-
private function getConfigForPath(array $config, $path, $alias)
136+
private function getConfigForPath(array $config, string $path, string $alias)
138137
{
139138
$steps = explode('.', $path);
140139

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
217217
$io->table($headers, $rows);
218218
}
219219

220-
private function formatState($state)
220+
private function formatState($state): string
221221
{
222222
if (self::MESSAGE_MISSING === $state) {
223223
return '<error> missing </error>';
@@ -234,7 +234,7 @@ private function formatState($state)
234234
return $state;
235235
}
236236

237-
private function formatStates(array $states)
237+
private function formatStates(array $states): string
238238
{
239239
$result = array();
240240
foreach ($states as $state) {
@@ -244,12 +244,12 @@ private function formatStates(array $states)
244244
return implode(' ', $result);
245245
}
246246

247-
private function formatId($id)
247+
private function formatId(string $id): string
248248
{
249249
return sprintf('<fg=cyan;options=bold>%s</>', $id);
250250
}
251251

252-
private function sanitizeString($string, $length = 40)
252+
private function sanitizeString(string $string, int $length = 40): string
253253
{
254254
$string = trim(preg_replace('/\s+/', ' ', $string));
255255

@@ -264,13 +264,7 @@ private function sanitizeString($string, $length = 40)
264264
return $string;
265265
}
266266

267-
/**
268-
* @param string $locale
269-
* @param array $transPaths
270-
*
271-
* @return MessageCatalogue
272-
*/
273-
private function extractMessages($locale, $transPaths)
267+
private function extractMessages(string $locale, array $transPaths): MessageCatalogue
274268
{
275269
$extractedCatalogue = new MessageCatalogue($locale);
276270
foreach ($transPaths as $path) {
@@ -283,13 +277,7 @@ private function extractMessages($locale, $transPaths)
283277
return $extractedCatalogue;
284278
}
285279

286-
/**
287-
* @param string $locale
288-
* @param array $transPaths
289-
*
290-
* @return MessageCatalogue
291-
*/
292-
private function loadCurrentMessages($locale, $transPaths)
280+
private function loadCurrentMessages(string $locale, array $transPaths): MessageCatalogue
293281
{
294282
$currentCatalogue = new MessageCatalogue($locale);
295283
foreach ($transPaths as $path) {
@@ -303,12 +291,9 @@ private function loadCurrentMessages($locale, $transPaths)
303291
}
304292

305293
/**
306-
* @param string $locale
307-
* @param array $transPaths
308-
*
309294
* @return MessageCatalogue[]
310295
*/
311-
private function loadFallbackCatalogues($locale, $transPaths)
296+
private function loadFallbackCatalogues(string $locale, array $transPaths): array
312297
{
313298
$fallbackCatalogues = array();
314299
if ($this->translator instanceof Translator || $this->translator instanceof DataCollectorTranslator || $this->translator instanceof LoggingTranslator) {

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TranslationUpdateCommand extends Command
4141
private $extractor;
4242
private $defaultLocale;
4343

44-
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, $defaultLocale)
44+
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale)
4545
{
4646
parent::__construct();
4747

@@ -242,7 +242,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
242242
$errorIo->success($resultMessage.'.');
243243
}
244244

245-
private function filterCatalogue(MessageCatalogue $catalogue, $domain)
245+
private function filterCatalogue(MessageCatalogue $catalogue, string $domain): MessageCatalogue
246246
{
247247
$filteredCatalogue = new MessageCatalogue($catalogue->getLocale());
248248

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RedirectController
3030
private $httpPort;
3131
private $httpsPort;
3232

33-
public function __construct(UrlGeneratorInterface $router = null, $httpPort = null, $httpsPort = null)
33+
public function __construct(UrlGeneratorInterface $router = null, int $httpPort = null, int $httpsPort = null)
3434
{
3535
$this->router = $router;
3636
$this->httpPort = $httpPort;
@@ -51,11 +51,9 @@ public function __construct(UrlGeneratorInterface $router = null, $httpPort = nu
5151
* @param bool $permanent Whether the redirection is permanent
5252
* @param bool|array $ignoreAttributes Whether to ignore attributes or an array of attributes to ignore
5353
*
54-
* @return Response A Response instance
55-
*
5654
* @throws HttpException In case the route name is empty
5755
*/
58-
public function redirectAction(Request $request, $route, $permanent = false, $ignoreAttributes = false)
56+
public function redirectAction(Request $request, string $route, bool $permanent = false, $ignoreAttributes = false): Response
5957
{
6058
if ('' == $route) {
6159
throw new HttpException($permanent ? 410 : 404);
@@ -89,11 +87,9 @@ public function redirectAction(Request $request, $route, $permanent = false, $ig
8987
* @param int|null $httpPort The HTTP port (null to keep the current one for the same scheme or the default configured port)
9088
* @param int|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the default configured port)
9189
*
92-
* @return Response A Response instance
93-
*
9490
* @throws HttpException In case the path is empty
9591
*/
96-
public function urlRedirectAction(Request $request, $path, $permanent = false, $scheme = null, $httpPort = null, $httpsPort = null)
92+
public function urlRedirectAction(Request $request, string $path, bool $permanent = false, string $scheme = null, int $httpPort = null, int $httpsPort = null): Response
9793
{
9894
if ('' == $path) {
9995
throw new HttpException($permanent ? 410 : 404);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ public function __construct(Environment $twig = null, EngineInterface $templatin
4040
* @param int|null $maxAge Max age for client caching
4141
* @param int|null $sharedAge Max age for shared (proxy) caching
4242
* @param bool|null $private Whether or not caching should apply for client caches only
43-
*
44-
* @return Response A Response instance
4543
*/
46-
public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null)
44+
public function templateAction(string $template, int $maxAge = null, int $sharedAge = null, bool $private = null): Response
4745
{
4846
if ($this->templating) {
4947
$response = new Response($this->templating->render($template));

src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
164164

165165
/**
166166
* Create the password question to ask the user for the password to be encoded.
167-
*
168-
* @return Question
169167
*/
170-
private function createPasswordQuestion()
168+
private function createPasswordQuestion(): Question
171169
{
172170
$passwordQuestion = new Question('Type in your password to be encoded');
173171

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
3333
private $createCacheItem;
3434
private $mergeByLifetime;
3535

36-
/**
37-
* @param string $namespace
38-
* @param int $defaultLifetime
39-
*/
40-
protected function __construct($namespace = '', $defaultLifetime = 0)
36+
protected function __construct(string $namespace = '', int $defaultLifetime = 0)
4137
{
4238
$this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).':';
4339
if (null !== $this->maxIdLength && strlen($namespace) > $this->maxIdLength - 24) {

0 commit comments

Comments
 (0)