diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index b247b115fa..5a9592a901 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -41,7 +41,7 @@ trait RedisTrait /** * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient */ - public function init($redisClient, $namespace = '', $defaultLifetime = 0) + private function init($redisClient, $namespace = '', $defaultLifetime = 0) { parent::__construct($namespace, $defaultLifetime); diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/DefaultsConfigurator.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/DefaultsConfigurator.php index aec0b2bd21..07f6b7257e 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/DefaultsConfigurator.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/DefaultsConfigurator.php @@ -34,12 +34,12 @@ class DefaultsConfigurator extends AbstractServiceConfigurator */ final public function tag(string $name, array $attributes = array()) { - if (!is_string($name) || '' === $name) { + if ('' === $name) { throw new InvalidArgumentException('The tag name in "_defaults" must be a non-empty string.'); } foreach ($attributes as $attribute => $value) { - if (!is_scalar($value) && null !== $value) { + if (null !== $value && !is_scalar($value)) { throw new InvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type.', $name, $attribute)); } } diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php index 760e8aa664..301ead682b 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php @@ -28,10 +28,6 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo */ public function __construct(?int $scale = 0, ?bool $grouping = false, int $roundingMode = self::ROUND_DOWN) { - if (null === $roundingMode) { - $roundingMode = self::ROUND_DOWN; - } - parent::__construct(0, $grouping, $roundingMode); } diff --git a/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentToken.php b/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentToken.php index 996ad285fd..7c12706e3c 100644 --- a/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentToken.php @@ -29,7 +29,7 @@ final class PersistentToken implements PersistentTokenInterface if (empty($class)) { throw new \InvalidArgumentException('$class must not be empty.'); } - if ('' === $username || null === $username) { + if ('' === $username) { throw new \InvalidArgumentException('$username must not be empty.'); } if (empty($series)) { diff --git a/src/Symfony/Component/Security/Core/User/LdapUserProvider.php b/src/Symfony/Component/Security/Core/User/LdapUserProvider.php index fcc3bcdb42..b3fa3fa6b9 100644 --- a/src/Symfony/Component/Security/Core/User/LdapUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/LdapUserProvider.php @@ -37,10 +37,6 @@ class LdapUserProvider implements UserProviderInterface public function __construct(LdapInterface $ldap, string $baseDn, string $searchDn = null, string $searchPassword = null, array $defaultRoles = array(), string $uidKey = 'sAMAccountName', string $filter = '({uid_key}={username})', string $passwordAttribute = null) { - if (null === $uidKey) { - $uidKey = 'sAMAccountName'; - } - $this->ldap = $ldap; $this->baseDn = $baseDn; $this->searchDn = $searchDn; diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index 121e01530d..08d6ff79db 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -212,11 +212,17 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn * @param array $context * @param bool $attributesAsString If false, return an array of {@link AttributeMetadataInterface} * + * @throws LogicException if the 'allow_extra_attributes' context variable is false and no class metadata factory is provided + * * @return string[]|AttributeMetadataInterface[]|bool */ protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false) { if (!$this->classMetadataFactory) { + if (isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) && !$context[static::ALLOW_EXTRA_ATTRIBUTES]) { + throw new LogicException(sprintf('A class metadata factory must be provided in the constructor when setting "%s" to false.', static::ALLOW_EXTRA_ATTRIBUTES)); + } + return false; } diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php index 5d0e3d1495..5cccdb3360 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php @@ -25,7 +25,7 @@ interface NormalizerInterface /** * Normalizes an object into a set of arrays/scalars. * - * @param object $object Object to normalize + * @param mixed $object Object to normalize * @param string $format Format the normalization result will be encoded as * @param array $context Context options for the normalizer * diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index 21943e3600..7aa6a76a7d 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -19,6 +19,7 @@ use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -52,7 +53,8 @@ class AbstractObjectNormalizerTest extends TestCase */ public function testDenormalizeWithExtraAttributes() { - $normalizer = new AbstractObjectNormalizerDummy(); + $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $normalizer = new AbstractObjectNormalizerDummy($factory); $normalizer->denormalize( array('fooFoo' => 'foo', 'fooBar' => 'bar'), __NAMESPACE__.'\Dummy', @@ -144,6 +146,21 @@ class AbstractObjectNormalizerTest extends TestCase return $denormalizer; } + + /** + * Test that additional attributes throw an exception if no metadata factory is specified. + * + * @expectedException \Symfony\Component\Serializer\Exception\LogicException + * @expectedExceptionMessage A class metadata factory must be provided in the constructor when setting "allow_extra_attributes" to false. + */ + public function testExtraAttributesException() + { + $normalizer = new ObjectNormalizer(); + + $normalizer->denormalize(array(), \stdClass::class, 'xml', array( + 'allow_extra_attributes' => false, + )); + } } class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer diff --git a/src/Symfony/Component/Translation/Extractor/AbstractFileExtractor.php b/src/Symfony/Component/Translation/Extractor/AbstractFileExtractor.php index 40b36451da..bdfec1a9ed 100644 --- a/src/Symfony/Component/Translation/Extractor/AbstractFileExtractor.php +++ b/src/Symfony/Component/Translation/Extractor/AbstractFileExtractor.php @@ -45,7 +45,7 @@ abstract class AbstractFileExtractor private function toSplFileInfo(string $file): \SplFileInfo { - return ($file instanceof \SplFileInfo) ? $file : new \SplFileInfo($file); + return new \SplFileInfo($file); } /**