Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3:
  cs fix
  Fix return statements
  [TwigBridge] add missing dep
  Add false type to ChoiceListFactoryInterface::createView $label argument
  Update UPGRADE guide of 4.3 for EventDispatcher
  [SecurityBundle] display the correct class name on the deprecated notice
  • Loading branch information
nicolas-grekas committed Aug 13, 2019
2 parents 3bc4e4f + 9b66113 commit 3ec9106
Show file tree
Hide file tree
Showing 59 changed files with 132 additions and 106 deletions.
31 changes: 30 additions & 1 deletion UPGRADE-4.3.md
Expand Up @@ -54,7 +54,36 @@ Dotenv
EventDispatcher
---------------

* The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated
* The signature of the `EventDispatcherInterface::dispatch()` method has been updated, consider using the new signature `dispatch($event, string $eventName = null)` instead of the old signature `dispatch($eventName, $event)` that is deprecated

You have to swap arguments when calling `dispatch()`:

Before:
```php
$this->eventDispatcher->dispatch(Events::My_EVENT, $event);
```

After:
```php
$this->eventDispatcher->dispatch($event, Events::My_EVENT);
```

If your bundle or package needs to provide compatibility with the previous way of using the dispatcher, you can use `Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy::decorate()` to ease upgrades:

Before:
```php
public function __construct(EventDispatcherInterface $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
}
```

After:
```php
public function __construct(EventDispatcherInterface $eventDispatcher) {
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
}
```

* The `Event` class has been deprecated, use `Symfony\Contracts\EventDispatcher\Event` instead

Filesystem
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php
Expand Up @@ -91,7 +91,7 @@ public function isIntId(): bool
public function getIdValue($object)
{
if (!$object) {
return;
return null;
}

if (!$this->om->contains($object)) {
Expand Down
Expand Up @@ -99,7 +99,7 @@ public function guessRequired($class, $property)
$classMetadatas = $this->getMetadata($class);

if (!$classMetadatas) {
return;
return null;
}

/** @var ClassMetadataInfo $classMetadata */
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/AppVariable.php
Expand Up @@ -68,7 +68,7 @@ public function getToken()
/**
* Returns the current user.
*
* @return mixed
* @return object|null
*
* @see TokenInterface::getUser()
*/
Expand All @@ -79,7 +79,7 @@ public function getUser()
}

if (!$token = $tokenStorage->getToken()) {
return;
return null;
}

$user = $token->getUser();
Expand Down
Expand Up @@ -352,7 +352,7 @@ protected function getDoctrine(): ManagerRegistry
/**
* Get a user from the Security Token Storage.
*
* @return mixed
* @return object|null
*
* @throws \LogicException If SecurityBundle is not available
*
Expand All @@ -367,12 +367,12 @@ protected function getUser()
}

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;
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function __construct(ContainerInterface $container)
public function getToken()
{
if (!$this->container->has('security.token_storage')) {
return;
return null;
}

return $this->container->get('security.token_storage')->getToken();
Expand Down
Expand Up @@ -126,7 +126,7 @@ public function fileExcerpt($file, $line)

// 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 '';
}
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ public function __invoke(RequestEvent $event)
if (\is_callable($this->listener)) {
($this->listener)($event);
} else {
@trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this)), E_USER_DEPRECATED);
@trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this->listener)), E_USER_DEPRECATED);
$this->listener->handle($event);
}
$this->time = microtime(true) - $startTime;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -528,7 +528,7 @@ protected function filterResponse($response)
protected function createCrawlerFromContent($uri, $content, $type)
{
if (!class_exists('Symfony\Component\DomCrawler\Crawler')) {
return;
return null;
}

$crawler = new Crawler(null, $uri);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Util/XmlUtils.php
Expand Up @@ -219,7 +219,7 @@ public static function phpize($value)

switch (true) {
case 'null' === $lowercaseValue:
return;
return null;
case ctype_digit($value):
$raw = $value;
$cast = (int) $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -482,7 +482,7 @@ public function add(Command $command)
if (!$command->isEnabled()) {
$command->setApplication(null);

return;
return null;
}

if (null === $command->getDefinition()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/CssSelector/Parser/TokenStream.php
Expand Up @@ -155,7 +155,7 @@ public function getNextIdentifierOrStar()
}

if ($next->isDelimiter(['*'])) {
return;
return null;
}

throw SyntaxErrorException::unexpectedToken('identifier or "*"', $next);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -446,7 +446,7 @@ public function handleError($type, $message, $file, $line)
self::$silencedErrorCache[$id][$message] = $errorAsException;
}
if (null === $lightTrace) {
return;
return true;
}
} else {
$errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);
Expand Down
Expand Up @@ -37,11 +37,11 @@ public function handleError(array $error, FatalErrorException $exception)
$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) {
Expand Down
Expand Up @@ -34,17 +34,17 @@ public function handleError(array $error, FatalErrorException $exception)
$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);
Expand Down
Expand Up @@ -32,7 +32,7 @@ public function handleError(array $error, FatalErrorException $exception)
{
preg_match('/^Call to undefined method (.*)::(.*)\(\)$/', $error['message'], $matches);
if (!$matches) {
return;
return null;
}

$className = $matches[1];
Expand Down
Expand Up @@ -29,7 +29,7 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
$type = $r->getReturnType();
}
if (!$type) {
return;
return null;
}
if (!\is_string($type)) {
$name = $type->getName();
Expand All @@ -45,7 +45,7 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
return $prefix.$name;
}
if (!$r instanceof \ReflectionMethod) {
return;
return null;
}
if ('self' === $lcName) {
return $prefix.$r->getDeclaringClass()->name;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -408,12 +408,12 @@ private function linkException(string $origin, string $target, string $linkType)
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) {
Expand Down
Expand Up @@ -78,14 +78,11 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
* 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
*/
Expand Down
Expand Up @@ -45,14 +45,14 @@ public function __construct(string $trueValue, array $falseValues = [null])
*
* @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)) {
Expand Down
Expand Up @@ -106,21 +106,21 @@ public function transform($dateInterval)
*
* @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
*/
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) {
Expand Down
Expand Up @@ -62,21 +62,21 @@ public function transform($value)
*
* @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
*/
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');
Expand Down
Expand Up @@ -105,23 +105,23 @@ public function transform($dateTime)
*
* @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
*/
public function reverseTransform($value)
{
if (null === $value) {
return;
return null;
}

if (!\is_array($value)) {
throw new TransformationFailedException('Expected an array.');
}

if ('' === implode('', $value)) {
return;
return null;
}

$emptyFields = [];
Expand Down
Expand Up @@ -66,7 +66,7 @@ public function transform($dateTime)
*
* @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
Expand All @@ -78,7 +78,7 @@ public function reverseTransform($dateTimeLocal)
}

if ('' === $dateTimeLocal) {
return;
return null;
}

// to maintain backwards compatibility we do not strictly validate the submitted date
Expand Down
Expand Up @@ -99,7 +99,7 @@ public function transform($dateTime)
*
* @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
Expand All @@ -111,7 +111,7 @@ public function reverseTransform($value)
}

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
Expand Down

0 comments on commit 3ec9106

Please sign in to comment.