Merge branch '3.4' into 4.3

* 3.4:
  Fix return statements
  [TwigBridge] add missing dep
  Add false type to ChoiceListFactoryInterface::createView $label argument
This commit is contained in:
Nicolas Grekas 2019-08-13 08:39:03 +02:00
commit 7d0795d0b8
58 changed files with 102 additions and 104 deletions

View File

@ -91,7 +91,7 @@ class IdReader
public function getIdValue($object)
{
if (!$object) {
return;
return null;
}
if (!$this->om->contains($object)) {

View File

@ -99,7 +99,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
$classMetadatas = $this->getMetadata($class);
if (!$classMetadatas) {
return;
return null;
}
/** @var ClassMetadataInfo $classMetadata */

View File

@ -68,7 +68,7 @@ class AppVariable
/**
* Returns the current user.
*
* @return mixed
* @return object|null
*
* @see TokenInterface::getUser()
*/
@ -79,7 +79,7 @@ class AppVariable
}
if (!$token = $tokenStorage->getToken()) {
return;
return null;
}
$user = $token->getUser();

View File

@ -22,6 +22,7 @@
},
"require-dev": {
"egulias/email-validator": "^2.0",
"fig/link-util": "^1.0",
"symfony/asset": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/finder": "~3.4|~4.0",

View File

@ -351,7 +351,7 @@ trait ControllerTrait
/**
* Get a user from the Security Token Storage.
*
* @return mixed
* @return object|null
*
* @throws \LogicException If SecurityBundle is not available
*
@ -366,12 +366,12 @@ trait ControllerTrait
}
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
return;
return null;
}
if (!\is_object($user = $token->getUser())) {
// e.g. anonymous authentication
return;
return null;
}
return $user;

View File

@ -40,7 +40,7 @@ class GlobalVariables
public function getToken()
{
if (!$this->container->has('security.token_storage')) {
return;
return null;
}
return $this->container->get('security.token_storage')->getToken();

View File

@ -126,7 +126,7 @@ class CodeHelper extends Helper
// Check if the file is an application/octet-stream (eg. Phar file) because highlight_file cannot parse these files
if ('application/octet-stream' === $finfo->file($file, FILEINFO_MIME_TYPE)) {
return;
return '';
}
}

View File

@ -533,7 +533,7 @@ abstract class Client
protected function createCrawlerFromContent($uri, $content, $type)
{
if (!class_exists('Symfony\Component\DomCrawler\Crawler')) {
return;
return null;
}
$crawler = new Crawler(null, $uri);

View File

@ -219,7 +219,7 @@ class XmlUtils
switch (true) {
case 'null' === $lowercaseValue:
return;
return null;
case ctype_digit($value):
$raw = $value;
$cast = (int) $value;

View File

@ -472,7 +472,7 @@ class Application
if (!$command->isEnabled()) {
$command->setApplication(null);
return;
return null;
}
if (null === $command->getDefinition()) {

View File

@ -155,7 +155,7 @@ class TokenStream
}
if ($next->isDelimiter(['*'])) {
return;
return null;
}
throw SyntaxErrorException::unexpectedToken('identifier or "*"', $next);

View File

@ -443,7 +443,7 @@ class ErrorHandler
self::$silencedErrorCache[$id][$message] = $errorAsException;
}
if (null === $lightTrace) {
return;
return true;
}
} else {
$errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);

View File

@ -33,11 +33,11 @@ class ClassNotFoundFatalErrorHandler implements FatalErrorHandlerInterface
$notFoundSuffix = '\' not found';
$notFoundSuffixLen = \strlen($notFoundSuffix);
if ($notFoundSuffixLen > $messageLen) {
return;
return null;
}
if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) {
return;
return null;
}
foreach (['class', 'interface', 'trait'] as $typeName) {

View File

@ -30,17 +30,17 @@ class UndefinedFunctionFatalErrorHandler implements FatalErrorHandlerInterface
$notFoundSuffix = '()';
$notFoundSuffixLen = \strlen($notFoundSuffix);
if ($notFoundSuffixLen > $messageLen) {
return;
return null;
}
if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) {
return;
return null;
}
$prefix = 'Call to undefined function ';
$prefixLen = \strlen($prefix);
if (0 !== strpos($error['message'], $prefix)) {
return;
return null;
}
$fullyQualifiedFunctionName = substr($error['message'], $prefixLen, -$notFoundSuffixLen);

View File

@ -28,7 +28,7 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface
{
preg_match('/^Call to undefined method (.*)::(.*)\(\)$/', $error['message'], $matches);
if (!$matches) {
return;
return null;
}
$className = $matches[1];

View File

@ -29,7 +29,7 @@ class ProxyHelper
$type = $r->getReturnType();
}
if (!$type) {
return;
return null;
}
if (!\is_string($type)) {
$name = $type->getName();
@ -45,7 +45,7 @@ class ProxyHelper
return $prefix.$name;
}
if (!$r instanceof \ReflectionMethod) {
return;
return null;
}
if ('self' === $lcName) {
return $prefix.$r->getDeclaringClass()->name;

View File

@ -414,12 +414,12 @@ class Filesystem
public function readlink($path, $canonicalize = false)
{
if (!$canonicalize && !is_link($path)) {
return;
return null;
}
if ($canonicalize) {
if (!$this->exists($path)) {
return;
return null;
}
if ('\\' === \DIRECTORY_SEPARATOR) {

View File

@ -78,14 +78,11 @@ interface ChoiceListFactoryInterface
* attributes that should be added to the respective choice.
*
* @param array|callable|null $preferredChoices The preferred choices
* @param callable|null $label The callable generating the
* choice labels
* @param callable|null $index The callable generating the
* view indices
* @param callable|null $groupBy The callable generating the
* group names
* @param array|callable|null $attr The callable generating the
* HTML attributes
* @param callable|false|null $label The callable generating the choice labels;
* pass false to discard the label
* @param callable|null $index The callable generating the view indices
* @param callable|null $groupBy The callable generating the group names
* @param array|callable|null $attr The callable generating the HTML attributes
*
* @return ChoiceListView The choice list view
*/

View File

@ -45,14 +45,14 @@ class BooleanToStringTransformer implements DataTransformerInterface
*
* @param bool $value Boolean value
*
* @return string String value
* @return string|null String value
*
* @throws TransformationFailedException if the given value is not a Boolean
*/
public function transform($value)
{
if (null === $value) {
return;
return null;
}
if (!\is_bool($value)) {

View File

@ -106,7 +106,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
*
* @param array $value Interval array
*
* @return \DateInterval Normalized date interval
* @return \DateInterval|null Normalized date interval
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the value could not be transformed
@ -114,13 +114,13 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
public function reverseTransform($value)
{
if (null === $value) {
return;
return null;
}
if (!\is_array($value)) {
throw new UnexpectedTypeException($value, 'array');
}
if ('' === implode('', $value)) {
return;
return null;
}
$emptyFields = [];
foreach ($this->fields as $field) {

View File

@ -62,7 +62,7 @@ class DateIntervalToStringTransformer implements DataTransformerInterface
*
* @param string $value An ISO 8601 or date string like date interval presentation
*
* @return \DateInterval An instance of \DateInterval
* @return \DateInterval|null An instance of \DateInterval
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the date interval could not be parsed
@ -70,13 +70,13 @@ class DateIntervalToStringTransformer implements DataTransformerInterface
public function reverseTransform($value)
{
if (null === $value) {
return;
return null;
}
if (!\is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
}
if ('' === $value) {
return;
return null;
}
if (!$this->isISO8601($value)) {
throw new TransformationFailedException('Non ISO 8601 date strings are not supported yet');

View File

@ -103,7 +103,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
*
* @param array $value Localized date
*
* @return \DateTime Normalized date
* @return \DateTime|null Normalized date
*
* @throws TransformationFailedException If the given value is not an array,
* if the value could not be transformed
@ -111,7 +111,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
public function reverseTransform($value)
{
if (null === $value) {
return;
return null;
}
if (!\is_array($value)) {
@ -119,7 +119,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
}
if ('' === implode('', $value)) {
return;
return null;
}
$emptyFields = [];

View File

@ -66,7 +66,7 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer
*
* @param string $dateTimeLocal Formatted string
*
* @return \DateTime Normalized date
* @return \DateTime|null Normalized date
*
* @throws TransformationFailedException If the given value is not a string,
* if the value could not be transformed
@ -78,7 +78,7 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer
}
if ('' === $dateTimeLocal) {
return;
return null;
}
// to maintain backwards compatibility we do not strictly validate the submitted date

View File

@ -99,7 +99,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
*
* @param string|array $value Localized date string/array
*
* @return \DateTime Normalized date
* @return \DateTime|null Normalized date
*
* @throws TransformationFailedException if the given value is not a string,
* if the date could not be parsed
@ -111,7 +111,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
}
if ('' === $value) {
return;
return null;
}
// date-only patterns require parsing to be done in UTC, as midnight might not exist in the local timezone due

View File

@ -53,7 +53,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
*
* @param string $rfc3339 Formatted string
*
* @return \DateTime Normalized date
* @return \DateTime|null Normalized date
*
* @throws TransformationFailedException If the given value is not a string,
* if the value could not be transformed
@ -65,7 +65,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
}
if ('' === $rfc3339) {
return;
return null;
}
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})T\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))$/', $rfc3339, $matches)) {

View File

@ -101,7 +101,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
*
* @param string $value A value as produced by PHP's date() function
*
* @return \DateTime An instance of \DateTime
* @return \DateTime|null An instance of \DateTime
*
* @throws TransformationFailedException If the given value is not a string,
* or could not be transformed
@ -109,7 +109,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
public function reverseTransform($value)
{
if (empty($value)) {
return;
return null;
}
if (!\is_string($value)) {

View File

@ -26,14 +26,14 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
*
* @param \DateTimeInterface $dateTime A DateTimeInterface object
*
* @return int A timestamp
* @return int|null A timestamp
*
* @throws TransformationFailedException If the given value is not a \DateTimeInterface
*/
public function transform($dateTime)
{
if (null === $dateTime) {
return;
return null;
}
if (!$dateTime instanceof \DateTimeInterface) {
@ -48,7 +48,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
*
* @param string $value A timestamp
*
* @return \DateTime A \DateTime object
* @return \DateTime|null A \DateTime object
*
* @throws TransformationFailedException If the given value is not a timestamp
* or if the given timestamp is invalid
@ -56,7 +56,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
public function reverseTransform($value)
{
if (null === $value) {
return;
return null;
}
if (!is_numeric($value)) {

View File

@ -145,7 +145,7 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
}
if ('' === $value) {
return;
return null;
}
if (\in_array($value, ['NaN', 'NAN', 'nan'], true)) {

View File

@ -112,7 +112,7 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
}
if ('' === $value) {
return;
return null;
}
$position = 0;

View File

@ -74,7 +74,7 @@ class ValueToDuplicatesTransformer implements DataTransformerInterface
if (\count($emptyKeys) > 0) {
if (\count($emptyKeys) == \count($this->keys)) {
// All keys empty
return;
return null;
}
throw new TransformationFailedException(sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)));

View File

@ -134,7 +134,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function getParent()
{
if ($this->length <= 1) {
return;
return null;
}
$parent = clone $this;

View File

@ -48,7 +48,7 @@ class ServerParams
$iniMax = strtolower($this->getNormalizedIniPostMaxSize());
if ('' === $iniMax) {
return;
return null;
}
$max = ltrim($iniMax, '+');

View File

@ -79,7 +79,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
}
if (!self::isSupported()) {
return;
return null;
}
ob_start();
@ -89,14 +89,14 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
if ($return > 0) {
ob_end_clean();
return;
return null;
}
$type = trim(ob_get_clean());
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) {
// it's not a type, but an error message
return;
return null;
}
return $match[1];

View File

@ -62,11 +62,11 @@ class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
}
if (!self::isSupported()) {
return;
return null;
}
if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) {
return;
return null;
}
return $finfo->file($path);

View File

@ -29,7 +29,7 @@ interface MimeTypeGuesserInterface
*
* @param string $path The path to the file
*
* @return string The mime type or NULL, if none could be guessed
* @return string|null The mime type or NULL, if none could be guessed
*
* @throws FileNotFoundException If the file does not exist
* @throws AccessDeniedException If the file could not be read

View File

@ -47,7 +47,7 @@ class RequestStack
public function pop()
{
if (!$this->requests) {
return;
return null;
}
return array_pop($this->requests);
@ -73,7 +73,7 @@ class RequestStack
public function getMasterRequest()
{
if (!$this->requests) {
return;
return null;
}
return $this->requests[0];
@ -95,7 +95,7 @@ class RequestStack
$pos = \count($this->requests) - 2;
if (!isset($this->requests[$pos])) {
return;
return null;
}
return $this->requests[$pos];

View File

@ -35,7 +35,7 @@ class SessionListener extends AbstractSessionListener
protected function getSession()
{
if (!$this->container->has('session')) {
return;
return null;
}
if ($this->container->has('session_storage')

View File

@ -33,7 +33,7 @@ class TestSessionListener extends AbstractTestSessionListener
protected function getSession()
{
if (!$this->container->has('session')) {
return;
return null;
}
return $this->container->get('session');

View File

@ -116,7 +116,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
public function read($token)
{
if (!$token || !file_exists($file = $this->getFilename($token))) {
return;
return null;
}
return $this->createProfileFromData($token, unserialize(file_get_contents($file)));
@ -227,7 +227,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
$position = ftell($file);
if (0 === $position) {
return;
return null;
}
while (true) {

View File

@ -143,7 +143,7 @@ class Profiler implements ResetInterface
public function collect(Request $request, Response $response, \Exception $exception = null)
{
if (false === $this->enabled) {
return;
return null;
}
$profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));

View File

@ -47,7 +47,7 @@ interface ProfilerStorageInterface
*
* @param string $token A token
*
* @return Profile The profile associated with token
* @return Profile|null The profile associated with token
*/
public function read($token);

View File

@ -79,7 +79,7 @@ class LocaleDataGenerator extends AbstractDataGenerator
// Don't generate aliases, as they are resolved during runtime
// Unless an alias is needed as fallback for de-duplication purposes
if (isset($this->localeAliases[$displayLocale]) && !$this->generatingFallback) {
return;
return null;
}
// Generate locale names for all locales that have translations in
@ -124,7 +124,7 @@ class LocaleDataGenerator extends AbstractDataGenerator
$data['Names'] = array_diff($data['Names'], $fallbackData['Names']);
}
if (!$data['Names']) {
return;
return null;
}
return $data;

View File

@ -42,7 +42,7 @@ class CurrencyBundle extends CurrencyDataProvider implements CurrencyBundleInter
try {
return $this->getSymbol($currency, $displayLocale);
} catch (MissingResourceException $e) {
return;
return null;
}
}
@ -54,7 +54,7 @@ class CurrencyBundle extends CurrencyDataProvider implements CurrencyBundleInter
try {
return $this->getName($currency, $displayLocale);
} catch (MissingResourceException $e) {
return;
return null;
}
}

View File

@ -54,7 +54,7 @@ class LanguageBundle extends LanguageDataProvider implements LanguageBundleInter
try {
return $this->getName($language, $displayLocale);
} catch (MissingResourceException $e) {
return;
return null;
}
}
@ -78,7 +78,7 @@ class LanguageBundle extends LanguageDataProvider implements LanguageBundleInter
try {
return $this->scriptProvider->getName($script, $displayLocale);
} catch (MissingResourceException $e) {
return;
return null;
}
}

View File

@ -43,7 +43,7 @@ class LocaleBundle extends LocaleDataProvider implements LocaleBundleInterface
try {
return $this->getName($locale, $displayLocale);
} catch (MissingResourceException $e) {
return;
return null;
}
}

View File

@ -42,7 +42,7 @@ class RegionBundle extends RegionDataProvider implements RegionBundleInterface
try {
return $this->getName($country, $displayLocale);
} catch (MissingResourceException $e) {
return;
return null;
}
}

View File

@ -83,7 +83,7 @@ class Version
}
if (!preg_match('/^'.$pattern.'/', $version, $matches)) {
return;
return null;
}
return $matches[0];

