Merge branch '3.4' into 4.3

* 3.4:
  Fix inconsistent return points.
  [Security/Core] UserInterface::getPassword() can return null
  [Router] Fix TraceableUrlMatcher behaviour with trailing slash
This commit is contained in:
Nicolas Grekas 2019-08-20 15:44:39 +02:00
commit aefbc93a07
98 changed files with 341 additions and 169 deletions

View File

@ -127,6 +127,8 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
return new ValueGuess(!$mapping['joinColumns'][0]['nullable'], Guess::HIGH_CONFIDENCE);
}
return null;
}
/**
@ -146,6 +148,8 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}
return null;
}
/**
@ -159,6 +163,8 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}
return null;
}
protected function getMetadata($class)
@ -180,6 +186,8 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
// not an entity or mapped super class, using Doctrine ORM 2.2
}
}
return null;
}
private static function getRealClass(string $class): string

View File

@ -160,6 +160,8 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
return $doctrineChoiceLoader;
}
return null;
};
$choiceName = function (Options $options) {
@ -171,6 +173,7 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
}
// Otherwise, an incrementing integer is used as name automatically
return null;
};
// The choices are always indexed by ID (see "choices" normalizer
@ -184,6 +187,7 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
}
// Otherwise, an incrementing integer is used as value automatically
return null;
};
$emNormalizer = function (Options $options, $em) {

View File

@ -47,7 +47,7 @@ class DoctrineFooType extends Type
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (null === $value) {
return;
return null;
}
if (!$value instanceof Foo) {
throw new ConversionException(sprintf('Expected %s, got %s', 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\Foo', \gettype($value)));
@ -62,7 +62,7 @@ class DoctrineFooType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (null === $value) {
return;
return null;
}
if (!\is_string($value)) {
throw ConversionException::conversionFailed($value, self::NAME);

View File

@ -26,6 +26,8 @@ class ClockMock
}
self::$now = is_numeric($enable) ? (float) $enable : ($enable ? microtime(true) : null);
return null;
}
public static function time()
@ -55,6 +57,8 @@ class ClockMock
}
self::$now += $us / 1000000;
return null;
}
public static function microtime($asFloat = false)

View File

@ -95,11 +95,7 @@ class CoverageListenerTrait
$sutFqcn = str_replace('\\Tests\\', '\\', $class);
$sutFqcn = preg_replace('{Test$}', '', $sutFqcn);
if (!class_exists($sutFqcn)) {
return;
}
return $sutFqcn;
return class_exists($sutFqcn) ? $sutFqcn : null;
}
public function __sleep()

View File

@ -341,6 +341,8 @@ class SymfonyTestsListenerTrait
$msg = 'Unsilenced deprecation: '.$msg;
}
$this->gatheredDeprecations[] = $msg;
return null;
}
/**

View File

@ -168,7 +168,7 @@ $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
$argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0;
if ($PHPUNIT_VERSION < 8.0) {
$argv = array_filter($argv, function ($v) use (&$argc) { if ('--do-not-cache-result' !== $v) return true; --$argc; });
$argv = array_filter($argv, function ($v) use (&$argc) { if ('--do-not-cache-result' !== $v) return true; --$argc; return false; });
} elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), FILTER_VALIDATE_BOOLEAN)) {
$argv[] = '--do-not-cache-result';
++$argc;

View File

@ -46,7 +46,7 @@ if (class_exists(Version::class) && version_compare(\defined(Version::class.'::V
$functionLoader = $functionLoader[0];
}
if (!\is_object($functionLoader)) {
return;
return null;
}
if ($functionLoader instanceof ClassLoader) {
return $functionLoader;
@ -57,6 +57,8 @@ if (class_exists(Version::class) && version_compare(\defined(Version::class.'::V
if ($functionLoader instanceof \Symfony\Component\ErrorHandler\DebugClassLoader) {
return $getComposerClassLoader($functionLoader->getClassLoader());
}
return null;
};
$classLoader = null;

View File

@ -83,9 +83,8 @@ class AppVariable
}
$user = $token->getUser();
if (\is_object($user)) {
return $user;
}
return \is_object($user) ? $user : null;
}
/**
@ -113,9 +112,7 @@ class AppVariable
throw new \RuntimeException('The "app.session" variable is not available.');
}
if ($request = $this->getRequest()) {
return $request->getSession();
}
return ($request = $this->getRequest()) ? $request->getSession() : null;
}
/**

View File

@ -296,16 +296,16 @@ EOF
return $entity;
}
if ('tests' === $type) {
return;
return null;
}
if ('functions' === $type || 'filters' === $type) {
$cb = $entity->getCallable();
if (null === $cb) {
return;
return null;
}
if (\is_array($cb)) {
if (!method_exists($cb[0], $cb[1])) {
return;
return null;
}
$refl = new \ReflectionMethod($cb[0], $cb[1]);
} elseif (\is_object($cb) && method_exists($cb, '__invoke')) {
@ -344,6 +344,8 @@ EOF
return $args;
}
return null;
}
private function getPrettyMetadata($type, $entity, $decorated)
@ -378,6 +380,8 @@ EOF
if ('filters' === $type) {
return $meta ? '('.implode(', ', $meta).')' : '';
}
return null;
}
private function findWrongBundleOverrides(): array

View File

@ -55,7 +55,7 @@ class DumpExtension extends AbstractExtension
public function dump(Environment $env, $context)
{
if (!$env->isDebug()) {
return;
return null;
}
if (2 === \func_num_args()) {

View File

@ -72,6 +72,8 @@ class UndefinedCallableHandler
}
self::onUndefined($name, 'filter', self::$filterComponents[$name]);
return true;
}
public static function onUndefinedFunction($name)
@ -81,6 +83,8 @@ class UndefinedCallableHandler
}
self::onUndefined($name, 'function', self::$functionComponents[$name]);
return true;
}
private static function onUndefined($name, $type, $component)

View File

@ -86,7 +86,7 @@ EOF
'For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>config:dump-reference FrameworkBundle profiler.matcher</comment> to dump the <comment>framework.profiler.matcher</comment> configuration)',
]);
return;
return null;
}
$extension = $this->findExtension($name);
@ -129,5 +129,7 @@ EOF
}
$io->writeln(null === $path ? $dumper->dump($configuration, $extension->getNamespace()) : $dumper->dumpAtPath($configuration, $path));
return null;
}
}

View File

@ -113,5 +113,7 @@ EOF
return 1;
}
return null;
}
}

View File

@ -235,7 +235,7 @@ EOF
if (!\count($operation->getDomains())) {
$errorIo->warning('No translation messages were found.');
return;
return null;
}
$resultMessage = 'Translation files were successfully updated';
@ -300,6 +300,8 @@ EOF
}
$errorIo->success($resultMessage.'.');
return null;
}
private function filterCatalogue(MessageCatalogue $catalogue, string $domain): MessageCatalogue

View File

@ -143,7 +143,9 @@ class JsonDescriptor extends Descriptor
protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null)
{
if (!$builder) {
return $this->writeData($this->getContainerAliasData($alias), $options);
$this->writeData($this->getContainerAliasData($alias), $options);
return;
}
$this->writeData(

View File

@ -253,7 +253,9 @@ class MarkdownDescriptor extends Descriptor
."\n".'- Public: '.($alias->isPublic() && !$alias->isPrivate() ? 'yes' : 'no');
if (!isset($options['id'])) {
return $this->write($output);
$this->write($output);
return;
}
$this->write(sprintf("### %s\n\n%s\n", $options['id'], $output));

View File

@ -387,7 +387,7 @@ class TextDescriptor extends Descriptor
return;
}
return $this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, ['id' => (string) $alias]));
$this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, ['id' => (string) $alias]));
}
/**

View File

@ -100,7 +100,9 @@ class XmlDescriptor extends Descriptor
$dom->appendChild($dom->importNode($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null)->childNodes->item(0), true));
if (!$builder) {
return $this->writeDocument($dom);
$this->writeDocument($dom);
return;
}
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $alias), (string) $alias)->childNodes->item(0), true));

View File

@ -49,15 +49,12 @@ class GlobalVariables
public function getUser()
{
if (!$token = $this->getToken()) {
return;
return null;
}
$user = $token->getUser();
if (!\is_object($user)) {
return;
}
return $user;
return \is_object($user) ? $user : null;
}
/**
@ -65,9 +62,7 @@ class GlobalVariables
*/
public function getRequest()
{
if ($this->container->has('request_stack')) {
return $this->container->get('request_stack')->getCurrentRequest();
}
return $this->container->has('request_stack') ? $this->container->get('request_stack')->getCurrentRequest() : null;
}
/**
@ -75,9 +70,7 @@ class GlobalVariables
*/
public function getSession()
{
if ($request = $this->getRequest()) {
return $request->getSession();
}
return ($request = $this->getRequest()) ? $request->getSession() : null;
}
/**

View File

@ -116,7 +116,7 @@ class CodeHelper extends Helper
* @param string $file A file path
* @param int $line The selected line number
*
* @return string An HTML string
* @return string|null An HTML string
*/
public function fileExcerpt($file, $line)
{
@ -144,6 +144,8 @@ class CodeHelper extends Helper
return '<ol start="'.max($line - 3, 1).'">'.implode("\n", $lines).'</ol>';
}
return null;
}
/**

View File

@ -97,7 +97,9 @@ abstract class FrameworkExtensionTest extends TestCase
$container = $this->createContainerFromFile('property_accessor');
if (!method_exists(PropertyAccessor::class, 'createCache')) {
return $this->assertFalse($container->hasDefinition('cache.property_access'));
$this->assertFalse($container->hasDefinition('cache.property_access'));
return;
}
$cache = $container->getDefinition('cache.property_access');
@ -110,7 +112,9 @@ abstract class FrameworkExtensionTest extends TestCase
$container = $this->createContainerFromFile('property_accessor', ['kernel.debug' => true]);
if (!method_exists(PropertyAccessor::class, 'createCache')) {
return $this->assertFalse($container->hasDefinition('cache.property_access'));
$this->assertFalse($container->hasDefinition('cache.property_access'));
return;
}
$cache = $container->getDefinition('cache.property_access');

View File

@ -162,6 +162,8 @@ EOF
}
$errorIo->success('Password encoding succeeded');
return null;
}
/**

View File

@ -98,9 +98,7 @@ class ProfilerControllerTest extends TestCase
->expects($this->exactly(2))
->method('loadProfile')
->willReturnCallback(function ($token) {
if ('found' == $token) {
return new Profile($token);
}
return 'found' == $token ? new Profile($token) : null;
})
;

View File

@ -159,5 +159,7 @@ EOF
return 1;
}
return null;
}
}

View File

@ -98,5 +98,7 @@ EOF
return 1;
}
}
return null;
}
}

View File

@ -72,5 +72,7 @@ EOF
return 1;
}
return null;
}
}

View File

@ -60,6 +60,8 @@ class CookieJar
}
}
}
return null;
}
/**

View File

@ -181,6 +181,8 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac
foreach ($this->getItems([$key]) as $item) {
return $item;
}
return null;
}
/**

View File

@ -296,5 +296,7 @@ class XmlReferenceDumper
if (\is_array($value)) {
return implode(',', $value);
}
return '';
}
}

View File

@ -166,5 +166,7 @@ abstract class FileLoader extends Loader
throw new LoaderLoadException($resource, $sourceResource, null, $e, $type);
}
}
return null;
}
}

View File

@ -40,7 +40,9 @@ class ErrorListener implements EventSubscriberInterface
$error = $event->getError();
if (!$inputString = $this->getInputString($event)) {
return $this->logger->error('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]);
$this->logger->error('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]);
return;
}
$this->logger->error('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]);
@ -59,7 +61,9 @@ class ErrorListener implements EventSubscriberInterface
}
if (!$inputString = $this->getInputString($event)) {
return $this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]);
$this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]);
return;
}
$this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]);

View File

@ -283,6 +283,8 @@ class ArgvInput extends Input
return $token;
}
return null;
}
/**

View File

@ -46,6 +46,8 @@ class ArrayInput extends Input
return $value;
}
return null;
}
/**

View File

@ -58,6 +58,8 @@ class TokenizerEscaping
if (0x10000 > $c) {
return \chr(0xE0 | $c >> 12).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
}
return '';
}, $value);
}
}

View File

@ -395,6 +395,12 @@ class DebugClassLoader
return $deprecations;
}
/**
* @param string $file
* @param string $class
*
* @return array|null
*/
public function checkCase(\ReflectionClass $refl, $file, $class)
{
$real = explode('\\', $class.strrchr($file, '.'));
@ -411,7 +417,7 @@ class DebugClassLoader
array_splice($tail, 0, $i + 1);
if (!$tail) {
return;
return null;
}
$tail = \DIRECTORY_SEPARATOR.implode(\DIRECTORY_SEPARATOR, $tail);
@ -427,6 +433,8 @@ class DebugClassLoader
) {
return [substr($tail, -$tailLen + 1), substr($real, -$tailLen + 1), substr($real, 0, -$tailLen + 1)];
}
return null;
}
/**

View File

@ -71,6 +71,8 @@ class ClassNotFoundFatalErrorHandler implements FatalErrorHandlerInterface
return new ClassNotFoundException($message, $exception);
}
return null;
}
/**

View File

@ -438,5 +438,7 @@ class ClassLoader
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtualMagicCall extends \\'.__NAMESPACE__.'\Fixtures\VirtualClassMagicCall implements \\'.__NAMESPACE__.'\Fixtures\VirtualInterface {
}');
}
return null;
}
}

View File

@ -81,5 +81,7 @@ class CheckArgumentsValidityPass extends AbstractRecursivePass
}
}
}
return null;
}
}

View File

@ -120,7 +120,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if (false !== $i || 'string' !== $prefix) {
if (null === $env = $getEnv($name)) {
return;
return null;
}
} elseif (isset($_ENV[$name])) {
$env = $_ENV[$name];
@ -132,7 +132,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
}
if (null === $env = $this->container->getParameter("env($name)")) {
return;
return null;
}
}

View File

@ -50,8 +50,7 @@ class ProxyHelper
if ('self' === $lcName) {
return $prefix.$r->getDeclaringClass()->name;
}
if ($parent = $r->getDeclaringClass()->getParentClass()) {
return $prefix.$parent->name;
}
return ($parent = $r->getDeclaringClass()->getParentClass()) ? $prefix.$parent->name : null;
}
}

View File

@ -72,9 +72,8 @@ abstract class FormField
}
$labels = $xpath->query('ancestor::label[1]', $this->node);
if ($labels->length > 0) {
return $labels->item(0);
}
return $labels->length > 0 ? $labels->item(0) : null;
}
/**

View File

@ -108,7 +108,7 @@ class EventDispatcher implements EventDispatcherInterface
public function getListenerPriority($eventName, $listener)
{
if (empty($this->listeners[$eventName])) {
return;
return null;
}
if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
@ -125,6 +125,8 @@ class EventDispatcher implements EventDispatcherInterface
}
}
}
return null;
}
/**

View File

@ -21,7 +21,7 @@ class FilesystemTestCase extends TestCase
protected $longPathNamesWindows = [];
/**
* @var \Symfony\Component\Filesystem\Filesystem
* @var Filesystem
*/
protected $filesystem = null;
@ -110,9 +110,8 @@ class FilesystemTestCase extends TestCase
$this->markAsSkippedIfPosixIsMissing();
$infos = stat($filepath);
if ($datas = posix_getpwuid($infos['uid'])) {
return $datas['name'];
}
return ($datas = posix_getpwuid($infos['uid'])) ? $datas['name'] : null;
}
protected function getFileGroup($filepath)

