From f885b9b4655b13bdbfdcc1f489cc917a3972da77 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 3 Mar 2015 11:27:01 +0100 Subject: [PATCH 01/10] Test with local components instead of waiting for the subtree-splitter when possible --- .gitignore | 2 ++ .travis.sh | 25 +++++++++++++++++++++++++ .travis.yml | 3 ++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .travis.sh diff --git a/.gitignore b/.gitignore index fc673fa663..418cb5f976 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ phpunit.xml composer.lock composer.phar autoload.php +package*.tar +packages.json /vendor/ diff --git a/.travis.sh b/.travis.sh new file mode 100644 index 0000000000..9eeecbeeb8 --- /dev/null +++ b/.travis.sh @@ -0,0 +1,25 @@ +branch=$1 +if [ -z "$branch" ]; then + echo 'Usage: branch dir1 dir2 ... dirN' + exit 1 +fi +shift +components=$* +if [ -z "$components" ]; then + echo 'Usage: branch dir1 dir2 ... dirN' + exit 1 +fi +echo '{"packages": {' > packages.json +components=$( + for c in $components; do + sed -i ':a;N;$!ba;s#^{\n\(\s*\)\("name"\)#{\n\1"repositories": \[{ "type": "composer", "url": "file://'$(pwd)'/" }\],\n\1\2#' $c/composer.json + n=$(php -r '$n=json_decode(file_get_contents("'$c'/composer.json"));echo $n->name;') + echo '"'$n'": {"'$branch'.x-dev": ' >> packages.json + cat $c/composer.json >> packages.json + echo '"version": "'$branch.x-dev'",\n "dist": {"type": "tar", "url": "file://'$(pwd)/$c'/package'$branch'.tar"}\n}},' >> packages.json + echo $c + done; +) +sed -i ':a;N;$!ba;s/\n}\n"/,\n "/g' packages.json +sed -i ':a;N;$!ba;s/}},$/\n}}\n}}/' packages.json +echo "$components" | parallel --gnu "cd {}; tar -cf package$branch.tar --exclude='package*.tar' *" diff --git a/.travis.yml b/.travis.yml index 6c70c3c307..06fc091ab5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,9 +40,10 @@ before_install: install: - if [ "$deps" = "no" ]; then composer --prefer-source install; fi; + - components=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -printf '%h\n') + - if [ "$deps" != "no" ]; then sh .travis.sh $TRAVIS_BRANCH $components; fi; script: - - components=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -printf '%h\n') - if [ "$deps" = "no" ]; then echo "$components" | parallel --gnu --keep-order 'echo -e "\\nRunning {} tests"; phpunit --exclude-group tty,benchmark,intl-data {} || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; - if [ "$deps" = "no" ]; then echo -e "\\nRunning tests requiring tty"; phpunit --group tty || (echo -e "\\e[41mKO\\e[0m tty group" && $(exit 1)); fi; - if [ "$deps" = "high" ]; then echo "$components" | parallel --gnu --keep-order -j25% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source update; phpunit --exclude-group tty,benchmark,intl-data,legacy || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; From 88627058c9eab927f10ecd328b0cecbc3403e956 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 7 Mar 2015 13:18:29 +0100 Subject: [PATCH 02/10] [2.3] Remove most refs uses --- .../Doctrine/DataCollector/DoctrineDataCollector.php | 8 +++++--- .../TwigBundle/DependencyInjection/TwigExtension.php | 6 +++--- .../Component/Console/Helper/FormatterHelper.php | 12 +++++++----- .../DependencyInjection/ContainerBuilder.php | 4 +--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index 89137d1055..b4a2acd4e6 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -117,8 +117,10 @@ class DoctrineDataCollector extends DataCollector private function sanitizeQuery($connectionName, $query) { $query['explainable'] = true; - $query['params'] = (array) $query['params']; - foreach ($query['params'] as $j => &$param) { + if (!is_array($query['params'])) { + $query['params'] = array($query['params']); + } + foreach ($query['params'] as $j => $param) { if (isset($query['types'][$j])) { // Transform the param according to the type $type = $query['types'][$j]; @@ -131,7 +133,7 @@ class DoctrineDataCollector extends DataCollector } } - list($param, $explainable) = $this->sanitizeParam($param); + list($query['params'][$j], $explainable) = $this->sanitizeParam($param); if (!$explainable) { $query['explainable'] = false; } diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index ff367ca161..9b6f806f04 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -36,13 +36,13 @@ class TwigExtension extends Extension $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('twig.xml'); - foreach ($configs as &$config) { + foreach ($configs as $key => $config) { if (isset($config['globals'])) { foreach ($config['globals'] as $name => $value) { if (is_array($value) && isset($value['key'])) { - $config['globals'][$name] = array( + $configs[$key]['globals'][$name] = array( 'key' => $name, - 'value' => $config['globals'][$name], + 'value' => $value, ); } } diff --git a/src/Symfony/Component/Console/Helper/FormatterHelper.php b/src/Symfony/Component/Console/Helper/FormatterHelper.php index b94294345e..ac736f982e 100644 --- a/src/Symfony/Component/Console/Helper/FormatterHelper.php +++ b/src/Symfony/Component/Console/Helper/FormatterHelper.php @@ -45,7 +45,9 @@ class FormatterHelper extends Helper */ public function formatBlock($messages, $style, $large = false) { - $messages = (array) $messages; + if (!is_array($messages)) { + $messages = array($messages); + } $len = 0; $lines = array(); @@ -56,15 +58,15 @@ class FormatterHelper extends Helper } $messages = $large ? array(str_repeat(' ', $len)) : array(); - foreach ($lines as $line) { - $messages[] = $line.str_repeat(' ', $len - $this->strlen($line)); + for ($i = 0; isset($lines[$i]); ++$i) { + $messages[] = $lines[$i].str_repeat(' ', $len - $this->strlen($lines[$i])); } if ($large) { $messages[] = str_repeat(' ', $len); } - foreach ($messages as &$message) { - $message = sprintf('<%s>%s', $style, $message, $style); + for ($i = 0; isset($messages[$i]); ++$i) { + $messages[$i] = sprintf('<%s>%s', $style, $messages[$i], $style); } return implode("\n", $messages); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 40b4eb51df..87b6118798 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -997,9 +997,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface public function resolveServices($value) { if (is_array($value)) { - foreach ($value as &$v) { - $v = $this->resolveServices($v); - } + $value = array_map(array($this, 'resolveServices'), $value); } elseif ($value instanceof Reference) { $value = $this->get((string) $value, $value->getInvalidBehavior()); } elseif ($value instanceof Definition) { From 968275624aae33c7a9ae2b178eef9f7160b9aea8 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 7 Mar 2015 20:12:23 +0100 Subject: [PATCH 03/10] Php Inspections (EA Extended) - static code analysis includes: Reduce couple count calls in [Yaml] Modernize type casting, fix several strict comparisons Unsets merged Elvis operator usage Short syntax for applied operations --- .../Bridge/Twig/Translation/TwigExtractor.php | 2 +- .../Command/ContainerDebugCommand.php | 2 +- .../Component/Config/Util/XmlUtils.php | 8 ++++---- .../Console/Helper/ProgressHelper.php | 8 ++++---- .../DependencyInjection/Dumper/PhpDumper.php | 4 ++-- src/Symfony/Component/DomCrawler/Link.php | 2 +- src/Symfony/Component/Finder/Finder.php | 8 ++++---- .../Form/Extension/Core/Type/ChoiceType.php | 2 +- .../Component/Form/Util/ServerParams.php | 2 +- .../HttpFoundation/File/UploadedFile.php | 2 +- .../Component/HttpFoundation/Request.php | 2 +- .../Component/HttpFoundation/Response.php | 2 +- .../DataCollector/MemoryDataCollector.php | 2 +- .../Component/OptionsResolver/Options.php | 15 ++++----------- .../Security/Acl/Dbal/MutableAclProvider.php | 10 +++++----- .../DigestAuthenticationEntryPoint.php | 2 +- .../Validator/Constraints/IsbnValidator.php | 2 +- src/Symfony/Component/Yaml/Inline.php | 19 ++++++++++--------- src/Symfony/Component/Yaml/Parser.php | 2 +- 19 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index fe36436c71..4e8b817f77 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -84,7 +84,7 @@ class TwigExtractor implements ExtractorInterface $this->twig->parse($this->twig->tokenize($template)); foreach ($visitor->getMessages() as $message) { - $catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ? $message[1] : $this->defaultDomain); + $catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain); } $visitor->disable(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index d4c8738844..a55bbb9895 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -305,7 +305,7 @@ EOF $synthetic = $definition->isSynthetic() ? 'yes' : 'no'; $output->writeln(sprintf('Synthetic %s', $synthetic)); - $file = $definition->getFile() ? $definition->getFile() : '-'; + $file = $definition->getFile() ?: '-'; $output->writeln(sprintf('Required File %s', $file)); } elseif ($definition instanceof Alias) { $alias = $definition; diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index 7d66799c08..34ad20e459 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -191,17 +191,17 @@ class XmlUtils return; case ctype_digit($value): $raw = $value; - $cast = intval($value); + $cast = (int) $value; - return '0' == $value[0] ? octdec($value) : (((string) $raw == (string) $cast) ? $cast : $raw); + return '0' == $value[0] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw); case 'true' === $lowercaseValue: return true; case 'false' === $lowercaseValue: return false; case is_numeric($value): - return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value); + return '0x' === $value[0].$value[1] ? hexdec($value) : (float) $value; case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value): - return floatval($value); + return (float) $value; default: return $value; } diff --git a/src/Symfony/Component/Console/Helper/ProgressHelper.php b/src/Symfony/Component/Console/Helper/ProgressHelper.php index e927fe3b10..7d80107909 100644 --- a/src/Symfony/Component/Console/Helper/ProgressHelper.php +++ b/src/Symfony/Component/Console/Helper/ProgressHelper.php @@ -235,11 +235,11 @@ class ProgressHelper extends Helper $redraw = true; } - $prevPeriod = intval($this->current / $this->redrawFreq); + $prevPeriod = (int) ($this->current / $this->redrawFreq); $this->current += $step; - $currPeriod = intval($this->current / $this->redrawFreq); + $currPeriod = (int) ($this->current / $this->redrawFreq); if ($redraw || $prevPeriod !== $currPeriod || $this->max === $this->current) { $this->display(); } @@ -269,11 +269,11 @@ class ProgressHelper extends Helper $redraw = true; } - $prevPeriod = intval($this->current / $this->redrawFreq); + $prevPeriod = (int) ($this->current / $this->redrawFreq); $this->current = $current; - $currPeriod = intval($this->current / $this->redrawFreq); + $currPeriod = (int) ($this->current / $this->redrawFreq); if ($redraw || $prevPeriod !== $currPeriod || $this->max === $this->current) { $this->display(); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index e152b9af2f..c12a60d2b9 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1341,13 +1341,13 @@ EOF; if ('' === $name) { $name .= $firstChars[$i%$firstCharsLength]; - $i = intval($i/$firstCharsLength); + $i = (int) ($i/$firstCharsLength); } while ($i > 0) { --$i; $name .= $nonFirstChars[$i%$nonFirstCharsLength]; - $i = intval($i/$nonFirstCharsLength); + $i = (int) ($i/$nonFirstCharsLength); } ++$this->variableCount; diff --git a/src/Symfony/Component/DomCrawler/Link.php b/src/Symfony/Component/DomCrawler/Link.php index 863a6383d6..86ed2bedcd 100644 --- a/src/Symfony/Component/DomCrawler/Link.php +++ b/src/Symfony/Component/DomCrawler/Link.php @@ -154,7 +154,7 @@ class Link } if ('.' === substr($path, -1)) { - $path = $path.'/'; + $path .= '/'; } $output = array(); diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index 4f8caecb38..940cb5b999 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -436,9 +436,9 @@ class Finder implements \IteratorAggregate, \Countable public function ignoreDotFiles($ignoreDotFiles) { if ($ignoreDotFiles) { - $this->ignore = $this->ignore | static::IGNORE_DOT_FILES; + $this->ignore |= static::IGNORE_DOT_FILES; } else { - $this->ignore = $this->ignore & ~static::IGNORE_DOT_FILES; + $this->ignore &= ~static::IGNORE_DOT_FILES; } return $this; @@ -458,9 +458,9 @@ class Finder implements \IteratorAggregate, \Countable public function ignoreVCS($ignoreVCS) { if ($ignoreVCS) { - $this->ignore = $this->ignore | static::IGNORE_VCS_FILES; + $this->ignore |= static::IGNORE_VCS_FILES; } else { - $this->ignore = $this->ignore & ~static::IGNORE_VCS_FILES; + $this->ignore &= ~static::IGNORE_VCS_FILES; } return $this; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 5520119fdf..418661aebe 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -131,7 +131,7 @@ class ChoiceType extends AbstractType // Add "[]" to the name in case a select tag with multiple options is // displayed. Otherwise only one of the selected options is sent in the // POST request. - $view->vars['full_name'] = $view->vars['full_name'].'[]'; + $view->vars['full_name'] .= '[]'; } } diff --git a/src/Symfony/Component/Form/Util/ServerParams.php b/src/Symfony/Component/Form/Util/ServerParams.php index 3b1f835182..9b9c02d393 100644 --- a/src/Symfony/Component/Form/Util/ServerParams.php +++ b/src/Symfony/Component/Form/Util/ServerParams.php @@ -35,7 +35,7 @@ class ServerParams } elseif (0 === strpos($max, '0')) { $max = intval($max, 8); } else { - $max = intval($max); + $max = (int) $max; } switch (substr($iniMax, -1)) { diff --git a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php index 98b1176063..24d03437d4 100644 --- a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php +++ b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php @@ -270,7 +270,7 @@ class UploadedFile extends File } elseif (0 === strpos($max, '0')) { $max = intval($max, 8); } else { - $max = intval($max); + $max = (int) $max; } switch (substr($iniMax, -1)) { diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 8a66e94567..f6c319c9ed 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -975,7 +975,7 @@ class Request } if (false !== $pos) { - return intval(substr($host, $pos + 1)); + return (int) substr($host, $pos + 1); } return 'https' === $this->getScheme() ? 443 : 80; diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index fa80ccc2af..3db864db8a 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -1195,7 +1195,7 @@ class Response protected function ensureIEOverSSLCompatibility(Request $request) { if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) { - if (intval(preg_replace("/(MSIE )(.*?);/", "$2", $match[0])) < 9) { + if ((int) preg_replace("/(MSIE )(.*?);/", "$2", $match[0]) < 9) { $this->headers->remove('Cache-Control'); } } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php index 9e1a310cb9..a3738b6de0 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php @@ -86,7 +86,7 @@ class MemoryDataCollector extends DataCollector } elseif (0 === strpos($max, '0')) { $max = intval($max, 8); } else { - $max = intval($max); + $max = (int) $max; } switch (substr($memoryLimit, -1)) { diff --git a/src/Symfony/Component/OptionsResolver/Options.php b/src/Symfony/Component/OptionsResolver/Options.php index a341ecc94d..e6da18c764 100644 --- a/src/Symfony/Component/OptionsResolver/Options.php +++ b/src/Symfony/Component/OptionsResolver/Options.php @@ -92,8 +92,7 @@ class Options implements \ArrayAccess, \Iterator, \Countable // Setting is equivalent to overloading while discarding the previous // option value - unset($this->options[$option]); - unset($this->lazy[$option]); + unset($this->options[$option], $this->lazy[$option]); $this->overload($option, $value); } @@ -270,9 +269,7 @@ class Options implements \ArrayAccess, \Iterator, \Countable throw new OptionDefinitionException('Options cannot be removed anymore once options have been read.'); } - unset($this->options[$option]); - unset($this->lazy[$option]); - unset($this->normalizers[$option]); + unset($this->options[$option], $this->lazy[$option], $this->normalizers[$option]); } /** @@ -470,10 +467,8 @@ class Options implements \ArrayAccess, \Iterator, \Countable foreach ($this->lazy[$option] as $closure) { $this->options[$option] = $closure($this, $this->options[$option]); } - unset($this->lock[$option]); - // The option now isn't lazy anymore - unset($this->lazy[$option]); + unset($this->lock[$option], $this->lazy[$option]); } /** @@ -509,9 +504,7 @@ class Options implements \ArrayAccess, \Iterator, \Countable $this->lock[$option] = true; $this->options[$option] = $normalizer($this, array_key_exists($option, $this->options) ? $this->options[$option] : null); - unset($this->lock[$option]); - // The option is now normalized - unset($this->normalizers[$option]); + unset($this->lock[$option], $this->normalizers[$option]); } } diff --git a/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php b/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php index f1b8afffb5..a710bf75e7 100644 --- a/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php +++ b/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php @@ -242,7 +242,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf if (null === $propertyChanges['parentAcl'][1]) { $sets[] = 'parent_object_identity_id = NULL'; } else { - $sets[] = 'parent_object_identity_id = '.intval($propertyChanges['parentAcl'][1]->getId()); + $sets[] = 'parent_object_identity_id = '.(int) $propertyChanges['parentAcl'][1]->getId(); } $this->regenerateAncestorRelations($acl); @@ -453,7 +453,7 @@ QUERY; $query, $this->options['entry_table_name'], $classId, - null === $objectIdentityId ? 'NULL' : intval($objectIdentityId), + null === $objectIdentityId ? 'NULL' : (int) $objectIdentityId, null === $field ? 'NULL' : $this->connection->quote($field), $aceOrder, $securityIdentityId, @@ -571,7 +571,7 @@ QUERY; $classId, null === $oid ? $this->connection->getDatabasePlatform()->getIsNullExpression('object_identity_id') - : 'object_identity_id = '.intval($oid), + : 'object_identity_id = '.(int) $oid, null === $field ? $this->connection->getDatabasePlatform()->getIsNullExpression('field_name') : 'field_name = '.$this->connection->quote($field), @@ -812,7 +812,7 @@ QUERY; $aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id'); $aceIdProperty->setAccessible(true); - $aceIdProperty->setValue($ace, intval($aceId)); + $aceIdProperty->setValue($ace, (int) $aceId); } else { $currentIds[$ace->getId()] = true; } @@ -888,7 +888,7 @@ QUERY; $aceIdProperty = new \ReflectionProperty($ace, 'id'); $aceIdProperty->setAccessible(true); - $aceIdProperty->setValue($ace, intval($aceId)); + $aceIdProperty->setValue($ace, (int) $aceId); } } } diff --git a/src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php b/src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php index 71a6313ae4..5a7aa1abee 100644 --- a/src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php +++ b/src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php @@ -50,7 +50,7 @@ class DigestAuthenticationEntryPoint implements AuthenticationEntryPointInterfac $authenticateHeader = sprintf('Digest realm="%s", qop="auth", nonce="%s"', $this->realmName, $nonceValueBase64); if ($authException instanceof NonceExpiredException) { - $authenticateHeader = $authenticateHeader.', stale="true"'; + $authenticateHeader .= ', stale="true"'; } if (null !== $this->logger) { diff --git a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php index 4f246960f3..40e4f743af 100644 --- a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php @@ -81,7 +81,7 @@ class IsbnValidator extends ConstraintValidator return false; } - $checkSum += $digit * intval(10 - $i); + $checkSum += $digit * (10 - $i); } return 0 === $checkSum % 11; diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index ab7c72e405..6564ad4422 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -125,7 +125,7 @@ class Inline if (false !== $locale) { setlocale(LC_NUMERIC, 'C'); } - $repr = is_string($value) ? "'$value'" : (is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : strval($value)); + $repr = is_string($value) ? "'$value'" : (is_infinite($value) ? str_ireplace('INF', '.Inf', (string) $value) : (string) $value); if (false !== $locale) { setlocale(LC_NUMERIC, $locale); @@ -157,8 +157,9 @@ class Inline { // array $keys = array_keys($value); - if ((1 == count($keys) && '0' == $keys[0]) - || (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2) + $keysCount = count($keys); + if ((1 === $keysCount && '0' == $keys[0]) + || ($keysCount > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) === $keysCount * ($keysCount - 1) / 2) ) { $output = array(); foreach ($value as $val) { @@ -431,7 +432,7 @@ class Inline case 0 === strpos($scalar, '!str'): return (string) substr($scalar, 5); case 0 === strpos($scalar, '! '): - return intval(self::parseScalar(substr($scalar, 2))); + return (int) self::parseScalar(substr($scalar, 2)); case 0 === strpos($scalar, '!!php/object:'): if (self::$objectSupport) { return unserialize(substr($scalar, 13)); @@ -444,23 +445,23 @@ class Inline return; case ctype_digit($scalar): $raw = $scalar; - $cast = intval($scalar); + $cast = (int) $scalar; return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw); case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)): $raw = $scalar; - $cast = intval($scalar); + $cast = (int) $scalar; - return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw); + return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw); case is_numeric($scalar): - return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar); + return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar; case '.inf' === $scalarLower: case '.nan' === $scalarLower: return -log(0); case '-.inf' === $scalarLower: return log(0); case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar): - return floatval(str_replace(',', '', $scalar)); + return (float) str_replace(',', '', $scalar); case preg_match(self::getTimestampRegex(), $scalar): return strtotime($scalar); } diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 6b2cc72aed..f815931507 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -423,7 +423,7 @@ class Parser if (preg_match('/^'.self::FOLDED_SCALAR_PATTERN.'$/', $value, $matches)) { $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : ''; - return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers))); + return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers)); } try { From 1af6a9ec5a16ed478eb60c1191630e0268f2f4f9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 10 Mar 2015 14:08:39 +0100 Subject: [PATCH 04/10] fixed XSS in the exception handler --- src/Symfony/Component/Debug/ExceptionHandler.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index 9ab418c945..f429add39e 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -131,6 +131,7 @@ class ExceptionHandler } $content = ''; + $flags = PHP_VERSION_ID >= 50400 ? ENT_QUOTES | ENT_SUBSTITUTE : ENT_QUOTES; if ($this->debug) { try { $count = count($exception->getAllPrevious()); @@ -138,7 +139,7 @@ class ExceptionHandler foreach ($exception->toArray() as $position => $e) { $ind = $count - $position + 1; $class = $this->abbrClass($e['class']); - $message = nl2br($e['message']); + $message = nl2br(htmlspecialchars($e['message'], $flags, $this->charset)); $content .= sprintf(<<

%d/%d %s: %s

@@ -169,7 +170,7 @@ EOF } catch (\Exception $e) { // something nasty happened and we cannot throw an exception anymore if ($this->debug) { - $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()); + $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), htmlspecialchars($e->getMessage(), $flags, $this->charset)); } else { $title = 'Whoops, looks like something went wrong.'; } From 6ca7fc946000b1f0c12e593da13d62881f236bb7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 11 Mar 2015 15:41:28 +0100 Subject: [PATCH 05/10] Revert "bug #13715 Enforce UTF-8 charset for core controllers (WouterJ)" This reverts commit 463b24b27c15c8b24cdb4925f8772ef53ede9b23, reversing changes made to c475704c8feaac30ee260a542185a5699eba3d1b. --- .../Controller/ExceptionController.php | 4 +- .../Controller/ExceptionControllerTest.php | 3 +- .../Controller/ExceptionController.php | 19 ++-- .../Controller/ProfilerController.php | 104 +++++++----------- .../Controller/RouterController.php | 14 +-- .../Controller/ProfilerControllerTest.php | 1 - 6 files changed, 57 insertions(+), 88 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php index 39d4aee102..9f1edad12c 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -51,7 +51,7 @@ class ExceptionController $code = $exception->getStatusCode(); - return Response::create($this->twig->render( + return new Response($this->twig->render( (string) $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug), array( 'status_code' => $code, @@ -60,7 +60,7 @@ class ExceptionController 'logger' => $logger, 'currentContent' => $currentContent, ) - ))->setCharset('UTF-8'); + )); } /** diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php index 6cdb02f99d..20646f74aa 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php @@ -39,7 +39,6 @@ class ExceptionControllerTest extends TestCase $request->headers->set('X-Php-Ob-Level', 1); $controller = new ExceptionController($twig, false); - $response = $controller->showAction($request, $flatten); - $this->assertEquals('UTF-8', $response->getCharset(), 'Request charset is explicitly set to UTF-8'); + $controller->showAction($request, $flatten); } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php index abd75d440e..0b5db752ee 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php @@ -62,17 +62,16 @@ class ExceptionController $code = $exception->getStatusCode(); - return Response::create( - $this->twig->render($template, array( + return new Response($this->twig->render( + $template, + array( 'status_code' => $code, 'status_text' => Response::$statusTexts[$code], 'exception' => $exception, 'logger' => null, 'currentContent' => '', - )), - 200, - array('Content-Type' => 'text/html') - )->setCharset('UTF-8'); + ) + ), 200, array('Content-Type' => 'text/html')); } /** @@ -98,14 +97,10 @@ class ExceptionController if (!$this->templateExists($template)) { $handler = new ExceptionHandler(); - $response = new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css')); - } else { - $response = new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css')); + return new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css')); } - $response->setCharset('UTF-8'); - - return $response; + return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css')); } protected function getTemplate() diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 2c0d7a795e..173616fd9f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -99,20 +99,16 @@ class ProfilerController throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token)); } - return Response::create( - $this->twig->render($this->getTemplateManager()->getName($profile, $panel), array( - 'token' => $token, - 'profile' => $profile, - 'collector' => $profile->getCollector($panel), - 'panel' => $panel, - 'page' => $page, - 'request' => $request, - 'templates' => $this->getTemplateManager()->getTemplates($profile), - 'is_ajax' => $request->isXmlHttpRequest(), - )), - 200, - array('Content-Type' => 'text/html') - )->setCharset('UTF-8'); + return new Response($this->twig->render($this->getTemplateManager()->getName($profile, $panel), array( + 'token' => $token, + 'profile' => $profile, + 'collector' => $profile->getCollector($panel), + 'panel' => $panel, + 'page' => $page, + 'request' => $request, + 'templates' => $this->getTemplateManager()->getTemplates($profile), + 'is_ajax' => $request->isXmlHttpRequest(), + )), 200, array('Content-Type' => 'text/html')); } /** @@ -151,13 +147,9 @@ class ProfilerController $this->profiler->disable(); - return Response::create( - $this->twig->render('@WebProfiler/Profiler/info.html.twig', array( - 'about' => $about, - )), - 200, - array('Content-Type' => 'text/html') - )->setCharset('UTF-8'); + return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array( + 'about' => $about, + )), 200, array('Content-Type' => 'text/html')); } /** @@ -205,17 +197,13 @@ class ProfilerController // the profiler is not enabled } - return Response::create( - $this->twig->render('@WebProfiler/Profiler/toolbar.html.twig', array( - 'position' => $position, - 'profile' => $profile, - 'templates' => $this->getTemplateManager()->getTemplates($profile), - 'profiler_url' => $url, - 'token' => $token, - )), - 200, - array('Content-Type' => 'text/html') - )->setCharset('UTF-8'); + return new Response($this->twig->render('@WebProfiler/Profiler/toolbar.html.twig', array( + 'position' => $position, + 'profile' => $profile, + 'templates' => $this->getTemplateManager()->getTemplates($profile), + 'profiler_url' => $url, + 'token' => $token, + )), 200, array('Content-Type' => 'text/html')); } /** @@ -253,19 +241,15 @@ class ProfilerController $token = $session->get('_profiler_search_token'); } - return Response::create( - $this->twig->render('@WebProfiler/Profiler/search.html.twig', array( - 'token' => $token, - 'ip' => $ip, - 'method' => $method, - 'url' => $url, - 'start' => $start, - 'end' => $end, - 'limit' => $limit, - )), - 200, - array('Content-Type' => 'text/html') - )->setCharset('UTF-8'); + return new Response($this->twig->render('@WebProfiler/Profiler/search.html.twig', array( + 'token' => $token, + 'ip' => $ip, + 'method' => $method, + 'url' => $url, + 'start' => $start, + 'end' => $end, + 'limit' => $limit, + )), 200, array('Content-Type' => 'text/html')); } /** @@ -295,22 +279,18 @@ class ProfilerController $end = $request->query->get('end', null); $limit = $request->query->get('limit'); - return Response::create( - $this->twig->render('@WebProfiler/Profiler/results.html.twig', array( - 'token' => $token, - 'profile' => $profile, - 'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end), - 'ip' => $ip, - 'method' => $method, - 'url' => $url, - 'start' => $start, - 'end' => $end, - 'limit' => $limit, - 'panel' => null, - )), - 200, - array('Content-Type' => 'text/html') - )->setCharset('UTF-8'); + return new Response($this->twig->render('@WebProfiler/Profiler/results.html.twig', array( + 'token' => $token, + 'profile' => $profile, + 'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end), + 'ip' => $ip, + 'method' => $method, + 'url' => $url, + 'start' => $start, + 'end' => $end, + 'limit' => $limit, + 'panel' => null, + )), 200, array('Content-Type' => 'text/html')); } /** @@ -384,7 +364,7 @@ class ProfilerController phpinfo(); $phpinfo = ob_get_clean(); - return Response::create($phpinfo, 200, array('Content-Type' => 'text/html'))->setCharset('UTF-8'); + return new Response($phpinfo, 200, array('Content-Type' => 'text/html')); } /** diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php index 800f209a6f..f4a84bf568 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php @@ -68,14 +68,10 @@ class RouterController $request = $profile->getCollector('request'); - return Response::create( - $this->twig->render('@WebProfiler/Router/panel.html.twig', array( - 'request' => $request, - 'router' => $profile->getCollector('router'), - 'traces' => $matcher->getTraces($request->getPathInfo()), - )), - 200, - array('Content-Type' => 'text/html') - )->setCharset('UTF-8'); + return new Response($this->twig->render('@WebProfiler/Router/panel.html.twig', array( + 'request' => $request, + 'router' => $profile->getCollector('router'), + 'traces' => $matcher->getTraces($request->getPathInfo()), + )), 200, array('Content-Type' => 'text/html')); } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php index 3338d8c53b..c10449d323 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php @@ -69,7 +69,6 @@ class ProfilerControllerTest extends \PHPUnit_Framework_TestCase $response = $controller->toolbarAction(Request::create('/_wdt/found'), 'found'); $this->assertEquals(200, $response->getStatusCode()); - $this->assertEquals('UTF-8', $response->getCharset(), 'Request charset is explicitly set to UTF-8'); $response = $controller->toolbarAction(Request::create('/_wdt/notFound'), 'notFound'); $this->assertEquals(404, $response->getStatusCode()); From cbd0525f8f5c4fa71caf4a6183dbb8cf61256cbc Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Sun, 31 Mar 2013 20:32:41 +0200 Subject: [PATCH 06/10] used HTML5 meta charset tag and removed hardcoded ones Conflicts: src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Resources/views/base.html.twig src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig src/Symfony/Bundle/TwigBundle/Resources/views/layout.html.twig --- .../Tests/Functional/app/Resources/views/base.html.twig | 2 +- .../TwigBundle/Resources/views/Exception/error.html.twig | 2 +- .../WebProfilerBundle/Resources/views/Profiler/base.html.twig | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Resources/views/base.html.twig b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Resources/views/base.html.twig index 4b9151eaf8..58ba1fe89e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Resources/views/base.html.twig +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Resources/views/base.html.twig @@ -1,7 +1,7 @@ - + {% block title %}Welcome!{% endblock %} {% block stylesheets %}{% endblock %} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig index 30b51e4760..138a60ad96 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig @@ -1,7 +1,7 @@ - + An Error Occurred: {{ status_text }} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base.html.twig index e4258a205d..3567708a72 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base.html.twig @@ -1,8 +1,8 @@ - - + + {% block title 'Profiler' %}