Tweak the code to avoid fabbot false positives

This commit is contained in:
Fabien Potencier 2020-04-12 18:10:21 +02:00
parent 11a707200d
commit 7d2cab1644
27 changed files with 39 additions and 39 deletions

View File

@ -102,7 +102,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

@ -96,7 +96,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
try {
$options = $this->getOptionsResolver()->resolve($options);
} catch (ExceptionInterface $e) {
throw new $e(sprintf('An error has occurred resolving the options of the form "%s": %s.', \get_class($this->getInnerType()), $e->getMessage()), $e->getCode(), $e);
throw new $e(sprintf('An error has occurred resolving the options of the form "%s": '.$e->getMessage(), \get_class($this->getInnerType())), $e->getCode(), $e);
}
// Should be decoupled from the specific option at some point

View File

@ -343,11 +343,11 @@ trait HttpClientTrait
try {
$value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0), $maxDepth);
} catch (\JsonException $e) {
throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
throw new InvalidArgumentException('Invalid value for "json" option: '.$e->getMessage());
}
if (\PHP_VERSION_ID < 70300 && JSON_ERROR_NONE !== json_last_error() && (false === $value || !($flags & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', json_last_error_msg()));
throw new InvalidArgumentException('Invalid value for "json" option: '.json_last_error_msg());
}
return $value;

View File

@ -153,11 +153,11 @@ trait ResponseTrait
try {
$content = json_decode($content, true, 512, JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0));
} catch (\JsonException $e) {
throw new JsonException(sprintf('%s for "%s".', $e->getMessage(), $this->getInfo('url')), $e->getCode());
throw new JsonException(sprintf($e->getMessage().' for "%s".', $this->getInfo('url')), $e->getCode());
}
if (\PHP_VERSION_ID < 70300 && JSON_ERROR_NONE !== json_last_error()) {
throw new JsonException(sprintf('%s for "%s".', json_last_error_msg(), $this->getInfo('url')), json_last_error());
throw new JsonException(sprintf(json_last_error_msg().' for "%s".', $this->getInfo('url')), json_last_error());
}
if (!\is_array($content)) {

View File

@ -64,7 +64,7 @@ class ControllerResolver implements ControllerResolverInterface
}
if (!\is_callable($controller)) {
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s.', $request->getPathInfo(), $this->getControllerError($controller)));
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable: '.$this->getControllerError($controller), $request->getPathInfo()));
}
return $controller;
@ -72,7 +72,7 @@ class ControllerResolver implements ControllerResolverInterface
if (\is_object($controller)) {
if (!\is_callable($controller)) {
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s.', $request->getPathInfo(), $this->getControllerError($controller)));
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable: '.$this->getControllerError($controller), $request->getPathInfo()));
}
return $controller;
@ -89,7 +89,7 @@ class ControllerResolver implements ControllerResolverInterface
}
if (!\is_callable($callable)) {
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s.', $request->getPathInfo(), $this->getControllerError($callable)));
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable: '.$this->getControllerError($callable), $request->getPathInfo()));
}
return $callable;

View File

@ -53,7 +53,7 @@ class Collection implements CollectionInterface
foreach ($searches as $search) {
$searchCount = ldap_count_entries($con, $search);
if (false === $searchCount) {
throw new LdapException(sprintf('Error while retrieving entry count: %s.', ldap_error($con)));
throw new LdapException('Error while retrieving entry count: '.ldap_error($con));
}
$count += $searchCount;
}
@ -76,7 +76,7 @@ class Collection implements CollectionInterface
$current = ldap_first_entry($con, $search);
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);

View File