View File

@ -140,6 +140,7 @@ abstract class AbstractExtension implements FormExtensionInterface
*/
protected function loadTypeGuesser()
{
return null;
}
/**

View File

@ -78,9 +78,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
// when such values are passed to
// ChoiceListInterface::getValuesForChoices(). Handle this case
// so that the call to getValue() doesn't break.
if (\is_object($choice) || \is_array($choice)) {
return $accessor->getValue($choice, $value);
}
return \is_object($choice) || \is_array($choice) ? $accessor->getValue($choice, $value) : null;
};
}
@ -109,9 +107,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
// when such values are passed to
// ChoiceListInterface::getValuesForChoices(). Handle this case
// so that the call to getValue() doesn't break.
if (\is_object($choice) || \is_array($choice)) {
return $accessor->getValue($choice, $value);
}
return \is_object($choice) || \is_array($choice) ? $accessor->getValue($choice, $value) : null;
};
}
@ -179,6 +175,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
return $accessor->getValue($choice, $groupBy);
} catch (UnexpectedTypeException $e) {
// Don't group if path is not readable
return null;
}
};
}

View File

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

View File

@ -42,7 +42,7 @@ class ChoiceToValueTransformer implements DataTransformerInterface
if (1 !== \count($choices)) {
if (null === $value || '' === $value) {
return;
return null;
}
throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));

View File

@ -34,7 +34,7 @@ class DateTimeZoneToStringTransformer implements DataTransformerInterface
public function transform($dateTimeZone)
{
if (null === $dateTimeZone) {
return;
return null;
}
if ($this->multiple) {
@ -58,7 +58,7 @@ class DateTimeZoneToStringTransformer implements DataTransformerInterface
public function reverseTransform($value)
{
if (null === $value) {
return;
return null;
}
if ($this->multiple) {

View File

@ -251,7 +251,7 @@ class ChoiceType extends AbstractType
{
$emptyData = function (Options $options) {
if ($options['expanded'] && !$options['multiple']) {
return;
return null;
}
if ($options['multiple']) {
@ -268,13 +268,13 @@ class ChoiceType extends AbstractType
$placeholderNormalizer = function (Options $options, $placeholder) {
if ($options['multiple']) {
// never use an empty value for this case
return;
return null;
} elseif ($options['required'] && ($options['expanded'] || isset($options['attr']['size']) && $options['attr']['size'] > 1)) {
// placeholder for required radio buttons or a select with size > 1 does not make sense
return;
return null;
} elseif (false === $placeholder) {
// an empty value should be added but the user decided otherwise
return;
return null;
} elseif ($options['expanded'] && '' === $placeholder) {
// never use an empty label for radio buttons
return 'None';
@ -362,9 +362,6 @@ class ChoiceType extends AbstractType
}
}
/**
* @return mixed
*/
private function addSubForm(FormBuilderInterface $builder, string $name, ChoiceView $choiceView, array $options)
{
$choiceOpts = [

View File

@ -36,7 +36,7 @@ abstract class BaseValidatorExtension extends AbstractTypeExtension
}
if (empty($groups)) {
return;
return null;
}
if (\is_callable($groups)) {

View File

@ -153,6 +153,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
case 'Symfony\Component\Validator\Constraints\IsFalse':
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CheckboxType', [], Guess::MEDIUM_CONFIDENCE);
}
return null;
}
/**
@ -168,6 +170,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
case 'Symfony\Component\Validator\Constraints\IsTrue':
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
}
return null;
}
/**
@ -196,6 +200,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
}
break;
}
return null;
}
/**
@ -232,6 +238,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
}
break;
}
return null;
}
/**

View File

@ -50,9 +50,7 @@ class MappingRule
*/
public function match($propertyPath)
{
if ($propertyPath === $this->propertyPath) {
return $this->getTarget();
}
return $propertyPath === $this->propertyPath ? $this->getTarget() : null;
}
/**

View File

@ -761,9 +761,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
return $this->clickedButton;
}
if ($this->parent && method_exists($this->parent, 'getClickedButton')) {
return $this->parent->getClickedButton();
}
return $this->parent && method_exists($this->parent, 'getClickedButton') ? $this->parent->getClickedButton() : null;
}
/**

View File

@ -53,5 +53,7 @@ class StringUtil
if (preg_match('~([^\\\\]+?)(type)?$~i', $fqcn, $matches)) {
return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $matches[1]));
}
return null;
}
}

View File

@ -96,5 +96,7 @@ class ExtensionGuesser implements ExtensionGuesserInterface
return $extension;
}
}
return null;
}
}

View File

@ -132,5 +132,7 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
if (2 === \count($this->guessers) && !FileBinaryMimeTypeGuesser::isSupported() && !FileinfoMimeTypeGuesser::isSupported()) {
throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)');
}
return null;
}
}

View File

@ -69,49 +69,49 @@ class Request
/**
* Custom parameters.
*
* @var \Symfony\Component\HttpFoundation\ParameterBag
* @var ParameterBag
*/
public $attributes;
/**
* Request body parameters ($_POST).
*
* @var \Symfony\Component\HttpFoundation\ParameterBag
* @var ParameterBag
*/
public $request;
/**
* Query string parameters ($_GET).
*
* @var \Symfony\Component\HttpFoundation\ParameterBag
* @var ParameterBag
*/
public $query;
/**
* Server and execution environment parameters ($_SERVER).
*
* @var \Symfony\Component\HttpFoundation\ServerBag
* @var ServerBag
*/
public $server;
/**
* Uploaded files ($_FILES).
*
* @var \Symfony\Component\HttpFoundation\FileBag
* @var FileBag
*/
public $files;
/**
* Cookies ($_COOKIE).
*
* @var \Symfony\Component\HttpFoundation\ParameterBag
* @var ParameterBag
*/
public $cookies;
/**
* Headers (taken from the $_SERVER).
*
* @var \Symfony\Component\HttpFoundation\HeaderBag
* @var HeaderBag
*/
public $headers;
@ -171,7 +171,7 @@ class Request
protected $format;
/**
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
* @var SessionInterface
*/
protected $session;
@ -1321,6 +1321,8 @@ class Request
return $format;
}
}
return null;
}
/**

View File

@ -86,9 +86,7 @@ abstract class Bundle implements BundleInterface
}
}
if ($this->extension) {
return $this->extension;
}
return $this->extension ?: null;
}
/**
@ -153,9 +151,7 @@ abstract class Bundle implements BundleInterface
*/
protected function createContainerExtension()
{
if (class_exists($class = $this->getContainerExtensionClass())) {
return new $class();
}
return class_exists($class = $this->getContainerExtensionClass()) ? new $class() : null;
}
private function parseClassName()

