Skip to content

Commit

Permalink
minor #32993 Turned return type annotations of private methods into p…
Browse files Browse the repository at this point in the history
…hp return types (derrabus)

This PR was merged into the 4.4 branch.

Discussion
----------

Turned return type annotations of private methods into php return types

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

As discussed with @nicolas-grekas in symfony/symfony#30323 (comment), this PR attempts to turn `@return` annotations on private methods into return type declarations.

Commits
-------

f54ca001fe Turned return type annotations of private methods into php return types.
  • Loading branch information
nicolas-grekas committed Aug 8, 2019
2 parents e424dda + 1c8b541 commit 9ea8dc8
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 79 deletions.
2 changes: 1 addition & 1 deletion CacheWarmer/SerializerCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
*
* @return XmlFileLoader[]|YamlFileLoader[]
*/
private function extractSupportedLoaders(array $loaders)
private function extractSupportedLoaders(array $loaders): array
{
$supportedLoaders = [];

Expand Down
4 changes: 2 additions & 2 deletions CacheWarmer/TemplateFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function findAllTemplates()
*
* @return TemplateReferenceInterface[]
*/
private function findTemplatesInFolder(string $dir)
private function findTemplatesInFolder(string $dir): array
{
$templates = [];

Expand All @@ -96,7 +96,7 @@ private function findTemplatesInFolder(string $dir)
*
* @return TemplateReferenceInterface[]
*/
private function findTemplatesInBundle(BundleInterface $bundle)
private function findTemplatesInBundle(BundleInterface $bundle): array
{
$name = $bundle->getName();
$templates = array_unique(array_merge(
Expand Down
2 changes: 1 addition & 1 deletion CacheWarmer/ValidatorCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array
*
* @return XmlFileLoader[]|YamlFileLoader[]
*/
private function extractSupportedLoaders(array $loaders)
private function extractSupportedLoaders(array $loaders): array
{
$supportedLoaders = [];

Expand Down
5 changes: 1 addition & 4 deletions Console/Descriptor/MarkdownDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,7 @@ protected function describeCallable($callable, array $options = [])
throw new \InvalidArgumentException('Callable is not describable.');
}

/**
* @return string
*/
private function formatRouterConfig(array $array)
private function formatRouterConfig(array $array): string
{
if (!$array) {
return 'NONE';
Expand Down
2 changes: 1 addition & 1 deletion Console/Descriptor/XmlDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private function getContainerDefinitionDocument(Definition $definition, string $
/**
* @return \DOMNode[]
*/
private function getArgumentNodes(array $arguments, \DOMDocument $dom)
private function getArgumentNodes(array $arguments, \DOMDocument $dom): array
{
$nodes = [];

Expand Down
5 changes: 1 addition & 4 deletions Tests/Command/RouterMatchCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ public function testWithNotMatchPath()
$this->assertStringContainsString('None of the routes match the path "/test"', $tester->getDisplay());
}

/**
* @return CommandTester
*/
private function createCommandTester()
private function createCommandTester(): CommandTester
{
$application = new Application($this->getKernel());
$application->add(new RouterMatchCommand($this->getRouter()));
Expand Down
5 changes: 1 addition & 4 deletions Tests/Command/TranslationDebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ protected function tearDown()
$this->fs->remove($this->translationDir);
}

/**
* @return CommandTester
*/
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = [])
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
{
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
->disableOriginalConstructor()
Expand Down
5 changes: 1 addition & 4 deletions Tests/Command/TranslationUpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ protected function tearDown()
$this->fs->remove($this->translationDir);
}

/**
* @return CommandTester
*/
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
{
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
->disableOriginalConstructor()
Expand Down
5 changes: 1 addition & 4 deletions Tests/Command/XliffLintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ public function testLintFilesFromBundleDirectory()
$this->assertStringContainsString('[OK] All 0 XLIFF files contain valid syntax', trim($tester->getDisplay()));
}

/**
* @return CommandTester
*/
private function createCommandTester($application = null)
private function createCommandTester($application = null): CommandTester
{
if (!$application) {
$application = new BaseApplication();
Expand Down
10 changes: 2 additions & 8 deletions Tests/Command/YamlLintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ public function testLintFilesFromBundleDirectory()
$this->assertStringContainsString('[OK] All 0 YAML files contain valid syntax', trim($tester->getDisplay()));
}

/**
* @return string Path to the new file
*/
private function createFile($content)
private function createFile($content): string
{
$filename = tempnam(sys_get_temp_dir().'/yml-lint-test', 'sf-');
file_put_contents($filename, $content);
Expand All @@ -122,10 +119,7 @@ private function createFile($content)
return $filename;
}

/**
* @return CommandTester
*/
private function createCommandTester($application = null)
private function createCommandTester($application = null): CommandTester
{
if (!$application) {
$application = new BaseApplication();
Expand Down
7 changes: 1 addition & 6 deletions Tests/Controller/ControllerTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ public function testGetUserWithEmptyContainer()
$controller->getUser();
}

/**
* @param $token
*
* @return Container
*/
private function getContainerWithTokenStorage($token = null)
private function getContainerWithTokenStorage($token = null): Container
{
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage')->getMock();
$tokenStorage
Expand Down
5 changes: 1 addition & 4 deletions Tests/Functional/ConfigDebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ public function testDumpWithPrefixedEnv()
$this->assertStringContainsString("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'", $tester->getDisplay());
}

/**
* @return CommandTester
*/
private function createCommandTester()
private function createCommandTester(): CommandTester
{
$command = $this->application->find('debug:config');

Expand Down
5 changes: 1 addition & 4 deletions Tests/Functional/ConfigDumpReferenceCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public function testDumpAtPathXml()
$this->assertStringContainsString('[ERROR] The "path" option is only available for the "yaml" format.', $tester->getDisplay());
}

/**
* @return CommandTester
*/
private function createCommandTester()
private function createCommandTester(): CommandTester
{
$command = $this->application->find('config:dump-reference');

Expand Down
6 changes: 2 additions & 4 deletions Tests/Routing/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
Expand Down Expand Up @@ -501,10 +502,7 @@ public function getNonStringValues()
return [[null], [false], [true], [new \stdClass()], [['foo', 'bar']], [[[]]]];
}

/**
* @return \Symfony\Component\DependencyInjection\Container
*/
private function getServiceContainer(RouteCollection $routes)
private function getServiceContainer(RouteCollection $routes): Container
{
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();

Expand Down
41 changes: 13 additions & 28 deletions Tests/Templating/TimedPhpEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
use Symfony\Bundle\FrameworkBundle\Templating\TimedPhpEngine;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;
use Symfony\Component\Templating\Loader\Loader;
use Symfony\Component\Templating\Storage\StringStorage;
use Symfony\Component\Templating\TemplateNameParserInterface;

/**
* @group legacy
Expand Down Expand Up @@ -42,18 +47,12 @@ public function testThatRenderLogsTime()
$engine->render('index.php');
}

/**
* @return Container
*/
private function getContainer()
private function getContainer(): Container
{
return $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')->getMock();
}

/**
* @return \Symfony\Component\Templating\TemplateNameParserInterface
*/
private function getTemplateNameParser()
private function getTemplateNameParser(): TemplateNameParserInterface
{
$templateReference = $this->getMockBuilder('Symfony\Component\Templating\TemplateReferenceInterface')->getMock();
$templateNameParser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock();
Expand All @@ -64,32 +63,24 @@ private function getTemplateNameParser()
return $templateNameParser;
}

/**
* @return GlobalVariables
*/
private function getGlobalVariables()
private function getGlobalVariables(): GlobalVariables
{
return $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables')
->disableOriginalConstructor()
->getMock();
}

/**
* @return \Symfony\Component\Templating\Storage\StringStorage
*/
private function getStorage()
private function getStorage(): StringStorage
{
return $this->getMockBuilder('Symfony\Component\Templating\Storage\StringStorage')
->disableOriginalConstructor()
->getMockForAbstractClass();
}

/**
* @param \Symfony\Component\Templating\Storage\StringStorage $storage
*
* @return \Symfony\Component\Templating\Loader\Loader
* @param StringStorage $storage
*/
private function getLoader($storage)
private function getLoader($storage): Loader
{
$loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
$loader->expects($this->once())
Expand All @@ -99,20 +90,14 @@ private function getLoader($storage)
return $loader;
}

/**
* @return \Symfony\Component\Stopwatch\StopwatchEvent
*/
private function getStopwatchEvent()
private function getStopwatchEvent(): StopwatchEvent
{
return $this->getMockBuilder('Symfony\Component\Stopwatch\StopwatchEvent')
->disableOriginalConstructor()
->getMock();
}

/**
* @return \Symfony\Component\Stopwatch\Stopwatch
*/
private function getStopwatch()
private function getStopwatch(): Stopwatch
{
return $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')->getMock();
}
Expand Down

0 comments on commit 9ea8dc8

Please sign in to comment.