@ -79,7 +79,7 @@ class EntryManager implements EntryManagerInterface
$con = $this->getConnectionResource();
if (!@ldap_mod_add($con, $entry->getDn(), [$attribute => $values])) {
throw new LdapException(sprintf('Could not add values to entry "%s", attribute %s: %s.', $entry->getDn(), $attribute, ldap_error($con)));
throw new LdapException(sprintf('Could not add values to entry "%s", attribute %s: '.ldap_error($con), $entry->getDn(), $attribute));
}
}
@ -94,7 +94,7 @@ class EntryManager implements EntryManagerInterface
$con = $this->getConnectionResource();
if (!@ldap_mod_del($con, $entry->getDn(), [$attribute => $values])) {
throw new LdapException(sprintf('Could not remove values from entry "%s", attribute %s: %s.', $entry->getDn(), $attribute, ldap_error($con)));
throw new LdapException(sprintf('Could not remove values from entry "%s", attribute %s: '.ldap_error($con), $entry->getDn(), $attribute));
}
}
@ -122,7 +122,7 @@ class EntryManager implements EntryManagerInterface
$rdn = $this->parseRdnFromEntry($entry);
// deleteOldRdn does not matter here, since the Rdn will not be changing in the move.
if (!@ldap_rename($con, $entry->getDn(), $rdn, $newParent, true)) {
throw new LdapException(sprintf('Could not move entry "%s" to "%s": %s.', $entry->getDn(), $newParent, ldap_error($con)));
throw new LdapException(sprintf('Could not move entry "%s" to "%s": '.ldap_error($con), $entry->getDn(), $newParent));
}
}

View File

@ -65,7 +65,7 @@ class SesApiTransport extends AbstractApiTransport
$result = new \SimpleXMLElement($response->getContent(false));
if (200 !== $response->getStatusCode()) {
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $result->Error->Message, $result->Error->Code), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$result->Error->Message.' (code %d).', $result->Error->Code), $response);
}
$property = $payload['Action'].'Result';

View File

@ -65,7 +65,7 @@ class SesHttpTransport extends AbstractHttpTransport
$result = new \SimpleXMLElement($response->getContent(false));
if (200 !== $response->getStatusCode()) {
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $result->Error->Message, $result->Error->Code), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$result->Error->Message.' (code %d).', $result->Error->Code), $response);
}
$message->setMessageId($result->SendRawEmailResult->MessageId);

View File

@ -51,7 +51,7 @@ class MandrillApiTransport extends AbstractApiTransport
$result = $response->toArray(false);
if (200 !== $response->getStatusCode()) {
if ('error' === ($result['status'] ?? false)) {
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $result['message'], $result['code']), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$result['message'].' (code %d).', $result['code']), $response);
}
throw new HttpTransportException(sprintf('Unable to send an email (code %d).', $result['code']), $response);

View File

@ -58,7 +58,7 @@ class MandrillHttpTransport extends AbstractHttpTransport
$result = $response->toArray(false);
if (200 !== $response->getStatusCode()) {
if ('error' === ($result['status'] ?? false)) {
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $result['message'], $result['code']), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$result['message'].' (code %d).', $result['code']), $response);
}
throw new HttpTransportException(sprintf('Unable to send an email (code %d).', $result['code']), $response);

View File

@ -65,10 +65,10 @@ class MailgunApiTransport extends AbstractApiTransport
$result = $response->toArray(false);
if (200 !== $response->getStatusCode()) {
if ('application/json' === $response->getHeaders(false)['content-type'][0]) {
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $result['message'], $response->getStatusCode()), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$result['message'].' (code %d).', $response->getStatusCode()), $response);
}
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $response->getContent(false), $response->getStatusCode()), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$response->getContent(false).' (code %d).', $response->getStatusCode()), $response);
}
$sentMessage->setMessageId($result['id']);

View File

@ -67,10 +67,10 @@ class MailgunHttpTransport extends AbstractHttpTransport
$result = $response->toArray(false);
if (200 !== $response->getStatusCode()) {
if ('application/json' === $response->getHeaders(false)['content-type'][0]) {
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $result['message'], $response->getStatusCode()), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$result['message'].' (code %d).', $response->getStatusCode()), $response);
}
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $response->getContent(false), $response->getStatusCode()), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$response->getContent(false).' (code %d).', $response->getStatusCode()), $response);
}
$message->setMessageId($result['id']);