View File

@ -108,5 +108,7 @@ class FragmentHandler
}
$response->sendContent();
return null;
}
}

View File

@ -109,6 +109,8 @@ abstract class AbstractSurrogate implements SurrogateInterface
throw $e;
}
}
return null;
}
/**

View File

@ -111,5 +111,7 @@ class Esi extends AbstractSurrogate
// remove ESI/1.0 from the Surrogate-Control header
$this->removeFromControl($response);
return $response;
}
}

View File

@ -94,5 +94,7 @@ class Ssi extends AbstractSurrogate
// remove SSI/1.0 from the Surrogate-Control header
$this->removeFromControl($response);
return null;
}
}

View File

@ -513,7 +513,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
if (isset($collectedLogs[$message])) {
++$collectedLogs[$message]['count'];
return;
return null;
}
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5);
@ -540,6 +540,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
'trace' => [$backtrace[0]],
'count' => 1,
];
return null;
});
}

View File

@ -242,16 +242,19 @@ class Profiler implements ResetInterface
return $this->collectors[$name];
}
/**
* @return int|null
*/
private function getTimestamp($value)
{
if (null === $value || '' == $value) {
return;
return null;
}
try {
$value = new \DateTime(is_numeric($value) ? '@'.$value : $value);
} catch (\Exception $e) {
return;
return null;
}
return $value->getTimestamp();

View File

@ -88,7 +88,7 @@ class EsiTest extends TestCase
$request = Request::create('/');
$response = new Response();
$response->headers->set('Content-Type', 'text/plain');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertFalse($response->headers->has('x-body-eval'));
}
@ -99,7 +99,7 @@ class EsiTest extends TestCase
$request = Request::create('/');
$response = new Response('<esi:remove> <a href="http://www.example.com">www.example.com</a> </esi:remove> Keep this'."<esi:remove>\n <a>www.example.com</a> </esi:remove> And this");
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals(' Keep this And this', $response->getContent());
}
@ -110,7 +110,7 @@ class EsiTest extends TestCase
$request = Request::create('/');
$response = new Response('<esi:comment text="some comment &gt;" /> Keep this');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals(' Keep this', $response->getContent());
}
@ -121,23 +121,23 @@ class EsiTest extends TestCase
$request = Request::create('/');
$response = new Response('foo <esi:comment text="some comment" /><esi:include src="..." alt="alt" onerror="continue" />');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('foo <?php echo $this->surrogate->handle($this, \'...\', \'alt\', true) ?>'."\n", $response->getContent());
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$response = new Response('foo <esi:comment text="some comment" /><esi:include src="foo\'" alt="bar\'" onerror="continue" />');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('foo <?php echo $this->surrogate->handle($this, \'foo\\\'\', \'bar\\\'\', true) ?>'."\n", $response->getContent());
$response = new Response('foo <esi:include src="..." />');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('foo <?php echo $this->surrogate->handle($this, \'...\', \'\', false) ?>'."\n", $response->getContent());
$response = new Response('foo <esi:include src="..."></esi:include>');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('foo <?php echo $this->surrogate->handle($this, \'...\', \'\', false) ?>'."\n", $response->getContent());
}
@ -148,7 +148,7 @@ class EsiTest extends TestCase
$request = Request::create('/');
$response = new Response('<?php <? <% <script language=php>');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('<?php echo "<?"; ?>php <?php echo "<?"; ?> <?php echo "<%"; ?> <?php echo "<s"; ?>cript language=php>', $response->getContent());
}
@ -160,7 +160,7 @@ class EsiTest extends TestCase
$request = Request::create('/');
$response = new Response('foo <esi:include />');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
}
public function testProcessRemoveSurrogateControlHeader()
@ -170,16 +170,16 @@ class EsiTest extends TestCase
$request = Request::create('/');
$response = new Response('foo <esi:include src="..." />');
$response->headers->set('Surrogate-Control', 'content="ESI/1.0"');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$response->headers->set('Surrogate-Control', 'no-store, content="ESI/1.0"');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$this->assertEquals('no-store', $response->headers->get('surrogate-control'));
$response->headers->set('Surrogate-Control', 'content="ESI/1.0", no-store');
$esi->process($request, $response);
$this->assertSame($response, $esi->process($request, $response));
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$this->assertEquals('no-store', $response->headers->get('surrogate-control'));
}

