Skip to content

Commit 82d13da

Browse files
minor symfony#27852 Fix coding standards (stof)
This PR was squashed before being merged into the 2.8 branch (closes symfony#27852). Discussion ---------- Fix coding standards | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This PR is mostly about running the PHP-CS-Fixer (v2.12.1) in the whole codebase. - I updated the exclude rule to avoid some false positives for the `error_suppression` fixer (we have more files triggering unsilenced deprecations on purpose than when building the initial whitelist, mostly). - I ran the fixer with this updated config. Most changes were related to fully-qualifying some constants, with the new fixer implemented in PHP-CS-Fixer/PHP-CS-Fixer#3127, for which @nicolas-grekas and I suggested a config to include in the Symfony ruleset. Based on the output, I suggested a feature request in PHP-CS-Fixer/PHP-CS-Fixer#3872 as we might want to avoid the `\` in non-namespaced files to improve readability. We might want to remove the second commit of this PR if we decide to wait for the feature to be implemented (update: implementation is contributed in PHP-CS-Fixer/PHP-CS-Fixer#3876) - I added the `native_function_invocation` fixer explicitly, to automatically fully-qualify calls to compiler-optimized functions. This feature was implemented in PHP-CS-Fixer based on our feature request (as currently, we do such thing only manually in some hot path, because it could not be automated). I opened PHP-CS-Fixer/PHP-CS-Fixer#3873 to include it in the ruleset automatically. TODOs: - [x] agree on the updated rules - [x] update fabbot to use the new version of PHP-CS-Fixer - [ ] make separate PRs for newer branches with their own updates (exclude rules, and CS fixes), once this PR gets merged. Commits ------- 538c69d Fix Clidumper tests 04654cf Enable the fixer enforcing fully-qualified calls for compiler-optimized functions f00b327 Apply fixers 720ed4d Disable the native_constant_invocation fixer until it can be scoped 8892b98 Update the list of excluded files for the CS fixer
2 parents a57549d + 538c69d commit 82d13da

File tree

720 files changed

+2268
-2271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

720 files changed

+2268
-2271
lines changed

.php_cs.dist

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ return PhpCsFixer\Config::create()
1515
// rule disabled due to https://bugs.php.net/bug.php?id=60573 bug;
1616
// to be re-enabled (by dropping next line, rule is part of @Symfony already) on branch that requires PHP 5.4+
1717
'self_accessor' => false,
18+
// TODO remove the disabling once https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/3876 is merged and released
19+
'native_constant_invocation' => false,
20+
// Part of @Symfony:risky in PHP-CS-Fixer 2.13.0. To be removed from the config file once upgrading
21+
'native_function_invocation' => array('include' => array('@compiler_optimized'), 'scope' => 'namespaced'),
1822
))
1923
->setRiskyAllowed(true)
2024
->setFinder(
@@ -32,16 +36,18 @@ return PhpCsFixer\Config::create()
3236
'Symfony/Component/VarDumper/Tests/Fixtures',
3337
// resource templates
3438
'Symfony/Bundle/FrameworkBundle/Resources/views/Form',
39+
// explicit trigger_error tests
40+
'Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/',
3541
))
42+
// Support for older PHPunit version
43+
->notPath('Symfony/Bridge/PhpUnit/SymfonyTestsListener.php')
3644
// file content autogenerated by `var_export`
3745
->notPath('Symfony/Component/Translation/Tests/fixtures/resources.php')
3846
// test template
3947
->notPath('Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom/_name_entry_label.html.php')
4048
// explicit heredoc test
4149
->notPath('Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php')
4250
// explicit trigger_error tests
43-
->notPath('Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt')
44-
->notPath('Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt')
4551
->notPath('Symfony/Component/Debug/Tests/DebugClassLoaderTest.php')
4652
)
4753
;

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function dispatchEvent($eventName, EventArgs $eventArgs = null)
5454
$initialized = isset($this->initialized[$eventName]);
5555

