Skip to content

Commit

Permalink
minor #19830 Code enhancement and cleanup (yceruto)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.7 branch (closes #19830).

Discussion
----------

Code enhancement and cleanup

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

Commits
-------

325da3c Code enhancement and cleanup
  • Loading branch information
nicolas-grekas committed Sep 6, 2016
2 parents 053d67b + 325da3c commit 39905fd
Show file tree
Hide file tree
Showing 41 changed files with 70 additions and 59 deletions.
Expand Up @@ -336,7 +336,7 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
$memcacheClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%'.$this->getObjectManagerElementName('cache.memcache.class').'%';
$memcacheInstanceClass = !empty($cacheDriver['instance_class']) ? $cacheDriver['instance_class'] : '%'.$this->getObjectManagerElementName('cache.memcache_instance.class').'%';
$memcacheHost = !empty($cacheDriver['host']) ? $cacheDriver['host'] : '%'.$this->getObjectManagerElementName('cache.memcache_host').'%';
$memcachePort = !empty($cacheDriver['port']) || (isset($cacheDriver['port']) && $cacheDriver['port'] === 0) ? $cacheDriver['port'] : '%'.$this->getObjectManagerElementName('cache.memcache_port').'%';
$memcachePort = !empty($cacheDriver['port']) || (isset($cacheDriver['port']) && $cacheDriver['port'] === 0) ? $cacheDriver['port'] : '%'.$this->getObjectManagerElementName('cache.memcache_port').'%';
$cacheDef = new Definition($memcacheClass);
$memcacheInstance = new Definition($memcacheInstanceClass);
$memcacheInstance->addMethodCall('connect', array(
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bridge/Twig/Command/DebugCommand.php
Expand Up @@ -140,7 +140,6 @@ private function getMetadata($type, $entity)
return;
}
if ($type === 'functions' || $type === 'filters') {
$args = array();
$cb = $entity->getCallable();
if (is_null($cb)) {
return;
Expand Down
Expand Up @@ -85,7 +85,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
}

$files = array();
if (is_file($filename)) {
$files = array($filename);
} elseif (is_dir($filename)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
Expand Up @@ -52,6 +52,8 @@ public function __construct($handler)
* @param string $uri A URI
* @param array $options An array of options
*
* @return string|null The Response content or null when the Response is streamed
*
* @see FragmentHandler::render()
*/
public function renderUri($uri, array $options = array())
Expand Down
Expand Up @@ -108,8 +108,6 @@ public function onKernelResponse(FilterResponseEvent $event)

/**
* Injects the web debug toolbar into the given Response.
*
* @param Response $response A Response instance
*/
protected function injectToolbar(Response $response, Request $request)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Tests/CookieTest.php
Expand Up @@ -178,7 +178,7 @@ public function testIsExpired()
}

/**
* @expectedException UnexpectedValueException
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage The cookie expiration time "string" is not valid.
*/
public function testConstructException()
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -569,6 +569,8 @@ public function getSynopsis($short = false)
* Add a command usage example.
*
* @param string $usage The usage, it'll be prefixed with the command name
*
* @return Command The current instance
*/
public function addUsage($usage)
{
Expand Down
Expand Up @@ -98,7 +98,7 @@ protected function describeCommand(Command $command, array $options = array())
.'* Description: '.($command->getDescription() ?: '<none>')."\n"
.'* Usage:'."\n\n"
.array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
return $carry .= ' * `'.$usage.'`'."\n";
return $carry.' * `'.$usage.'`'."\n";
})
);

Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Console/Helper/ProgressHelper.php
Expand Up @@ -371,8 +371,6 @@ private function generate($finish = false)
}

