From 16e86bc0c0e416071fbabbd5f22be0cb115e4364 Mon Sep 17 00:00:00 2001 From: Jakub Kulhan Date: Thu, 8 Mar 2018 00:00:26 +0100 Subject: [PATCH 1/3] [CssSelector] Fix CSS identifiers parsing - they can start with dash --- .../CssSelector/Parser/Tokenizer/TokenizerPatterns.php | 2 +- src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/CssSelector/Parser/Tokenizer/TokenizerPatterns.php b/src/Symfony/Component/CssSelector/Parser/Tokenizer/TokenizerPatterns.php index b548905fa2..15dfb0eb0e 100644 --- a/src/Symfony/Component/CssSelector/Parser/Tokenizer/TokenizerPatterns.php +++ b/src/Symfony/Component/CssSelector/Parser/Tokenizer/TokenizerPatterns.php @@ -44,7 +44,7 @@ class TokenizerPatterns $this->nonAsciiPattern = '[^\x00-\x7F]'; $this->nmCharPattern = '[_a-z0-9-]|'.$this->escapePattern.'|'.$this->nonAsciiPattern; $this->nmStartPattern = '[_a-z]|'.$this->escapePattern.'|'.$this->nonAsciiPattern; - $this->identifierPattern = '(?:'.$this->nmStartPattern.')(?:'.$this->nmCharPattern.')*'; + $this->identifierPattern = '-?(?:'.$this->nmStartPattern.')(?:'.$this->nmCharPattern.')*'; $this->hashPattern = '#((?:'.$this->nmCharPattern.')+)'; $this->numberPattern = '[+-]?(?:[0-9]*\.[0-9]+|[0-9]+)'; $this->quotedStringPattern = '([^\n\r\f%s]|'.$this->stringEscapePattern.')*'; diff --git a/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php b/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php index 37a3ef1d58..53b35a9547 100644 --- a/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php +++ b/src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php @@ -186,6 +186,7 @@ class ParserTest extends TestCase array('foo:after', 'Element[foo]', 'after'), array('foo::selection', 'Element[foo]', 'selection'), array('lorem#ipsum ~ a#b.c[href]:empty::selection', 'CombinedSelector[Hash[Element[lorem]#ipsum] ~ Pseudo[Attribute[Class[Hash[Element[a]#b].c][href]]:empty]]', 'selection'), + array('video::-webkit-media-controls', 'Element[video]', '-webkit-media-controls'), ); } From 1debf79430f84d612f1ac0c1b7765f35bf8f1b3a Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 7 Mar 2018 23:32:04 +0000 Subject: [PATCH 2/3] [Intl] Load locale aliases to support alias fallbacks --- src/Symfony/Component/Intl/Intl.php | 6 ++ src/Symfony/Component/Intl/Tests/IntlTest.php | 84 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/Symfony/Component/Intl/Tests/IntlTest.php diff --git a/src/Symfony/Component/Intl/Intl.php b/src/Symfony/Component/Intl/Intl.php index 3444c10f83..e552b994fd 100644 --- a/src/Symfony/Component/Intl/Intl.php +++ b/src/Symfony/Component/Intl/Intl.php @@ -15,6 +15,7 @@ use Symfony\Component\Intl\Data\Bundle\Reader\JsonBundleReader; use Symfony\Component\Intl\Data\Bundle\Reader\BufferedBundleReader; use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader; use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface; +use Symfony\Component\Intl\Data\Provider\LocaleDataProvider; use Symfony\Component\Intl\Data\Provider\ScriptDataProvider; use Symfony\Component\Intl\ResourceBundle\CurrencyBundle; use Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface; @@ -259,6 +260,11 @@ final class Intl new JsonBundleReader(), self::BUFFER_SIZE )); + $localeDataProvider = new LocaleDataProvider( + self::getDataDirectory().'/'.self::LOCALE_DIR, + self::$entryReader + ); + self::$entryReader->setLocaleAliases($localeDataProvider->getAliases()); } return self::$entryReader; diff --git a/src/Symfony/Component/Intl/Tests/IntlTest.php b/src/Symfony/Component/Intl/Tests/IntlTest.php new file mode 100644 index 0000000000..d77655b77d --- /dev/null +++ b/src/Symfony/Component/Intl/Tests/IntlTest.php @@ -0,0 +1,84 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests; + +use Symfony\Component\Intl\Intl; +use PHPUnit\Framework\TestCase; + +class IntlTest extends TestCase +{ + /** + * @requires extension intl + */ + public function testIsExtensionLoadedChecksIfIntlExtensionIsLoaded() + { + $this->assertTrue(Intl::isExtensionLoaded()); + } + + public function testGetCurrencyBundleCreatesTheCurrencyBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface', Intl::getCurrencyBundle()); + } + + public function testGetLanguageBundleCreatesTheLanguageBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface', Intl::getLanguageBundle()); + } + + public function testGetLocaleBundleCreatesTheLocaleBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle()); + } + + public function testGetRegionBundleCreatesTheRegionBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle()); + } + + public function testGetIcuVersionReadsTheVersionOfInstalledIcuLibrary() + { + $this->assertStringMatchesFormat('%d.%d', Intl::getIcuVersion()); + } + + public function testGetIcuDataVersionReadsTheVersionOfInstalledIcuData() + { + $this->assertStringMatchesFormat('%d.%d', Intl::getIcuDataVersion()); + } + + public function testGetIcuStubVersionReadsTheVersionOfBundledStubs() + { + $this->assertStringMatchesFormat('%d.%d', Intl::getIcuStubVersion()); + } + + public function testGetDataDirectoryReturnsThePathToIcuData() + { + $this->assertTrue(is_dir(Intl::getDataDirectory())); + } + + /** + * @requires extension intl + */ + public function testLocaleAliasesAreLoaded() + { + \Locale::setDefault('zh_TW'); + $countryNameZhTw = Intl::getRegionBundle()->getCountryName('AD'); + + \Locale::setDefault('zh_Hant_TW'); + $countryNameHantZhTw = Intl::getRegionBundle()->getCountryName('AD'); + + \Locale::setDefault('zh'); + $countryNameZh = Intl::getRegionBundle()->getCountryName('AD'); + + $this->assertSame($countryNameZhTw, $countryNameHantZhTw, 'zh_TW is an alias to zh_Hant_TW'); + $this->assertNotSame($countryNameZh, $countryNameZhTw, 'zh_TW does not fall back to zh'); + } +} From f16d99ecfa2c98a41c8ebcd42c69fd27720d634c Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 10 Mar 2018 10:27:05 +0100 Subject: [PATCH 3/3] Php Inspections (EA Ultimate): address some of one-time used local variables --- src/Symfony/Bridge/Twig/Translation/TwigExtractor.php | 3 +-- src/Symfony/Component/DomCrawler/Crawler.php | 4 +--- .../Component/Form/ChoiceList/LegacyChoiceListAdapter.php | 4 +--- .../Component/Form/Extension/Core/Type/FormType.php | 7 ++++--- .../Validator/EventListener/ValidationListener.php | 4 +--- .../Form/Extension/Validator/ValidatorTypeGuesser.php | 8 ++------ 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index db388ab70b..a921582dba 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -54,8 +54,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface */ public function extract($resource, MessageCatalogue $catalogue) { - $files = $this->extractFiles($resource); - foreach ($files as $file) { + foreach ($this->extractFiles($resource) as $file) { try { $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue); } catch (Error $e) { diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index cccea633dd..a387b5245e 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1039,8 +1039,6 @@ class Crawler extends \SplObjectStorage */ private function createSubCrawler($nodes) { - $crawler = new static($nodes, $this->uri, $this->baseHref); - - return $crawler; + return new static($nodes, $this->uri, $this->baseHref); } } diff --git a/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php b/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php index 929ef8c290..57ec192e49 100644 --- a/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php +++ b/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php @@ -133,9 +133,7 @@ class LegacyChoiceListAdapter implements ChoiceListInterface $this->values = array(); $this->structuredValues = $this->adaptedList->getValues(); - $innerChoices = $this->adaptedList->getChoices(); - - foreach ($innerChoices as $index => $choice) { + foreach ($this->adaptedList->getChoices() as $index => $choice) { $value = $this->structuredValues[$index]; $this->values[] = $value; $this->choices[$value] = $choice; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index d8e8ff3176..9c5642b116 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -81,6 +81,7 @@ class FormType extends BaseType } } + $formConfig = $form->getConfig(); $view->vars = array_replace($view->vars, array( 'read_only' => $readOnly, 'errors' => $form->getErrors(), @@ -92,9 +93,9 @@ class FormType extends BaseType 'pattern' => isset($options['attr']['pattern']) ? $options['attr']['pattern'] : null, // Deprecated 'size' => null, 'label_attr' => $options['label_attr'], - 'compound' => $form->getConfig()->getCompound(), - 'method' => $form->getConfig()->getMethod(), - 'action' => $form->getConfig()->getAction(), + 'compound' => $formConfig->getCompound(), + 'method' => $formConfig->getMethod(), + 'action' => $formConfig->getAction(), 'submitted' => $form->isSubmitted(), )); } diff --git a/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php b/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php index 4bebce09cd..884bfca9e4 100644 --- a/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php +++ b/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php @@ -61,9 +61,7 @@ class ValidationListener implements EventSubscriberInterface if ($form->isRoot()) { // Validate the form in group "Default" - $violations = $this->validator->validate($form); - - foreach ($violations as $violation) { + foreach ($this->validator->validate($form) as $violation) { // Allow the "invalid" constraint to be put onto // non-synchronized forms // ConstraintViolation::getConstraint() must not expect to provide a constraint as long as Symfony\Component\Validator\ExecutionContext exists (before 3.0) diff --git a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php index 90dadd08d9..f40347d2a1 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php +++ b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php @@ -261,12 +261,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface $classMetadata = $this->metadataFactory->getMetadataFor($class); if ($classMetadata instanceof ClassMetadataInterface && $classMetadata->hasPropertyMetadata($property)) { - $memberMetadatas = $classMetadata->getPropertyMetadata($property); - - foreach ($memberMetadatas as $memberMetadata) { - $constraints = $memberMetadata->getConstraints(); - - foreach ($constraints as $constraint) { + foreach ($classMetadata->getPropertyMetadata($property) as $memberMetadata) { + foreach ($memberMetadata->getConstraints() as $constraint) { if ($guess = $closure($constraint)) { $guesses[] = $guess; }