Tweak the code to avoid fabbot false positives

This commit is contained in:
Fabien Potencier 2020-04-12 16:22:30 +02:00
parent a21c1127dc
commit ad6f75e5c8
24 changed files with 42 additions and 42 deletions

View File

@ -96,7 +96,7 @@ class DbalSessionHandler implements \SessionHandlerInterface
$stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$stmt->execute();
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Exception was thrown when trying to delete a session: %s.', $e->getMessage()), 0, $e);
throw new \RuntimeException('Exception was thrown when trying to delete a session: '.$e->getMessage(), 0, $e);
}
return true;
@ -115,7 +115,7 @@ class DbalSessionHandler implements \SessionHandlerInterface
$stmt->bindValue(':time', time() - $maxlifetime, \PDO::PARAM_INT);
$stmt->execute();
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Exception was thrown when trying to delete expired sessions: %s.', $e->getMessage()), 0, $e);
throw new \RuntimeException('Exception was thrown when trying to delete expired sessions: '.$e->getMessage(), 0, $e);
}
return true;
@ -142,7 +142,7 @@ class DbalSessionHandler implements \SessionHandlerInterface
return '';
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Exception was thrown when trying to read the session data: %s.', $e->getMessage()), 0, $e);
throw new \RuntimeException('Exception was thrown when trying to read the session data: '.$e->getMessage(), 0, $e);
}
}
@ -212,7 +212,7 @@ class DbalSessionHandler implements \SessionHandlerInterface
}
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Exception was thrown when trying to write the session data: %s.', $e->getMessage()), 0, $e);
throw new \RuntimeException('Exception was thrown when trying to write the session data: '.$e->getMessage(), 0, $e);
}
return true;

View File

@ -92,7 +92,7 @@ class EntityUserProvider implements UserProviderInterface
$refreshedUser = $repository->find($id);
if (null === $refreshedUser) {
throw new UsernameNotFoundException(sprintf('User with id %s not found.', json_encode($id)));
throw new UsernameNotFoundException('User with id '.json_encode($id).' not found.'));
}
}

View File

@ -99,7 +99,7 @@ EOF
}
if (!$socket = stream_socket_server($host, $errno, $errstr)) {
throw new RuntimeException(sprintf('Server start failed on "%s": %s %s.', $host, $errstr, $errno));
throw new RuntimeException(sprintf('Server start failed on "%s": '.$errstr.' '.$errno, $host));
}
foreach ($this->getLogs($socket) as $clientId => $message) {

View File

@ -59,7 +59,7 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
$this->manifestData = json_decode(file_get_contents($this->manifestPath), true);
if (0 < json_last_error()) {
throw new \RuntimeException(sprintf('Error parsing JSON from asset manifest file "%s" - %s.', $this->manifestPath, json_last_error_msg()));
throw new \RuntimeException(sprintf('Error parsing JSON from asset manifest file "%s": '.json_last_error_msg(), $this->manifestPath));
}
}

View File