View File

@ -54,7 +54,7 @@ class PostmarkApiTransport extends AbstractApiTransport
$result = $response->toArray(false);
if (200 !== $response->getStatusCode()) {
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', $result['Message'], $result['ErrorCode']), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.$result['Message'].' (code %d).', $result['ErrorCode']), $response);
}
$sentMessage->setMessageId($result['MessageID']);

View File

@ -53,7 +53,7 @@ class SendgridApiTransport extends AbstractApiTransport
if (202 !== $response->getStatusCode()) {
$errors = $response->toArray(false);
throw new HttpTransportException(sprintf('Unable to send an email: %s (code %d).', implode('; ', array_column($errors['errors'], 'message')), $response->getStatusCode()), $response);
throw new HttpTransportException(sprintf('Unable to send an email: '.implode('; ', array_column($errors['errors'], 'message')).' (code %d).', $response->getStatusCode()), $response);
}
$sentMessage->setMessageId($response->getHeaders(false)['x-message-id'][0]);

View File

@ -31,7 +31,7 @@ abstract class AbstractApiTransport extends AbstractHttpTransport
try {
$email = MessageConverter::toEmail($message->getOriginalMessage());
} catch (\Exception $e) {
throw new RuntimeException(sprintf('Unable to send message with the "%s" transport: %s.', __CLASS__, $e->getMessage()), 0, $e);
throw new RuntimeException(sprintf('Unable to send message with the "%s" transport: '.$e->getMessage(), __CLASS__), 0, $e);
}
return $this->doSendApi($message, $email, $message->getEnvelope());

View File

@ -41,7 +41,7 @@ final class ProcessStream extends AbstractStream
$this->stream = proc_open($this->command, $descriptorSpec, $pipes);
stream_set_blocking($pipes[2], false);
if ($err = stream_get_contents($pipes[2])) {
throw new TransportException(sprintf('Process could not be started: %s.', $err));
throw new TransportException('Process could not be started: '.$err);
}
$this->in = &$pipes[0];
$this->out = &$pipes[1];

View File

@ -135,7 +135,7 @@ final class SocketStream extends AbstractStream
$streamContext = stream_context_create($options);
set_error_handler(function ($type, $msg) {
throw new TransportException(sprintf('Connection could not be established with host "%s": %s.', $this->url, $msg));
throw new TransportException(sprintf('Connection could not be established with host "%s": '.$msg, $this->url));
});
try {
$this->stream = stream_socket_client($this->url, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $streamContext);

View File

@ -56,11 +56,11 @@ class Connection
$this->connection->setOption(\Redis::OPT_SERIALIZER, $redisOptions['serializer'] ?? \Redis::SERIALIZER_PHP);
if (isset($connectionCredentials['auth']) && !$this->connection->auth($connectionCredentials['auth'])) {
throw new InvalidArgumentException(sprintf('Redis connection failed: %s.', $redis->getLastError()));
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
}
if (($dbIndex = $configuration['dbindex'] ?? self::DEFAULT_OPTIONS['dbindex']) && !$this->connection->select($dbIndex)) {
throw new InvalidArgumentException(sprintf('Redis connection failed: %s.', $redis->getLastError()));
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
}
$this->stream = $configuration['stream'] ?? self::DEFAULT_OPTIONS['stream'];

View File

@ -80,7 +80,7 @@ class Serializer implements SerializerInterface
try {
$message = $this->serializer->deserialize($encodedEnvelope['body'], $encodedEnvelope['headers']['type'], $this->format, $context);
} catch (ExceptionInterface $e) {
throw new MessageDecodingFailedException(sprintf('Could not decode message: %s.', $e->getMessage()), $e->getCode(), $e);
throw new MessageDecodingFailedException('Could not decode message: '.$e->getMessage(), $e->getCode(), $e);
}
return new Envelope($message, $stamps);
@ -118,7 +118,7 @@ class Serializer implements SerializerInterface
try {
$stamps[] = $this->serializer->deserialize($value, substr($name, \strlen(self::STAMP_HEADER_PREFIX)).'[]', $this->format, $this->context);
} catch (ExceptionInterface $e) {
throw new MessageDecodingFailedException(sprintf('Could not decode stamp: %s.', $e->getMessage()), $e->getCode(), $e);
throw new MessageDecodingFailedException('Could not decode stamp: '.$e->getMessage(), $e->getCode(), $e);
}
}
if ($stamps) {

View File

@ -1648,7 +1648,7 @@ class Process implements \IteratorAggregate
{
return preg_replace_callback('/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function ($matches) use ($commandline, $env) {
if (!isset($env[$matches[1]]) || false === $env[$matches[1]]) {
throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": %s.', $matches[1], $commandline));
throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": '.$commandline, $matches[1]));
}
return $this->escapeArgument($env[$matches[1]]);

View File

@ -359,7 +359,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
try {
$this->setAttributeValue($object, $attribute, $value, $format, $context);
} catch (InvalidArgumentException $e) {
throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": %s.', $attribute, $type, $e->getMessage()), $e->getCode(), $e);
throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type), $e->getCode(), $e);
}
}