View File

@ -753,7 +753,7 @@ class Process implements \IteratorAggregate
public function getExitCodeText()
{
if (null === $exitcode = $this->getExitCode()) {
return;
return null;
}
return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error';

View File

@ -136,7 +136,7 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface
public function getParent()
{
if ($this->length <= 1) {
return;
return null;
}
$parent = clone $this;

View File

@ -40,7 +40,7 @@ interface PropertyPathInterface extends \Traversable
*
* If this property path only contains one item, null is returned.
*
* @return PropertyPath The parent path or null
* @return PropertyPath|null The parent path or null
*/
public function getParent();

View File

@ -73,7 +73,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
/** @var $docBlock DocBlock */
list($docBlock) = $this->getDocBlock($class, $property);
if (!$docBlock) {
return;
return null;
}
$shortDescription = $docBlock->getSummary();
@ -99,7 +99,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
/** @var $docBlock DocBlock */
list($docBlock) = $this->getDocBlock($class, $property);
if (!$docBlock) {
return;
return null;
}
$contents = $docBlock->getDescription()->render();
@ -115,7 +115,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
/** @var $docBlock DocBlock */
list($docBlock, $source, $prefix) = $this->getDocBlock($class, $property);
if (!$docBlock) {
return;
return null;
}
switch ($source) {
@ -141,7 +141,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
}
if (!isset($types[0])) {
return;
return null;
}
if (!\in_array($prefix, $this->arrayMutatorPrefixes)) {

View File

@ -80,7 +80,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
try {
$reflectionClass = new \ReflectionClass($class);
} catch (\ReflectionException $e) {
return;
return null;
}
$propertyFlags = 0;

View File

@ -36,11 +36,11 @@ class SerializerExtractor implements PropertyListExtractorInterface
public function getProperties($class, array $context = [])
{
if (!isset($context['serializer_groups']) || !\is_array($context['serializer_groups'])) {
return;
return null;
}
if (!$this->classMetadataFactory->getMetadataFor($class)) {
return;
return null;
}
$properties = [];

View File

@ -46,7 +46,7 @@ class AnnotationFileLoader extends FileLoader
* @param string $file A PHP file path
* @param string|null $type The resource type
*
* @return RouteCollection A RouteCollection instance
* @return RouteCollection|null A RouteCollection instance
*
* @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
*/
@ -58,7 +58,7 @@ class AnnotationFileLoader extends FileLoader
if ($class = $this->findClass($path)) {
$refl = new \ReflectionClass($class);
if ($refl->isAbstract()) {
return;
return null;
}
$collection->addResource(new FileResource($path));

View File

@ -88,7 +88,7 @@ class NativeSessionTokenStorage implements ClearableTokenStorageInterface
}
if (!isset($_SESSION[$this->namespace][$tokenId])) {
return;
return null;
}
$token = (string) $_SESSION[$this->namespace][$tokenId];

View File

@ -45,7 +45,7 @@ final class ParameterBagUtils
$root = substr($path, 0, $pos);
if (null === $value = $parameters->get($root)) {
return;
return null;
}
if (null === self::$propertyAccessor) {
@ -55,7 +55,7 @@ final class ParameterBagUtils
try {
return self::$propertyAccessor->getValue($value, substr($path, $pos));
} catch (AccessException $e) {
return;
return null;
}
}
@ -80,7 +80,7 @@ final class ParameterBagUtils
$root = substr($path, 0, $pos);
if (null === $value = $request->get($root)) {
return;
return null;
}
if (null === self::$propertyAccessor) {
@ -90,7 +90,7 @@ final class ParameterBagUtils
try {
return self::$propertyAccessor->getValue($value, substr($path, $pos));
} catch (AccessException $e) {
return;
return null;
}
}
}

View File

@ -82,7 +82,7 @@ class Regex extends Constraint
// Quit if delimiters not at very beginning/end (e.g. when options are passed)
if ($this->pattern[0] !== $this->pattern[\strlen($this->pattern) - 1]) {
return;
return null;
}
$delimiter = $this->pattern[0];

View File

@ -223,7 +223,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
$item = $item->value;
}
if (!($item = $this->getStub($item)) instanceof Stub || !$item->position) {
return;
return null;
}
$keys = [$key];
@ -238,7 +238,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
case Stub::TYPE_RESOURCE:
break;
default:
return;
return null;
}
$data = null;