if (isset($this->formatVars['bar'])) {
$completeBars = 0;

if ($this->max > 0) {
$completeBars = floor($percent * $this->barWidth);
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Console/Helper/QuestionHelper.php
Expand Up @@ -200,6 +200,7 @@ protected function writeError(OutputInterface $output, \Exception $error)
*
* @param OutputInterface $output
* @param Question $question
* @param resource $inputStream
*
* @return string
*/
Expand Down Expand Up @@ -316,7 +317,8 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
/**
* Gets a hidden response from user.
*
* @param OutputInterface $output An Output instance
* @param OutputInterface $output An Output instance
* @param resource $inputStream The handler resource
*
* @return string The answer
*
Expand Down
7 changes: 0 additions & 7 deletions src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php
Expand Up @@ -107,13 +107,6 @@ public function testIteration()
}
}

/**
* Create a generic mock for the helper interface. Optionally check for a call to setHelperSet with a specific
* helperset instance.
*
* @param string $name
* @param HelperSet $helperset allows a mock to verify a particular helperset set is being added to the Helper
*/
private function getGenericMockHelper($name, HelperSet $helperset = null)
{
$mock_helper = $this->getMock('\Symfony\Component\Console\Helper\HelperInterface');
Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/CssSelector/XPath/Translator.php
Expand Up @@ -68,9 +68,6 @@ class Translator implements TranslatorInterface
*/
private $attributeMatchingTranslators = array();

/**
* Constructor.
*/
public function __construct(ParserInterface $parser = null)
{
$this->mainParser = $parser ?: new Parser();
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -349,10 +349,12 @@ private function reRegister($prev)
/**
* Handles errors by filtering then logging them according to the configured bit fields.
*
* @param int $type One of the E_* constants
* @param int $type One of the E_* constants
* @param string $message
* @param string $file
* @param int $line
* @param array $context
* @param array $backtrace
*
* @return bool Returns false when no handling happens so that the PHP engine can handle the error itself
*
Expand Down
Expand Up @@ -39,7 +39,7 @@ public function __construct(ServiceReferenceGraphNode $sourceNode, ServiceRefere
/**
* Returns the value of the edge.
*
* @return ServiceReferenceGraphNode
* @return string
*/
public function getValue()
{
Expand Down
Expand Up @@ -169,7 +169,7 @@ public function testAddServiceInvalidServiceId()

/**
* @dataProvider provideInvalidFactories
* @expectedException Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Cannot dump definition
*/
public function testInvalidFactories($factory)
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/ExpressionLanguage/TokenStream.php
Expand Up @@ -60,6 +60,10 @@ public function next()

/**
* Tests a token.
*
* @param array|int $type The type to test
* @param string|null $value The token value
* @param string|null $message The syntax error message
*/
public function expect($type, $value = null, $message = null)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -285,6 +285,8 @@ public function rename($origin, $target, $overwrite = false)
*
* @param string $filename Path to the file
*
* @return bool
*
* @throws IOException When windows path is longer than 258 characters
*/
private function isReadable($filename)
Expand Down
13 changes: 7 additions & 6 deletions src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php
Expand Up @@ -183,12 +183,13 @@ public function getValuesForChoices(array $choices)
/**
* Flattens an array into the given output variables.
*
* @param array $choices The array to flatten
* @param callable $value The callable for generating choice values
* @param array $choicesByValues The flattened choices indexed by the
* corresponding values
* @param array $keysByValues The original keys indexed by the
* corresponding values
* @param array $choices The array to flatten
* @param callable $value The callable for generating choice values
* @param array $choicesByValues The flattened choices indexed by the
* corresponding values
* @param array $keysByValues The original keys indexed by the
* corresponding values
* @param array $structuredValues The values indexed by the original keys
*
* @internal Must not be used by user-land code
*/
Expand Down
13 changes: 7 additions & 6 deletions src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php
Expand Up @@ -153,12 +153,13 @@ public function getValuesForChoices(array $choices)
/**
* Flattens and flips an array into the given output variable.
*
* @param array $choices The array to flatten
* @param callable $value The callable for generating choice values
* @param array $choicesByValues The flattened choices indexed by the
* corresponding values
* @param array $keysByValues The original keys indexed by the
* corresponding values
* @param array $choices The array to flatten
* @param callable $value The callable for generating choice values
* @param array $choicesByValues The flattened choices indexed by the
* corresponding values
* @param array $keysByValues The original keys indexed by the
* corresponding values
* @param array $structuredValues The values indexed by the original keys
*
* @internal Must not be used by user-land code
*/
Expand Down
Expand Up @@ -178,8 +178,6 @@ protected function getIntlDateFormatter($ignoreTimezone = false)
/**
* Checks if the pattern contains only a date.
*
* @param string $pattern The input pattern
*
* @return bool
*/
protected function isPatternDateOnly()
Expand Down
Expand Up @@ -23,14 +23,8 @@
*/
class FormDataExtractor implements FormDataExtractorInterface
{
/**
* @var ValueExporter
*/
private $valueExporter;

/**
* Constructs a new data extractor.
*/
public function __construct(ValueExporter $valueExporter = null)
{
$this->valueExporter = $valueExporter ?: new ValueExporter();
Expand Down
Expand Up @@ -2040,7 +2040,7 @@ public function getOptionsWithPlaceholderAndEmptyValue()
'An empty string empty_value is used if placeholder is also an empty string when required [maintains BC]' => array(false, false, true, '', '', ''),
'A non-empty string empty_value is used if placeholder is an empty string when required [maintains BC]' => array(false, false, true, '', 'bar', 'bar'),
'A non-empty string placeholder takes precedence over an empty_value set to false when required' => array(false, false, true, 'foo', false, 'foo'),
'A non-empty string placeholder takes precedence over a not set empty_value' => array(false, false, true, 'foo', null, 'foo'),
'A non-empty string placeholder takes precedence over a not set empty_value when required' => array(false, false, true, 'foo', null, 'foo'),
'A non-empty string placeholder takes precedence over an empty string empty_value when required' => array(false, false, true, 'foo', '', 'foo'),
'A non-empty string placeholder takes precedence over a non-empty string empty_value when required' => array(false, false, true, 'foo', 'bar', 'foo'),
// single expanded, not required
Expand Down
13 changes: 12 additions & 1 deletion src/Symfony/Component/HttpFoundation/JsonResponse.php
Expand Up @@ -50,7 +50,18 @@ public function __construct($data = null, $status = 200, $headers = array())
}

/**
* {@inheritdoc}
* Factory method for chainability.
*
* Example:
*
* return JsonResponse::create($data, 200)
* ->setSharedMaxAge(300);
*
* @param mixed $data The json response data
* @param int $status The response status code
* @param array $headers An array of response headers
*
* @return JsonResponse
*/
public static function create($data = null, $status = 200, $headers = array())
{
Expand Down
Expand Up @@ -72,6 +72,8 @@ public function all();

/**
* Sets all flash messages.
*
* @param array $messages
*/
public function setAll(array $messages);

Expand Down
Expand Up @@ -214,6 +214,8 @@ protected function getMongo()
* Return an instance of a MongoDate or \MongoDB\BSON\UTCDateTime
*
* @param int $seconds An integer representing UTC seconds since Jan 1 1970. Defaults to now.
*
* @return \MongoDate|\MongoDB\BSON\UTCDateTime
*/
private function createDateTime($seconds = null)
{
Expand Down
Expand Up @@ -35,6 +35,7 @@ public function __construct(ContainerInterface $container, $debug = false, Reque
/**
* Adds a service as a fragment renderer.
*
* @param string $name The service name
* @param string $renderer The render service id
*/
public function addRendererService($name, $renderer)
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpKernel/Profiler/Profiler.php
Expand Up @@ -78,7 +78,7 @@ public function enable()
*
* @param Response $response A Response instance
*
* @return Profile A Profile instance
* @return Profile|false A Profile instance
*/
public function loadProfileFromResponse(Response $response)
{
Expand Down Expand Up @@ -149,7 +149,7 @@ public function export(Profile $profile)
*
* @param string $data A data string as exported by the export() method
*
* @return Profile A Profile instance
* @return Profile|false A Profile instance
*/
public function import($data)
{
Expand Down
Expand Up @@ -21,7 +21,7 @@
class ValidateRequestListenerTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException
* @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException
*/
public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
Expand Up @@ -272,7 +272,7 @@ public function testVerifyRequestStackPushPopDuringHandle()
}

/**
* @expectedException Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*/
public function testInconsistentClientIpsOnMasterRequests()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/UriSigner.php
Expand Up @@ -98,7 +98,7 @@ private function buildUrl(array $url, array $params = array())
$host = isset($url['host']) ? $url['host'] : '';
$port = isset($url['port']) ? ':'.$url['port'] : '';
$user = isset($url['user']) ? $url['user'] : '';
$pass = isset($url['pass']) ? ':'.$url['pass'] : '';
$pass = isset($url['pass']) ? ':'.$url['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($url['path']) ? $url['path'] : '';
$query = isset($url['query']) && $url['query'] ? '?'.$url['query'] : '';
Expand Down
Expand Up @@ -564,7 +564,7 @@ public function setTimeZoneId($timeZoneId)
try {
$this->dateTimeZone = new \DateTimeZone($timeZoneId);
if ('GMT' !== $timeZoneId && $this->dateTimeZone->getName() !== $timeZoneId) {
$timeZoneId = $timeZone = $this->getTimeZoneId();
$timeZone = $this->getTimeZoneId();
}
} catch (\Exception $e) {
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
Expand Down
Expand Up @@ -42,6 +42,7 @@ class LanguageBundle extends LanguageDataProvider implements LanguageBundleInter
* @param string $path
* @param BundleEntryReaderInterface $reader
* @param LocaleDataProvider $localeProvider
* @param ScriptDataProvider $scriptProvider
*/
public function __construct($path, BundleEntryReaderInterface $reader, LocaleDataProvider $localeProvider, ScriptDataProvider $scriptProvider)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Tests/ProcessTest.php
Expand Up @@ -943,7 +943,7 @@ public function provideMethodsThatNeedARunningProcess()

/**
* @dataProvider provideMethodsThatNeedATerminatedProcess
* @expectedException Symfony\Component\Process\Exception\LogicException
* @expectedException \Symfony\Component\Process\Exception\LogicException
* @expectedExceptionMessage Process must be terminated before calling
*/
public function testMethodsThatNeedATerminatedProcess($method)
Expand Down
Expand Up @@ -101,7 +101,7 @@ public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenti
}

/**
* @expectedException Symfony\Component\Security\Core\Exception\AuthenticationException
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
* @expectedExceptionMessage Authentication failed.
*/
public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExceptionThrownAuthenticationManagerImplementation()
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Templating/PhpEngine.php
Expand Up @@ -142,6 +142,7 @@ protected function evaluate(Storage $template, array $parameters = array())
throw new \InvalidArgumentException('Invalid parameter (view)');
}

// the view variable is exposed to the require file below
$view = $this;
if ($this->evalTemplate instanceof FileStorage) {
extract($this->evalParameters, EXTR_SKIP);
Expand Down
Expand Up @@ -108,7 +108,7 @@ public function getCollectedMessages()
* @param string|null $locale
* @param string|null $domain
* @param string $id
* @param string $trans
* @param string $translation
*/
private function collectMessage($locale, $domain, $id, $translation)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/MoFileDumper.php
Expand Up @@ -26,7 +26,7 @@ class MoFileDumper extends FileDumper
*/
public function format(MessageCatalogue $messages, $domain = 'messages')
{
$output = $sources = $targets = $sourceOffsets = $targetOffsets = '';
$sources = $targets = $sourceOffsets = $targetOffsets = '';
$offsets = array();
$size = 0;

Expand Down

0 comments on commit 39905fd

Please sign in to comment.