5656
foreach ($this->listeners[$eventName] as $hash => $listener) {
57-
if (!$initialized && is_string($listener)) {
57+
if (!$initialized && \is_string($listener)) {
5858
$this->listeners[$eventName][$hash] = $listener = $this->container->get($listener);
5959
}
6060

@@ -98,7 +98,7 @@ public function hasListeners($event)
9898
*/
9999
public function addEventListener($events, $listener)
100100
{
101-
if (is_string($listener)) {
101+
if (\is_string($listener)) {
102102
if ($this->initialized) {
103103
throw new \RuntimeException('Adding lazy-loading listeners after construction is not supported.');
104104
}
@@ -124,7 +124,7 @@ public function addEventListener($events, $listener)
124124
*/
125125
public function removeEventListener($events, $listener)
126126
{
127-
if (is_string($listener)) {
127+
if (\is_string($listener)) {
128128
$hash = '_service_'.$listener;
129129
} else {
130130
// Picks the hash code related to that listener

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ private function sanitizeQuery($connectionName, $query)
120120
if (null === $query['params']) {
121121
$query['params'] = array();
122122
}
123-
if (!is_array($query['params'])) {
123+
if (!\is_array($query['params'])) {
124124
$query['params'] = array($query['params']);
125125
}
126126
foreach ($query['params'] as $j => $param) {
127127
if (isset($query['types'][$j])) {
128128
// Transform the param according to the type
129129
$type = $query['types'][$j];
130-
if (is_string($type)) {
130+
if (\is_string($type)) {
131131
$type = Type::getType($type);
132132
}
133133
if ($type instanceof Type) {
@@ -158,11 +158,11 @@ private function sanitizeQuery($connectionName, $query)
158158
*/
159159
private function sanitizeParam($var)
160160
{
161-
if (is_object($var)) {
162-
return array(sprintf('Object(%s)', get_class($var)), false);
161+
if (\is_object($var)) {
162+
return array(sprintf('Object(%s)', \get_class($var)), false);
163163
}
164164

165-
if (is_array($var)) {
165+
if (\is_array($var)) {
166166
$a = array();
167167
$original = true;
168168
foreach ($var as $k => $v) {
@@ -174,7 +174,7 @@ private function sanitizeParam($var)
174174
return array($a, $original);
175175
}
176176

177-
if (is_resource($var)) {
177+
if (\is_resource($var)) {
178178
return array(sprintf('Resource(%s)', get_resource_type($var)), false);
179179
}
180180

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function setMappingDriverConfig(array $mappingConfig, $mappingName)
142142
*/
143143
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container)
144144
{
145-
$bundleDir = dirname($bundle->getFileName());
145+
$bundleDir = \dirname($bundle->getFileName());
146146

147147
if (!$bundleConfig['type']) {
148148
$bundleConfig['type'] = $this->detectMetadataDriver($bundleDir, $container);
@@ -154,7 +154,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
154154
}
155155

156156
if (!$bundleConfig['dir']) {
157-
if (in_array($bundleConfig['type'], array('annotation', 'staticphp'))) {
157+
if (\in_array($bundleConfig['type'], array('annotation', 'staticphp'))) {
158158
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
159159
} else {
160160
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
@@ -241,7 +241,7 @@ protected function assertValidMappingConfiguration(array $mappingConfig, $object
241241
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
242242
}
243243

244-
if (!in_array($mappingConfig['type'], array('xml', 'yml', 'annotation', 'php', 'staticphp'))) {
244+
if (!\in_array($mappingConfig['type'], array('xml', 'yml', 'annotation', 'php', 'staticphp'))) {
245245
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or '.
246246
'"staticphp" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. '.
247247
'You can register them by adding a new driver to the '.
@@ -264,17 +264,17 @@ protected function detectMetadataDriver($dir, ContainerBuilder $container)
264264
$configPath = $this->getMappingResourceConfigDirectory();
265265
$resource = $dir.'/'.$configPath;
266266
while (!is_dir($resource)) {
267-
$resource = dirname($resource);
267+
$resource = \dirname($resource);
268268
}
269269

270270
$container->addResource(new FileResource($resource));
271271

272272
$extension = $this->getMappingResourceExtension();
273-
if (($files = glob($dir.'/'.$configPath.'/*.'.$extension.'.xml')) && count($files)) {
273+
if (($files = glob($dir.'/'.$configPath.'/*.'.$extension.'.xml')) && \count($files)) {
274274
return 'xml';
275-
} elseif (($files = glob($dir.'/'.$configPath.'/*.'.$extension.'.yml')) && count($files)) {
275+
} elseif (($files = glob($dir.'/'.$configPath.'/*.'.$extension.'.yml')) && \count($files)) {
276276
return 'yml';
277-
} elseif (($files = glob($dir.'/'.$configPath.'/*.'.$extension.'.php')) && count($files)) {
277+
} elseif (($files = glob($dir.'/'.$configPath.'/*.'.$extension.'.php')) && \count($files)) {
278278
return 'php';
279279
}
280280

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/DoctrineValidationPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private function updateValidatorMappingFiles(ContainerBuilder $container, $mappi
6060

6161
foreach ($container->getParameter('kernel.bundles') as $bundle) {
6262
$reflection = new \ReflectionClass($bundle);
63-
if (is_file($file = dirname($reflection->getFileName()).'/'.$validationPath)) {
63+
if (is_file($file = \dirname($reflection->getFileName()).'/'.$validationPath)) {
6464
$files[] = $file;
6565
$container->addResource(new FileResource($file));
6666
}

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private function findAndSortTags($tagName, ContainerBuilder $container)
153153

154154
if ($sortedTags) {
155155
krsort($sortedTags);
156-
$sortedTags = call_user_func_array('array_merge', $sortedTags);
156+
$sortedTags = \call_user_func_array('array_merge', $sortedTags);
157157
}
158158

159159
return $sortedTags;

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function __construct($driver, array $namespaces, array $managerParameters
124124
$this->managerParameters = $managerParameters;
125125
$this->driverPattern = $driverPattern;
126126
$this->enabledParameter = $enabledParameter;
127-
if (count($aliasMap) && (!$configurationPattern || !$registerAliasMethodName)) {
127+
if (\count($aliasMap) && (!$configurationPattern || !$registerAliasMethodName)) {
128128
throw new \InvalidArgumentException('configurationPattern and registerAliasMethodName are required to register namespace alias');
129129
}
130130
$this->configurationPattern = $configurationPattern;
@@ -149,7 +149,7 @@ public function process(ContainerBuilder $container)
149149
$chainDriverDef->addMethodCall('addDriver', array($mappingDriverDef, $namespace));
150150
}
151151

152-
if (!count($this->aliasMap)) {
152+
if (!\count($this->aliasMap)) {
153153
return;
154154
}
155155

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function loadValuesForChoices(array $choices, $value = null)
8888

8989
// Optimize performance for single-field identifiers. We already
9090
// know that the IDs are used as values
91-
$optimize = null === $value || is_array($value) && $value[0] === $this->idReader;
91+
$optimize = null === $value || \is_array($value) && $value[0] === $this->idReader;
9292

9393
// Attention: This optimization does not check choices for existence
9494
if ($optimize && !$this->choiceList && $this->idReader->isSingleId()) {
@@ -125,7 +125,7 @@ public function loadChoicesForValues(array $values, $value = null)
125125

126126
// Optimize performance in case we have an object loader and
127127
// a single-field identifier
128-
$optimize = null === $value || is_array($value) && $value[0] === $this->idReader;
128+
$optimize = null === $value || \is_array($value) && $value[0] === $this->idReader;
129129

130130
if ($optimize && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
131131
$unorderedObjects = $this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values);

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function __construct(ObjectManager $manager, $class, $labelPath = null, E
117117
$this->entityLoader = $entityLoader;
118118
$this->classMetadata = $manager->getClassMetadata($class);
119119
$this->class = $this->classMetadata->getName();
120-
$this->loaded = is_array($entities) || $entities instanceof \Traversable;
120+
$this->loaded = \is_array($entities) || $entities instanceof \Traversable;
121121
$this->preferredEntities = $preferredEntities;
122122
list(
123123
$this->idAsIndex,
@@ -449,13 +449,13 @@ private function getIdentifierInfoForClass(ClassMetadata $classMetadata)
449449

450450
$identifiers = $classMetadata->getIdentifierFieldNames();
451451

452-
if (1 === count($identifiers)) {
452+
if (1 === \count($identifiers)) {
453453
$identifier = $identifiers[0];
454454

455455
if (!$classMetadata->hasAssociation($identifier)) {
456456
$idAsValue = true;
457457

458-
if (in_array($classMetadata->getTypeOfField($identifier), array('integer', 'smallint', 'bigint'))) {
458+
if (\in_array($classMetadata->getTypeOfField($identifier), array('integer', 'smallint', 'bigint'))) {
459459
$idAsIndex = true;
460460
}
461461
}

src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
4242

4343
$this->om = $om;
4444
$this->classMetadata = $classMetadata;
45-
$this->singleId = 1 === count($ids);
46-
$this->intId = $this->singleId && in_array($idType, array('integer', 'smallint', 'bigint'));
45+
$this->singleId = 1 === \count($ids);
46+
$this->intId = $this->singleId && \in_array($idType, array('integer', 'smallint', 'bigint'));
4747
$this->idField = current($ids);
4848

4949
// single field association are resolved, since the schema column could be an int
@@ -95,7 +95,7 @@ public function getIdValue($object)
9595
}
9696

9797
if (!$this->om->contains($object)) {
98-
throw new RuntimeException(sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', get_class($object)));
98+
throw new RuntimeException(sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', \get_class($object)));
9999
}
100100

101101
$this->om->initializeObject($object);

0 commit comments

Comments
 (0)