@ -272,7 +272,7 @@ trait MemcachedTrait
return $result;
}
throw new CacheException(sprintf('MemcachedAdapter client error: %s.', strtolower($this->client->getResultMessage())));
throw new CacheException('MemcachedAdapter client error: '.strtolower($this->client->getResultMessage()));
}
/**

View File

@ -335,7 +335,7 @@ abstract class BaseNode implements NodeInterface
} catch (Exception $e) {
throw $e;
} catch (\Exception $e) {
throw new InvalidConfigurationException(sprintf('Invalid configuration for path "%s": %s.', $this->getPath(), $e->getMessage()), $e->getCode(), $e);
throw new InvalidConfigurationException(sprintf('Invalid configuration for path "%s": '.$e->getMessage(), $this->getPath()), $e->getCode(), $e);
}
}

View File

@ -126,7 +126,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
throw new RuntimeException(sprintf('Invalid service "%s": class "%s" does not exist.', $this->currentId, $class));
}
} catch (\ReflectionException $e) {
throw new RuntimeException(sprintf('Invalid service "%s": %s.', $this->currentId, lcfirst(rtrim($e->getMessage(), '.'))));
throw new RuntimeException(sprintf('Invalid service "%s": '.lcfirst($e->getMessage()), $this->currentId));
}
if (!$r = $r->getConstructor()) {
if ($required) {

View File

@ -660,7 +660,7 @@ class YamlFileLoader extends FileLoader
try {
$configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
} catch (ParseException $e) {
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: %s.', $file, $e->getMessage()), 0, $e);
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: '.$e->getMessage(), $file), 0, $e);
} finally {
restore_error_handler();
}

View File

@ -101,7 +101,7 @@ class Filesystem
if (!is_dir($dir)) {
// The directory was not created by a concurrent process. Let's throw an exception with a developer friendly error message if we have one
if (self::$lastError) {
throw new IOException(sprintf('Failed to create "%s": %s.', $dir, self::$lastError), 0, null, $dir);
throw new IOException(sprintf('Failed to create "%s": '.self::$lastError, $dir), 0, null, $dir);
}
throw new IOException(sprintf('Failed to create "%s".', $dir), 0, null, $dir);
}
@ -171,16 +171,16 @@ class Filesystem
if (is_link($file)) {
// See https://bugs.php.net/52176
if (!(self::box('unlink', $file) || '\\' !== \DIRECTORY_SEPARATOR || self::box('rmdir', $file)) && file_exists($file)) {
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, self::$lastError));
throw new IOException(sprintf('Failed to remove symlink "%s": '.self::$lastError, $file));
}
} elseif (is_dir($file)) {
$this->remove(new \FilesystemIterator($file, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS));
if (!self::box('rmdir', $file) && file_exists($file)) {
throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, self::$lastError));
throw new IOException(sprintf('Failed to remove directory "%s": '.self::$lastError, $file));
}
} elseif (!self::box('unlink', $file) && file_exists($file)) {
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, self::$lastError));
throw new IOException(sprintf('Failed to remove file "%s": '.self::$lastError, $file));
}
}
}

View File

@ -1031,7 +1031,7 @@ class Form implements \IteratorAggregate, FormInterface
$value = $transformer->transform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to transform data for property path "%s": %s', $this->getPropertyPath(), $exception->getMessage()), $exception->getCode(), $exception);
throw new TransformationFailedException(sprintf('Unable to transform data for property path "%s": '.$exception->getMessage(), $this->getPropertyPath()), $exception->getCode(), $exception);
}
return $value;
@ -1055,7 +1055,7 @@ class Form implements \IteratorAggregate, FormInterface
$value = $transformers[$i]->reverseTransform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to reverse value for property path "%s": %s', $this->getPropertyPath(), $exception->getMessage()), $exception->getCode(), $exception);
throw new TransformationFailedException(sprintf('Unable to reverse value for property path "%s": '.$exception->getMessage(), $this->getPropertyPath()), $exception->getCode(), $exception);
}
return $value;
@ -1086,7 +1086,7 @@ class Form implements \IteratorAggregate, FormInterface
$value = $transformer->transform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to transform value for property path "%s": %s', $this->getPropertyPath(), $exception->getMessage()), $exception->getCode(), $exception);
throw new TransformationFailedException(sprintf('Unable to transform value for property path "%s": '.$exception->getMessage(), $this->getPropertyPath()), $exception->getCode(), $exception);
}
return $value;
@ -1112,7 +1112,7 @@ class Form implements \IteratorAggregate, FormInterface
$value = $transformers[$i]->reverseTransform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to reverse value for property path "%s": %s', $this->getPropertyPath(), $exception->getMessage()), $exception->getCode(), $exception);
throw new TransformationFailedException(sprintf('Unable to reverse value for property path "%s": '.$exception->getMessage(), $this->getPropertyPath()), $exception->getCode(), $exception);
}
return $value;

View File

@ -88,7 +88,7 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
try {
$callable = $this->createController($controller);
} catch (\InvalidArgumentException $e) {
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s.', $request->getPathInfo(), $e->getMessage()), 0, $e);
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable: '.$e->getMessage(), $request->getPathInfo()), 0, $e);
}
return $callable;

View File

@ -46,7 +46,7 @@ class JsonBundleReader implements BundleReaderInterface
$data = json_decode(file_get_contents($fileName), true);
if (null === $data) {
throw new RuntimeException(sprintf('The resource bundle "%s" contains invalid JSON: %s.', $fileName, json_last_error_msg()));
throw new RuntimeException(sprintf('The resource bundle "%s" contains invalid JSON: '.json_last_error_msg(), $fileName));
}
return $data;

View File

@ -48,7 +48,7 @@ class Collection implements CollectionInterface
return $count;
}
throw new LdapException(sprintf('Error while retrieving entry count: %s.', ldap_error($this->connection->getResource())));
throw new LdapException('Error while retrieving entry count: '.ldap_error($this->connection->getResource()));
}
public function getIterator()
@ -62,7 +62,7 @@ class Collection implements CollectionInterface
}
if (false === $current) {
throw new LdapException(sprintf('Could not rewind entries array: %s.', ldap_error($con)));
throw new LdapException('Could not rewind entries array: '.ldap_error($con));
}
yield $this->getSingleEntry($con, $current);
@ -105,7 +105,7 @@ class Collection implements CollectionInterface
$attributes = ldap_get_attributes($con, $current);
if (false === $attributes) {
throw new LdapException(sprintf('Could not fetch attributes: %s.', ldap_error($con)));
throw new LdapException('Could not fetch attributes: '.ldap_error($con));
}
$attributes = $this->cleanupAttributes($attributes);
@ -113,7 +113,7 @@ class Collection implements CollectionInterface
$dn = ldap_get_dn($con, $current);
if (false === $dn) {
throw new LdapException(sprintf('Could not fetch DN: %s.', ldap_error($con)));
throw new LdapException('Could not fetch DN: '.ldap_error($con));
}
return new Entry($dn, $attributes);

View File

@ -138,11 +138,11 @@ class Connection extends AbstractConnection
}
if (false === $this->connection) {
throw new LdapException(sprintf('Could not connect to Ldap server: %s.', ldap_error($this->connection)));
throw new LdapException('Could not connect to Ldap server: '.ldap_error($this->connection));
}
if ('tls' === $this->config['encryption'] && false === @ldap_start_tls($this->connection)) {
throw new LdapException(sprintf('Could not initiate TLS connection: %s.', ldap_error($this->connection)));
throw new LdapException('Could not initiate TLS connection: '.ldap_error($this->connection));
}
}

View File

@ -38,7 +38,7 @@ class EntryManager implements EntryManagerInterface, RenameEntryInterface
$con = $this->getConnectionResource();
if (!@ldap_add($con, $entry->getDn(), $entry->getAttributes())) {
throw new LdapException(sprintf('Could not add entry "%s": %s.', $entry->getDn(), ldap_error($con)));
throw new LdapException(sprintf('Could not add entry "%s": '.ldap_error($con), $entry->getDn()));
}
return $this;
@ -52,7 +52,7 @@ class EntryManager implements EntryManagerInterface, RenameEntryInterface
$con = $this->getConnectionResource();
if (!@ldap_modify($con, $entry->getDn(), $entry->getAttributes())) {
throw new LdapException(sprintf('Could not update entry "%s": %s.', $entry->getDn(), ldap_error($con)));
throw new LdapException(sprintf('Could not update entry "%s": '.ldap_error($con), $entry->getDn()));
}
}
@ -64,7 +64,7 @@ class EntryManager implements EntryManagerInterface, RenameEntryInterface
$con = $this->getConnectionResource();
if (!@ldap_delete($con, $entry->getDn())) {
throw new LdapException(sprintf('Could not remove entry "%s": %s.', $entry->getDn(), ldap_error($con)));
throw new LdapException(sprintf('Could not remove entry "%s": '.ldap_error($con), $entry->getDn()));
}
}
@ -76,7 +76,7 @@ class EntryManager implements EntryManagerInterface, RenameEntryInterface
$con = $this->getConnectionResource();
if (!@ldap_rename($con, $entry->getDn(), $newRdn, null, $removeOldRdn)) {
throw new LdapException(sprintf('Could not rename entry "%s" to "%s": %s.', $entry->getDn(), $newRdn, ldap_error($con)));
throw new LdapException(sprintf('Could not rename entry "%s" to "%s": '.ldap_error($con), $entry->getDn(), $newRdn));
}
}

View File

@ -45,7 +45,7 @@ class Query extends AbstractQuery
$this->search = null;
if (!$success) {
throw new LdapException(sprintf('Could not free results: %s.', ldap_error($con)));
throw new LdapException('Could not free results: '.ldap_error($con));
}
}

View File

@ -57,7 +57,7 @@ class WindowsPipes extends AbstractPipes
if (!$h = fopen($file.'.lock', 'w')) {
restore_error_handler();
throw new RuntimeException(sprintf('A temporary file could not be opened to write the process output: %s.', $lastError));
throw new RuntimeException('A temporary file could not be opened to write the process output: '.$lastError);
}
if (!flock($h, LOCK_EX | LOCK_NB)) {
continue 2;

View File

@ -71,10 +71,10 @@ class EncoderFactory implements EncoderFactoryInterface
$config = $this->getEncoderConfigFromAlgorithm($config);
}
if (!isset($config['class'])) {
throw new \InvalidArgumentException(sprintf('"class" must be set in %s.', json_encode($config)));
throw new \InvalidArgumentException('"class" must be set in '.json_encode($config));
}
if (!isset($config['arguments'])) {
throw new \InvalidArgumentException(sprintf('"arguments" must be set in %s.', json_encode($config)));
throw new \InvalidArgumentException('"arguments" must be set in '.json_encode($config));
}
$reflection = new \ReflectionClass($config['class']);

View File

@ -431,7 +431,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
return $this->appendNode($parentNode, $data, 'data');
}
throw new NotEncodableValueException(sprintf('An unexpected value could not be serialized: %s.', !\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
throw new NotEncodableValueException('An unexpected value could not be serialized: '.(!\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
}
/**

View File

@ -164,7 +164,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
throw new NotNormalizableValueException(sprintf('Could not normalize object of type "%s", no supporting normalizer found.', \get_class($data)));
}
throw new NotNormalizableValueException(sprintf('An unexpected value could not be normalized: %s.', !\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
throw new NotNormalizableValueException('An unexpected value could not be normalized: '.(!\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
}
/**

View File

@ -30,7 +30,7 @@ class JsonFileLoader extends FileLoader
$messages = json_decode($data, true);
if (0 < $errorCode = json_last_error()) {
throw new InvalidResourceException(sprintf('Error parsing JSON - %s.', $this->getJSONErrorMessage($errorCode)));
throw new InvalidResourceException('Error parsing JSON: '.$this->getJSONErrorMessage($errorCode));
}
}

View File

@ -53,7 +53,7 @@ class XliffFileLoader implements LoaderInterface
try {
$dom = XmlUtils::loadFile($resource);
} catch (\InvalidArgumentException $e) {
throw new InvalidResourceException(sprintf('Unable to load "%s": %s.', $resource, $e->getMessage()), $e->getCode(), $e);
throw new InvalidResourceException(sprintf('Unable to load "%s": '.$e->getMessage(), $resource), $e->getCode(), $e);
}
$xliffVersion = $this->getVersionNumber($dom);
@ -194,7 +194,7 @@ class XliffFileLoader implements LoaderInterface
if (!@$dom->schemaValidateSource($schema)) {
libxml_disable_entity_loader($disableEntities);
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s.', $file, implode("\n", $this->getXmlErrors($internalErrors))));
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: '.implode("\n", $this->getXmlErrors($internalErrors)), $file));
}
libxml_disable_entity_loader($disableEntities);

View File

@ -55,7 +55,7 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
try {
$comparedValue = $this->getPropertyAccessor()->getValue($object, $path);
} catch (NoSuchPropertyException $e) {
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: %s.', $path, \get_class($constraint), $e->getMessage()), 0, $e);
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: '.$e->getMessage(), $path, \get_class($constraint)), 0, $e);
}
} else {
$comparedValue = $constraint->value;

View File

@ -40,7 +40,7 @@ class CallbackValidator extends ConstraintValidator
if (isset($method[0]) && \is_object($method[0])) {
$method[0] = \get_class($method[0]);
}
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable.', json_encode($method)));
throw new ConstraintDefinitionException(json_encode($method).' targeted by Callback constraint is not a valid callable.');
}
\call_user_func($method, $object, $this->context, $constraint->payload);