View File

@ -90,6 +90,8 @@ class CurrencyDataGenerator extends AbstractDataGenerator
return $data;
}
return null;
}
/**

View File

@ -140,6 +140,8 @@ class LanguageDataGenerator extends AbstractDataGenerator
return $data;
}
return null;
}
/**

View File

@ -110,6 +110,8 @@ class RegionDataGenerator extends AbstractDataGenerator
return $data;
}
return null;
}
/**

View File

@ -77,6 +77,8 @@ class ScriptDataGenerator extends AbstractDataGenerator
return $data;
}
return null;
}
/**

View File

@ -101,7 +101,7 @@ class FullTransformer
* @param string $dateChars The date characters to be replaced with a formatted ICU value
* @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
*
* @return string The formatted value
* @return string|null The formatted value
*
* @throws NotImplementedException When it encounters a not implemented date character
*/
@ -123,6 +123,8 @@ class FullTransformer
if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
throw new NotImplementedException(sprintf('Unimplemented date character "%s" in format "%s"', $dateChars[0], $this->pattern));
}
return null;
}
/**
@ -196,6 +198,8 @@ class FullTransformer
return "(?P<$captureName>".$transformer->getReverseMatchingRegExp($length).')';
}
return null;
}, $escapedPattern);
return $reverseMatchingRegExp;

View File

@ -78,7 +78,7 @@ class CurrencyBundle extends CurrencyDataProvider implements CurrencyBundleInter
try {
return parent::getFractionDigits($currency);
} catch (MissingResourceException $e) {
return;
return null;
}
}
@ -90,7 +90,7 @@ class CurrencyBundle extends CurrencyDataProvider implements CurrencyBundleInter
try {
return parent::getRoundingIncrement($currency);
} catch (MissingResourceException $e) {
return;
return null;
}
}

View File

@ -62,7 +62,7 @@ function get_icu_version_from_genrb($genrb)
}
if (!preg_match('/ICU version ([\d\.]+)/', implode('', $output), $matches)) {
return;
return null;
}
return $matches[1];

View File

@ -88,12 +88,14 @@ abstract class AbstractPipes implements PipesInterface
/**
* Writes input to stdin.
*
* @return array|null
*
* @throws InvalidArgumentException When an input iterator yields a non supported value
*/
protected function write()
{
if (!isset($this->pipes[0])) {
return;
return null;
}
$input = $this->input;
@ -122,7 +124,7 @@ abstract class AbstractPipes implements PipesInterface
// let's have a look if something changed in streams
if (false === @stream_select($r, $w, $e, 0, 0)) {
return;
return null;
}
foreach ($w as $stdin) {
@ -166,6 +168,8 @@ abstract class AbstractPipes implements PipesInterface
} elseif (!$w) {
return [$this->pipes[0]];
}
return null;
}
/**

View File

@ -1224,6 +1224,8 @@ class ProcessTest extends TestCase
return $stream;
}
return null;
};
$input = new InputStream();

View File

@ -33,5 +33,7 @@ class TestClassMagicCall
if ('setMagicCallProperty' === $method) {
$this->magicCallProperty = reset($args);
}
return null;
}
}

View File

@ -89,6 +89,8 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
return $varDescription;
}
}
return null;
}
/**

View File

@ -110,5 +110,7 @@ class PropertyInfoExtractor implements PropertyInfoExtractorInterface, PropertyI
return $value;
}
}
return null;
}
}

View File

@ -154,6 +154,8 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
* it does not match the requirement
*
* @return string
*/
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = [])
{

View File

@ -52,10 +52,30 @@ class TraceableUrlMatcher extends UrlMatcher
protected function matchCollection($pathinfo, RouteCollection $routes)
{
// HEAD and GET are equivalent as per RFC
if ('HEAD' === $method = $this->context->getMethod()) {
$method = 'GET';
}
$supportsTrailingSlash = 'GET' === $method && $this instanceof RedirectableUrlMatcherInterface;
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
$staticPrefix = rtrim($compiledRoute->getStaticPrefix(), '/');
$requiredMethods = $route->getMethods();
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
if ('' !== $staticPrefix && 0 !== strpos($trimmedPathinfo, $staticPrefix)) {
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
continue;
}
$regex = $compiledRoute->getRegex();
$pos = strrpos($regex, '$');
$hasTrailingSlash = '/' === $regex[$pos - 1];
$regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
if (!preg_match($regex, $pathinfo, $matches)) {
// does it match without any requirements?
$r = new Route($route->getPath(), $route->getDefaults(), [], $route->getOptions());
$cr = $r->compile();
@ -79,54 +99,57 @@ class TraceableUrlMatcher extends UrlMatcher
continue;
}
// check host requirement
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && preg_match('#\{\w+\}/?$#', $route->getPath());
if ($hasTrailingVar && ($hasTrailingSlash || (null === $m = $matches[\count($compiledRoute->getPathVariables())] ?? null) || '/' !== ($m[-1] ?? '/')) && preg_match($regex, $trimmedPathinfo, $m)) {
if ($hasTrailingSlash) {
$matches = $m;
} else {
$hasTrailingVar = false;
}
}
$hostMatches = [];
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
$this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
// check HTTP method requirement
if ($requiredMethods = $route->getMethods()) {
// HEAD and GET are equivalent as per RFC
if ('HEAD' === $method = $this->context->getMethod()) {
$method = 'GET';
}
$status = $this->handleRouteRequirements($pathinfo, $name, $route);
if (!\in_array($method, $requiredMethods)) {
$this->allow = array_merge($this->allow, $requiredMethods);
$this->addTrace(sprintf('Method "%s" does not match any of the required methods (%s)', $this->context->getMethod(), implode(', ', $requiredMethods)), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
if (self::REQUIREMENT_MISMATCH === $status[0]) {
$this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $route->getCondition()), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
// check condition
if ($condition = $route->getCondition()) {
if (!$this->getExpressionLanguage()->evaluate($condition, ['context' => $this->context, 'request' => $this->request ?: $this->createRequest($pathinfo)])) {
$this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $condition), self::ROUTE_ALMOST_MATCHES, $name, $route);
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
$this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
continue;
return $this->allow = $this->allowSchemes = [];
}
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
continue;
}
// check HTTP scheme requirement
if ($requiredSchemes = $route->getSchemes()) {
$scheme = $this->context->getScheme();
if ($route->getSchemes() && !$route->hasScheme($this->context->getScheme())) {
$this->allowSchemes = array_merge($this->allowSchemes, $route->getSchemes());
$this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes (%s)', $this->context->getScheme(), implode(', ', $route->getSchemes())), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
if (!$route->hasScheme($scheme)) {
$this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes (%s); the user will be redirected to first required scheme', $scheme, implode(', ', $requiredSchemes)), self::ROUTE_ALMOST_MATCHES, $name, $route);
return true;
}
if ($requiredMethods && !\in_array($method, $requiredMethods)) {
$this->allow = array_merge($this->allow, $requiredMethods);
$this->addTrace(sprintf('Method "%s" does not match any of the required methods (%s)', $this->context->getMethod(), implode(', ', $requiredMethods)), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
$this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
return true;
return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : []));
}
return [];
}
private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null)

View File

@ -11,14 +11,13 @@
namespace Symfony\Component\Routing\Tests\Matcher;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class TraceableUrlMatcherTest extends TestCase
class TraceableUrlMatcherTest extends UrlMatcherTest
{
public function test()
{
@ -119,4 +118,9 @@ class TraceableUrlMatcherTest extends TestCase
$traces = $matcher->getTracesForRequest($matchingRequest);
$this->assertEquals('Route matches!', $traces[0]['log']);
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return new TraceableUrlMatcher($routes, $context ?: new RequestContext());
}
}

View File

@ -54,7 +54,7 @@ interface UserInterface
* This should be the encoded password. On authentication, a plain-text
* password will be salted, encoded, and then compared to this value.
*
* @return string The password
* @return string|null The encoded password if any
*/
public function getPassword();

View File

@ -92,11 +92,21 @@ class ExceptionListener
$exception = $event->getException();
do {
if ($exception instanceof AuthenticationException) {
return $this->handleAuthenticationException($event, $exception);
} elseif ($exception instanceof AccessDeniedException) {
return $this->handleAccessDeniedException($event, $exception);
} elseif ($exception instanceof LogoutException) {
return $this->handleLogoutException($exception);
$this->handleAuthenticationException($event, $exception);
return;
}
if ($exception instanceof AccessDeniedException) {
$this->handleAccessDeniedException($event, $exception);
return;
}
if ($exception instanceof LogoutException) {
$this->handleLogoutException($exception);
return;
}
} while (null !== $exception = $exception->getPrevious());
}

View File

@ -140,6 +140,9 @@ class UsernamePasswordJsonAuthenticationListener implements ListenerInterface
$event->setResponse($response);
}
/**
* @return Response|null
*/
private function onSuccess(Request $request, TokenInterface $token)
{
if (null !== $this->logger) {
@ -156,7 +159,7 @@ class UsernamePasswordJsonAuthenticationListener implements ListenerInterface
}
if (!$this->successHandler) {
return; // let the original request succeeds
return null; // let the original request succeeds
}
$response = $this->successHandler->onAuthenticationSuccess($request, $token);

View File

@ -394,7 +394,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
$expectedTypes = [];
foreach ($types as $type) {
if (null === $data && $type->isNullable()) {
return;
return null;
}
if ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueType()) && Type::BUILTIN_TYPE_OBJECT === $collectionValueType->getBuiltinType()) {

View File

@ -139,6 +139,8 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
if (\is_callable([$object, $haser])) {
return $object->$haser();
}
return null;
}
/**

View File

@ -123,7 +123,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
try {
$reflectionProperty = $this->getReflectionProperty($object, $attribute);
} catch (\ReflectionException $reflectionException) {
return;
return null;
}
// Override visibility

View File

@ -292,6 +292,8 @@ class SerializerCollectionDummy implements SerializerInterface, DenormalizerInte
return $normalizer->denormalize($data, $type, $format, $context);
}
}
return null;
}
public function supportsDenormalization($data, $type, $format = null)

View File

@ -223,10 +223,13 @@ EOF
}
}
/**
* @return string|null
*/
private function getStdin()
{
if (0 !== ftell(STDIN)) {
return;
return null;
}
$inputs = '';

View File

@ -86,9 +86,7 @@ class IcuResFileDumper extends FileDumper
{
$padding = \strlen($data) % 4;
if ($padding) {
return str_repeat("\xAA", 4 - $padding);
}
return $padding ? str_repeat("\xAA", 4 - $padding) : null;
}
private function getPosition($data)

View File

@ -261,6 +261,8 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
return $this->metadata[$domain][$key];
}
}
return null;
}
/**

View File

@ -112,5 +112,6 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
*/
protected function getErrorCode()
{
return null;
}
}

