Skip to content

CS fixes native functions #32020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ return PhpCsFixer\Config::create()
'ordered_imports' => true,
'protected_to_private' => false,
// Part of @Symfony:risky in PHP-CS-Fixer 2.13.0. To be removed from the config file once upgrading
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true],
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
])
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function createTestConfiguration()
$config = new Configuration();
$config->setEntityNamespaces(['SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures']);
$config->setAutoGenerateProxyClasses(true);
$config->setProxyDir(\sys_get_temp_dir());
$config->setProxyDir(sys_get_temp_dir());
$config->setProxyNamespace('SymfonyTests\Doctrine');
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
$config->setQueryCacheImpl(new ArrayCache());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class,
return $this->formatValue($value, self::PRETTY_DATE);
}

if (\method_exists($value, '__toString')) {
if (method_exists($value, '__toString')) {
return (string) $value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
$instantiation = 'return';

if ($definition->isShared()) {
$instantiation .= sprintf(' $this->%s[%s] =', \method_exists(ContainerBuilder::class, 'addClassResource') || ($definition->isPublic() && !$definition->isPrivate()) ? 'services' : 'privates', var_export($id, true));
$instantiation .= sprintf(' $this->%s[%s] =', method_exists(ContainerBuilder::class, 'addClassResource') || ($definition->isPublic() && !$definition->isPrivate()) ? 'services' : 'privates', var_export($id, true));
}

if (null === $factoryCode) {
Expand Down Expand Up @@ -120,7 +120,7 @@ public function getProxyCode(Definition $definition)
*/
private static function getProxyManagerVersion()
{
if (!\class_exists(Version::class)) {
if (!class_exists(Version::class)) {
return '0.0.1';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getPrivatePublicDefinitions()
[
(new Definition(__CLASS__))
->setPublic(false),
\method_exists(ContainerBuilder::class, 'addClassResource') ? 'services' : 'privates',
method_exists(ContainerBuilder::class, 'addClassResource') ? 'services' : 'privates',
],
[
(new Definition(__CLASS__))
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testWithGlobals()

$display = $tester->getDisplay();

$this->assertContains(\json_encode($message), $display);
$this->assertContains(json_encode($message), $display);
}

public function testWithGlobalsJson()
Expand All @@ -81,7 +81,7 @@ public function testWithGlobalsJson()
$tester->execute(['--format' => 'json'], ['decorated' => true]);

$display = $tester->getDisplay();
$display = \json_decode($display, true);
$display = json_decode($display, true);

$this->assertSame($globals, $display['globals']);
}
Expand All @@ -91,11 +91,11 @@ public function testWithFilter()
$tester = $this->createCommandTester([]);
$tester->execute(['--format' => 'json'], ['decorated' => false]);
$display = $tester->getDisplay();
$display1 = \json_decode($display, true);
$display1 = json_decode($display, true);

$tester->execute(['filter' => 'date', '--format' => 'json'], ['decorated' => false]);
$display = $tester->getDisplay();
$display2 = \json_decode($display, true);
$display2 = json_decode($display, true);

$this->assertNotSame($display1, $display2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/UndefinedCallableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function onUndefinedFunction($name)

private static function onUndefined($name, $type, $component)
{
if (\class_exists(FullStack::class) && isset(self::$fullStackEnable[$component])) {
if (class_exists(FullStack::class) && isset(self::$fullStackEnable[$component])) {
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::$fullStackEnable[$component], $type, $name));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/PhpArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function warmUp(array $values)
if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) {
$value = serialize($value);
}
} elseif (!\is_scalar($value)) {
} elseif (!is_scalar($value)) {
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, \gettype($value)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/PhpFilesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function doSave(array $values, $lifetime)
if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) {
$value = serialize($value);
}
} elseif (!\is_scalar($value)) {
} elseif (!is_scalar($value)) {
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, \gettype($value)));
}

Expand Down
26 changes: 13 additions & 13 deletions src/Symfony/Component/Debug/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function loadClass($class)

private function checkClass($class, $file = null)
{
$exists = null === $file || \class_exists($class, false) || \interface_exists($class, false) || \trait_exists($class, false);
$exists = null === $file || class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false);

if (null !== $file && $class && '\\' === $class[0]) {
$class = substr($class, 1);
Expand All @@ -186,13 +186,13 @@ private function checkClass($class, $file = null)
}
$name = $refl->getName();

if ($name !== $class && 0 === \strcasecmp($name, $class)) {
if ($name !== $class && 0 === strcasecmp($name, $class)) {
throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: "%s" vs "%s".', $class, $name));
}

$deprecations = $this->checkAnnotations($refl, $name);

if (isset(self::$php7Reserved[\strtolower($refl->getShortName())])) {
if (isset(self::$php7Reserved[strtolower($refl->getShortName())])) {
$deprecations[] = sprintf('The "%s" class uses the reserved name "%s", it will break on PHP 7 and higher', $name, $refl->getShortName());
}

Expand Down Expand Up @@ -223,23 +223,23 @@ public function checkAnnotations(\ReflectionClass $refl, $class)
$deprecations = [];

// Don't trigger deprecations for classes in the same vendor
if (2 > $len = 1 + (\strpos($class, '\\') ?: \strpos($class, '_'))) {
if (2 > $len = 1 + (strpos($class, '\\') ?: strpos($class, '_'))) {
$len = 0;
$ns = '';
} else {
$ns = \str_replace('_', '\\', \substr($class, 0, $len));
$ns = str_replace('_', '\\', substr($class, 0, $len));
}

// Detect annotations on the class
if (false !== $doc = $refl->getDocComment()) {
foreach (['final', 'deprecated', 'internal'] as $annotation) {
if (false !== \strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
self::${$annotation}[$class] = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
}
}
}

$parent = \get_parent_class($class);
$parent = get_parent_class($class);
$parentAndOwnInterfaces = $this->getOwnInterfaces($class, $parent);
if ($parent) {
$parentAndOwnInterfaces[$parent] = $parent;
Expand All @@ -254,22 +254,22 @@ public function checkAnnotations(\ReflectionClass $refl, $class)
}

// Detect if the parent is annotated
foreach ($parentAndOwnInterfaces + \class_uses($class, false) as $use) {
foreach ($parentAndOwnInterfaces + class_uses($class, false) as $use) {
if (!isset(self::$checkedClasses[$use])) {
$this->checkClass($use);
}
if (isset(self::$deprecated[$use]) && \strncmp($ns, \str_replace('_', '\\', $use), $len) && !isset(self::$deprecated[$class])) {
if (isset(self::$deprecated[$use]) && strncmp($ns, str_replace('_', '\\', $use), $len) && !isset(self::$deprecated[$class])) {
$type = class_exists($class, false) ? 'class' : (interface_exists($class, false) ? 'interface' : 'trait');
$verb = class_exists($use, false) || interface_exists($class, false) ? 'extends' : (interface_exists($use, false) ? 'implements' : 'uses');

$deprecations[] = sprintf('The "%s" %s %s "%s" that is deprecated%s.', $class, $type, $verb, $use, self::$deprecated[$use]);
}
if (isset(self::$internal[$use]) && \strncmp($ns, \str_replace('_', '\\', $use), $len)) {
if (isset(self::$internal[$use]) && strncmp($ns, str_replace('_', '\\', $use), $len)) {
$deprecations[] = sprintf('The "%s" %s is considered internal%s. It may change without further notice. You should not use it from "%s".', $use, class_exists($use, false) ? 'class' : (interface_exists($use, false) ? 'interface' : 'trait'), self::$internal[$use], $class);
}
}

if (\trait_exists($class)) {
if (trait_exists($class)) {
return $deprecations;
}

Expand All @@ -296,7 +296,7 @@ public function checkAnnotations(\ReflectionClass $refl, $class)

if (isset(self::$internalMethods[$class][$method->name])) {
list($declaringClass, $message) = self::$internalMethods[$class][$method->name];
if (\strncmp($ns, $declaringClass, $len)) {
if (strncmp($ns, $declaringClass, $len)) {
$deprecations[] = sprintf('The "%s::%s()" method is considered internal%s. It may change without further notice. You should not extend it from "%s".', $declaringClass, $method->name, $message, $class);
}
}
Expand All @@ -307,7 +307,7 @@ public function checkAnnotations(\ReflectionClass $refl, $class)
}

foreach (['final', 'internal'] as $annotation) {
if (false !== \strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
$message = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
self::${$annotation.'Methods'}[$class][$method->name] = [$class, $message];
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,16 @@ private function getSchemeAndHierarchy($filename)
private static function box($func)
{
self::$lastError = null;
\set_error_handler(__CLASS__.'::handleError');
set_error_handler(__CLASS__.'::handleError');
try {
$result = \call_user_func_array($func, \array_slice(\func_get_args(), 1));
\restore_error_handler();
restore_error_handler();

return $result;
} catch (\Throwable $e) {
} catch (\Exception $e) {
}
\restore_error_handler();
restore_error_handler();

throw $e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ private function doAdvisoryLock($sessionId)
switch ($this->driver) {
case 'mysql':
// MySQL 5.7.5 and later enforces a maximum length on lock names of 64 characters. Previously, no limit was enforced.
$lockId = \substr($sessionId, 0, 64);
$lockId = substr($sessionId, 0, 64);
// should we handle the return value? 0 on timeout, null on error
// we use a timeout of 50 seconds which is also the default for innodb_lock_wait_timeout
$stmt = $this->pdo->prepare('SELECT GET_LOCK(:key, 50)');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function collect(Request $request, Response $response, \Exception $except
'token' => $response->headers->get('X-Debug-Token'),
'start_time' => $startTime * 1000,
'events' => [],
'stopwatch_installed' => \class_exists(Stopwatch::class, false),
'stopwatch_installed' => class_exists(Stopwatch::class, false),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ public function update(Response $response)
$maxAge = null;
$sMaxage = null;

if (\is_numeric($this->ageDirectives['max-age'])) {
if (is_numeric($this->ageDirectives['max-age'])) {
$maxAge = $this->ageDirectives['max-age'] + $this->age;
$response->headers->addCacheControlDirective('max-age', $maxAge);
}

if (\is_numeric($this->ageDirectives['s-maxage'])) {
if (is_numeric($this->ageDirectives['s-maxage'])) {
$sMaxage = $this->ageDirectives['s-maxage'] + $this->age;

if ($maxAge !== $sMaxage) {
$response->headers->addCacheControlDirective('s-maxage', $sMaxage);
}
}

if (\is_numeric($this->ageDirectives['expires'])) {
if (is_numeric($this->ageDirectives['expires'])) {
$date = clone $response->getDate();
$date->modify('+'.($this->ageDirectives['expires'] + $this->age).' seconds');
$response->setExpires($date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function handle(HttpKernelInterface $kernel, Request $request, $ty
// save global state related to trusted headers and proxies
$trustedProxies = Request::getTrustedProxies();
$trustedHeaderSet = Request::getTrustedHeaderSet();
if (\method_exists(Request::class, 'getTrustedHeaderName')) {
if (method_exists(Request::class, 'getTrustedHeaderName')) {
Request::setTrustedProxies($trustedProxies, -1);
$trustedHeaders = [
Request::HEADER_FORWARDED => Request::getTrustedHeaderName(Request::HEADER_FORWARDED, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function testCollect()

$c->collect($request, new Response());
$this->assertEquals(123456000, $c->getStartTime());
$this->assertSame(\class_exists(Stopwatch::class, false), $c->isStopwatchInstalled());
$this->assertSame(class_exists(Stopwatch::class, false), $c->isStopwatchInstalled());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function serialize()
{
$serialized = [$this->user, $this->authenticated, $this->roles, $this->attributes];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function serialize()
{
$serialized = [$this->secret, parent::serialize(true)];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function serialize()
{
$serialized = [$this->credentials, $this->providerKey, parent::serialize(true)];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function serialize()
{
$serialized = [$this->secret, $this->providerKey, parent::serialize(true)];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function serialize()
{
$serialized = [$this->credentials, $this->providerKey, parent::serialize(true)];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function isSupported()
return true;
}

if (\class_exists('ParagonIE_Sodium_Compat') && \method_exists('ParagonIE_Sodium_Compat', 'crypto_pwhash_is_available')) {
if (class_exists('ParagonIE_Sodium_Compat') && method_exists('ParagonIE_Sodium_Compat', 'crypto_pwhash_is_available')) {
return \ParagonIE_Sodium_Compat::crypto_pwhash_is_available();
}

Expand Down Expand Up @@ -66,8 +66,8 @@ public function isPasswordValid($encoded, $raw, $salt)
return !$this->isPasswordTooLong($raw) && password_verify($raw, $encoded);
}
if (\function_exists('sodium_crypto_pwhash_str_verify')) {
$valid = !$this->isPasswordTooLong($raw) && \sodium_crypto_pwhash_str_verify($encoded, $raw);
\sodium_memzero($raw);
$valid = !$this->isPasswordTooLong($raw) && sodium_crypto_pwhash_str_verify($encoded, $raw);
sodium_memzero($raw);

return $valid;
}
Expand All @@ -88,12 +88,12 @@ private function encodePasswordNative($raw)

private function encodePasswordSodiumFunction($raw)
{
$hash = \sodium_crypto_pwhash_str(
$hash = sodium_crypto_pwhash_str(
$raw,
\SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
\SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
);
\sodium_memzero($raw);
sodium_memzero($raw);

return $hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function serialize()
{
$serialized = [$this->user, parent::serialize(true)];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function serialize()
$this->line,
];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function serialize()
{
$serialized = [parent::serialize(true), $this->messageKey, $this->messageData];

return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
}

/**
Expand Down
Loading