8000 Merge branch '2.7' into 2.8 · symfony/symfony@b0bbdef · GitHub
[go: up one dir, main page]

Skip to content

Commit b0bbdef

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Php Inspections (EA Ultimate): address some of one-time used local variables [Intl] Load locale aliases to support alias fallbacks [CssSelector] Fix CSS identifiers parsing - they can start with dash
2 parents 5757a85 + ed63ab6 commit b0bbdef

File tree

9 files changed

+101
-18
lines changed

9 files changed

+101
-18
lines changed

src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public function __construct(Environment $twig)
5454
*/
5555
public function extract($resource, MessageCatalogue $catalogue)
5656
{
57-
$files = $this->extractFiles($resource);
58-
foreach ($files as $file) {
57+
foreach ($this->extractFiles($resource) as $file) {
5958
try {
6059
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
6160
} catch (Error $e) {

src/Symfony/Component/CssSelector/Parser/Tokenizer/TokenizerPatterns.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct()
4646
$this->nonAsciiPattern = '[^\x00-\x7F]';
4747
$this->nmCharPattern = '[_a-z0-9-]|'.$this->escapePattern.'|'.$this->nonAsciiPattern;
4848
$this->nmStartPattern = '[_a-z]|'.$this->escapePattern.'|'.$this->nonAsciiPattern;
49-
$this->identifierPattern = '(?:'.$this->nmStartPattern.')(?:'.$this->nmCharPattern.')*';
49+
$this->identifierPattern = '-?(?:'.$this->nmStartPattern.')(?:'.$this->nmCharPattern.')*';
5050
$this->hashPattern = '#((?:'.$this->nmCharPattern.')+)';
5151
$this->numberPattern = '[+-]?(?:[0-9]*\.[0-9]+|[0-9]+)';
5252
$this->quotedStringPattern = '([^\n\r\f%s]|'.$this->stringEscapePattern.')*';

src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public function getPseudoElementsTestData()
186186
array('foo:after', 'Element[foo]', 'after'),
187187
array('foo::selection', 'Element[foo]', 'selection'),
188188
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'),
189+
array('video::-webkit-media-controls', 'Element[video]', '-webkit-media-controls'),
189190
);
190191
}
191192

src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ private function initialize()
133133
$this->values = array();
134134
$this->structuredValues = $this->adaptedList->getValues();
135135

136-
$innerChoices = $this->adaptedList->getChoices();
137-
138-
foreach ($innerChoices as $index => $choice) {
136+
foreach ($this->adaptedList->getChoices() as $index => $choice) {
139137
$value = $this->structuredValues[$index];
140138
$this->values[] = $value;
141139
$this->choices[$value] = $choice;

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
8080
}
8181
}
8282

83+
$formConfig = $form->getConfig();
8384
$view->vars = array_replace($view->vars, array(
8485
'read_only' => isset($view->vars['attr']['readonly']) && false !== $view->vars['attr']['readonly'], // deprecated
8586
'errors' => $form->getErrors(),
@@ -91,9 +92,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
9192
'pattern' => isset($options['attr']['pattern']) ? $options['attr']['pattern'] : null, // Deprecated
9293
'size' => null,
9394
'label_attr' => $options['label_attr'],
94-
'compound' => $form->getConfig()->getCompound(),
95-
'method' => $form->getConfig()->getMethod(),
96-
'action' => $form->getConfig()->getAction(),
95+
'compound' => $formConfig->getCompound(),
96+
'method' => $formConfig->getMethod(),
97+
'action' => $formConfig->getAction(),
9798 F438
'submitted' => $form->isSubmitted(),
9899
));
99100
}

src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public function validateForm(FormEvent $event)
6565

6666
if ($form->isRoot()) {
6767
// Validate the form in group "Default"
68-
$violations = $this->validator->validate($form);
69-
70-
foreach ($violations as $violation) {
68+
foreach ($this->validator->validate($form) as $violation) {
7169
// Allow the "invalid" constraint to be put onto
7270
// non-synchronized forms
7371
// ConstraintViolation::getConstraint() must not expect to provide a constraint as long as Symfony\Component\Validator\ExecutionContext exists (before 3.0)

src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,8 @@ protected function guess($class, $property, \Closure $closure, $defaultValue = n
264264
$classMetadata = $this->metadataFactory->getMetadataFor($class);
265265

266266
if ($classMetadata instanceof ClassMetadataInterface && $classMetadata->hasPropertyMetadata($property)) {
267-
$memberMetadatas = $classMetadata->getPropertyMetadata($property);
268-
269-
foreach ($memberMetadatas as $memberMetadata) {
270-
$constraints = $memberMetadata->getConstraints();
271-
272-
foreach ($constraints as $constraint) {
267+
foreach ($classMetadata->getPropertyMetadata($property) as $memberMetadata) {
268+
foreach ($memberMetadata->getConstraints() as $constraint) {
273269
if ($guess = $closure($constraint)) {
274270
$guesses[] = $guess;
275271
}

src/Symfony/Component/Intl/Intl.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Intl\Data\Bundle\Reader\BufferedBundleReader;
1616
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader;
1717
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
18+
use Symfony\Component\Intl\Data\Provider\LocaleDataProvider;
1819
use Symfony\Component\Intl\Data\Provider\ScriptDataProvider;
1920
use Symfony\Component\Intl\ResourceBundle\CurrencyBundle;
2021
use Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface;
@@ -259,6 +260,11 @@ private static function getEntryReader()
259260
new JsonBundleReader(),
260261
self::BUFFER_SIZE
261262
));
263+
$localeDataProvider = new LocaleDataProvider(
264+
self::getDataDirectory().'/'.self::LOCALE_DIR,
265+
self::$entryReader
266+
);
267+
self::$entryReader->setLocaleAliases($localeDataProvider->getAliases());
262268
}
263269

264270
return self::$entryReader;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Intl\Tests;
13+
14+
use Symfony\Component\Intl\Intl;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class IntlTest extends TestCase
18+
{
19+
/**
20+
* @requires extension intl
21+
*/
22+
public function testIsExtensionLoadedChecksIfIntlExtensionIsLoaded()
23+
{
24+
$this->assertTrue(Intl::isExtensionLoaded());
25+
}
26+
27+
public function testGetCurrencyBundleCreatesTheCurrencyBundle()
28+
{
29+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface', Intl::getCurrencyBundle());
30+
}
31+
32+
public function testGetLanguageBundleCreatesTheLanguageBundle()
33+
{
34+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface', Intl::getLanguageBundle());
35+
}
36+
37+
public function testGetLocaleBundleCreatesTheLocaleBundle()
38+
{
39+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle());
40+
}
41+
42+
public function testGetRegionBundleCreatesTheRegionBundle()
43+
{
44+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle());
45+
}
46+
47+
public function testGetIcuVersionReadsTheVersionOfInstalledIcuLibrary()
48+
{
49+
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuVersion());
50+
}
51+
52+
public function testGetIcuDataVersionReadsTheVersionOfInstalledIcuData()
53+
{
54+
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuDataVersion());
55+
}
56+
57+
public function testGetIcuStubVersionReadsTheVersionOfBundledStubs()
58+
{
59+
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuStubVersion());
60+
}
61+
62+
public function testGetDataDirectoryReturnsThePathToIcuData()
63+
{
64+
$this->assertTrue(is_dir(Intl::getDataDirectory()));
65+
}
66+
67+
/**
68+
* @requires extension intl
69+
*/
70+
public function testLocaleAliasesAreLoaded()
71+
{
72+
\Locale::setDefault('zh_TW');
73+
$countryNameZhTw = Intl::getRegionBundle()->getCountryName('AD');
74+
75+
\Locale::setDefault('zh_Hant_TW');
76+
$countryNameHantZhTw = Intl::getRegionBundle()->getCountryName('AD');
77+
78+
\Locale::setDefault('zh');
79+
$countryNameZh = Intl::getRegionBundle()->getCountryName('AD');
80+
81+
$this->assertSame($countryNameZhTw, $countryNameHantZhTw, 'zh_TW is an alias to zh_Hant_TW');
82+
$this->assertNotSame($countryNameZh, $countryNameZhTw, 'zh_TW does not fall back to zh');
83+
}
84+
}

0 commit comments

Comments
 (0)
0