View File

@ -244,5 +244,6 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
*/
protected function getErrorCode()
{
return null;
}
}

View File

@ -34,7 +34,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
}
/**
* @return string The type of the value
* @return string|null The type of the value
*/
public function getType()
{
@ -58,6 +58,8 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
if (Stub::TYPE_RESOURCE === $item->type) {
return $item->class.' resource';
}
return null;
}
/**
@ -125,6 +127,8 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
return $item instanceof Stub || [] === $item ? $data : $item;
}
return null;
}
public function __isset($key)

View File

@ -154,6 +154,8 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface
setlocale(LC_NUMERIC, $locale);
}
}
return null;
}
/**

View File

@ -29,6 +29,9 @@ trait VarDumperTestTrait
$this->assertStringMatchesFormat($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message);
}
/**
* @return string|null
*/
protected function getDump($data, $key = null, $filter = 0)
{
$flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
@ -41,7 +44,7 @@ trait VarDumperTestTrait
$dumper->setColors(false);
$data = $cloner->cloneVar($data, $filter)->withRefHandles(false);
if (null !== $key && null === $data = $data->seek($key)) {
return;
return null;
}
return rtrim($dumper->dump($data, true));

View File

@ -199,10 +199,13 @@ EOF
}
}
/**
* @return string|null
*/
private function getStdin()
{
if (0 !== ftell(STDIN)) {
return;
return null;
}
$inputs = '';

View File

@ -512,12 +512,12 @@ class Parser
*
* @throws ParseException When indentation problem are detected
*/
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false): ?string
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false): string
{
$oldLineIndentation = $this->getCurrentLineIndentation();
if (!$this->moveToNextLine()) {
return null;
return '';
}
if (null === $indentation) {
@ -560,7 +560,7 @@ class Parser
} else {
$this->moveToPreviousLine();
return null;
return '';
}
if ($inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
@ -568,7 +568,7 @@ class Parser
// and therefore no nested list or mapping
$this->moveToPreviousLine();
return null;
return '';
}
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();