View File

@ -40,7 +40,7 @@ class IntlFormatter implements IntlFormatterInterface
try {
$this->cache[$locale][$message] = $formatter = new \MessageFormatter($locale, $message);
} catch (\IntlException $e) {
throw new InvalidArgumentException(sprintf('Invalid message format (error #%d): %s.', intl_get_error_code(), intl_get_error_message()), 0, $e);
throw new InvalidArgumentException(sprintf('Invalid message format (error #%d): '.intl_get_error_message(), intl_get_error_code()), 0, $e);
}
}
@ -52,7 +52,7 @@ class IntlFormatter implements IntlFormatterInterface
}
if (false === $message = $formatter->format($parameters)) {
throw new InvalidArgumentException(sprintf('Unable to format message (error #%s): %s.', $formatter->getErrorCode(), $formatter->getErrorMessage()));
throw new InvalidArgumentException(sprintf('Unable to format message (error #%s): '.$formatter->getErrorMessage(), $formatter->getErrorCode()));
}
return $message;

View File

@ -58,7 +58,7 @@ class XliffFileLoader implements LoaderInterface
$xliffVersion = XliffUtils::getVersionNumber($dom);
if ($errors = XliffUtils::validateSchema($dom)) {
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s.', $resource, XliffUtils::getErrorsAsString($errors)));
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: '.XliffUtils::getErrorsAsString($errors), $resource));
}
if ('1.2' === $xliffVersion) {

View File

@ -138,7 +138,7 @@ class BicValidator extends ConstraintValidator
try {
$iban = $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);
}
}
if (!$iban) {

View File

@ -157,7 +157,7 @@ class RangeValidator extends ConstraintValidator
try {
return $this->getPropertyAccessor()->getValue($object, $propertyPath);
} catch (NoSuchPropertyException $e) {
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: %s.', $propertyPath, \get_class($constraint), $e->getMessage()), 0, $e);
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: '.$e->getMessage(), $propertyPath, \get_class($constraint)), 0, $e);
}
}

View File

@ -41,7 +41,7 @@ class DumpServer
public function start(): void
{
if (!$this->socket = stream_socket_server($this->host, $errno, $errstr)) {
throw new \RuntimeException(sprintf('Server start failed on "%s": %s %s.', $this->host, $errstr, $errno));
throw new \RuntimeException(sprintf('Server start failed on "%s": '.$errstr.' '.$errno, $this->host));
}
}