Skip to content

Commit

Permalink
feature #30323 [ErrorHandler] trigger deprecation in DebugClassLoader…
Browse files Browse the repository at this point in the history
… when child class misses a return type (fancyweb, nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[ErrorHandler] trigger deprecation in DebugClassLoader when child class misses a return type

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30123
| License       | MIT
| Doc PR        | TODO

I wanted to push something to show the advancement and get feedback.

I pushed two versions : one with dedicated functions for code clarity (DebugClassLoader.php) and one withtout (DebugClassLoader___.php). It would be nice if some people with Blackfire could compare the performances.

So let's be clear, we are never gonna be able to cover all cases! We can however cover the vast majority.

Current non covered cases and problems :
- We assume that if there is more than 2 returned types, we cannot do anything. Even if it could technically be possible.
- We assume that any returned type that doesn't fit our "returnable" types list is a class. We don't check at all if this class actualy exists.
- We don't handle spaces in types. The types stop at the first space.
- That means we don't handle (yet) the callable type with spaces (cf #29969)
- Vendor code extending other vendor core triggers the deprecations 😕

Commits
-------

aa338c8 Import return annotations from vendors
10fc13e [ErrorHandler] Handle return types in DebugClassLoader
  • Loading branch information
nicolas-grekas committed Aug 14, 2019
2 parents c8e15e1 + aa338c8 commit 320e495
Show file tree
Hide file tree
Showing 84 changed files with 1,129 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
Expand Up @@ -39,6 +39,8 @@ public function __construct(ContainerInterface $container)

/**
* {@inheritdoc}
*
* @return void
*/
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
{
Expand All @@ -59,6 +61,8 @@ public function dispatchEvent($eventName, EventArgs $eventArgs = null)

/**
* {@inheritdoc}
*
* @return object[][]
*/
public function getListeners($event = null)
{
Expand All @@ -81,6 +85,8 @@ public function getListeners($event = null)

/**
* {@inheritdoc}
*
* @return bool
*/
public function hasListeners($event)
{
Expand All @@ -89,6 +95,8 @@ public function hasListeners($event)

/**
* {@inheritdoc}
*
* @return void
*/
public function addEventListener($events, $listener)
{
Expand All @@ -109,6 +117,8 @@ public function addEventListener($events, $listener)

/**
* {@inheritdoc}
*
* @return void
*/
public function removeEventListener($events, $listener)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
Expand Up @@ -34,6 +34,8 @@ public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch

/**
* {@inheritdoc}
*
* @return void
*/
public function startQuery($sql, array $params = null, array $types = null)
{
Expand All @@ -48,6 +50,8 @@ public function startQuery($sql, array $params = null, array $types = null)

/**
* {@inheritdoc}
*
* @return void
*/
public function stopQuery()
{
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/Doctrine/ManagerRegistry.php
Expand Up @@ -29,6 +29,8 @@ abstract class ManagerRegistry extends AbstractManagerRegistry

/**
* {@inheritdoc}
*
* @return object
*/
protected function getService($name)
{
Expand All @@ -37,6 +39,8 @@ protected function getService($name)

/**
* {@inheritdoc}
*
* @return void
*/
protected function resetService($name)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php
Expand Up @@ -28,6 +28,8 @@ final class TestRepositoryFactory implements RepositoryFactory

/**
* {@inheritdoc}
*
* @return ObjectRepository
*/
public function getRepository(EntityManagerInterface $entityManager, $entityName)
{
Expand Down
Expand Up @@ -34,6 +34,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform)

/**
* {@inheritdoc}
*
* @return string
*/
public function getName()
{
Expand Down
Expand Up @@ -27,6 +27,8 @@ class DoctrineFooType extends Type

/**
* {@inheritdoc}
*
* @return string
*/
public function getName()
{
Expand All @@ -35,6 +37,8 @@ public function getName()

/**
* {@inheritdoc}
*
* @return string
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
Expand Down Expand Up @@ -76,6 +80,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform)

/**
* {@inheritdoc}
*
* @return bool
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php
Expand Up @@ -72,6 +72,8 @@ protected function sendHeader($header, $content)

/**
* Override default behavior since we check it in onKernelResponse.
*
* @return bool
*/
protected function headersAccepted()
{
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Monolog\Handler;

use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
Expand Down Expand Up @@ -73,6 +74,8 @@ public function __construct(OutputInterface $output = null, bool $bubble = true,

/**
* {@inheritdoc}
*
* @return bool
*/
public function isHandling(array $record)
{
Expand All @@ -81,6 +84,8 @@ public function isHandling(array $record)

/**
* {@inheritdoc}
*
* @return bool
*/
public function handle(array $record)
{
Expand Down Expand Up @@ -142,6 +147,8 @@ public static function getSubscribedEvents()

/**
* {@inheritdoc}
*
* @return void
*/
protected function write(array $record)
{
Expand All @@ -151,6 +158,8 @@ protected function write(array $record)

/**
* {@inheritdoc}
*
* @return FormatterInterface
*/
protected function getDefaultFormatter()
{
Expand Down
Expand Up @@ -45,6 +45,9 @@ public function __construct(RequestStack $requestStack, array $exclusions, $acti
$this->exclusions = $exclusions;
}

/**
* @return bool
*/
public function isHandlerActivated(array $record)
{
$isActivated = parent::isHandlerActivated($record);
Expand Down
Expand Up @@ -34,6 +34,9 @@ public function __construct(RequestStack $requestStack, array $excludedUrls, $ac
$this->blacklist = '{('.implode('|', $excludedUrls).')}i';
}

/**
* @return bool
*/
public function isHandlerActivated(array $record)
{
$isActivated = parent::isHandlerActivated($record);
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php
Expand Up @@ -74,6 +74,8 @@ protected function sendHeader($header, $content)

/**
* Override default behavior since we check the user agent in onKernelResponse.
*
* @return bool
*/
protected function headersAccepted()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Monolog\Handler;

use Monolog\Formatter\FormatterInterface;
use Monolog\Handler\AbstractHandler;
use Monolog\Logger;
use Symfony\Bridge\Monolog\Formatter\VarDumperFormatter;
Expand Down Expand Up @@ -38,6 +39,8 @@ public function __construct(string $host, int $level = Logger::DEBUG, bool $bubb

/**
* {@inheritdoc}
*
* @return bool
*/
public function handle(array $record)
{
Expand Down Expand Up @@ -77,6 +80,8 @@ public function handle(array $record)

/**
* {@inheritdoc}
*
* @return FormatterInterface
*/
protected function getDefaultFormatter()
{
Expand Down
Expand Up @@ -29,6 +29,8 @@ public function setFluentSafe(bool $fluentSafe)

/**
* {@inheritdoc}
*
* @return void
*/
public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/AssetExtension.php
Expand Up @@ -31,6 +31,8 @@ public function __construct(Packages $packages)

/**
* {@inheritdoc}
*
* @return TwigFunction[]
*/
public function getFunctions()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Expand Up @@ -40,6 +40,8 @@ public function __construct($fileLinkFormat, string $projectDir, string $charset

/**
* {@inheritdoc}
*
* @return TwigFilter[]
*/
public function getFilters()
{
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/DumpExtension.php
Expand Up @@ -17,6 +17,7 @@
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Template;
use Twig\TokenParser\TokenParserInterface;
use Twig\TwigFunction;

/**
Expand All @@ -35,13 +36,19 @@ public function __construct(ClonerInterface $cloner, HtmlDumper $dumper = null)
$this->dumper = $dumper;
}

/**
* @return TwigFunction[]
*/
public function getFunctions()
{
return [
new TwigFunction('dump', [$this, 'dump'], ['is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true]),
];
}

/**
* @return TokenParserInterface[]
*/
public function getTokenParsers()
{
return [new DumpTokenParser()];
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
Expand Up @@ -24,6 +24,8 @@ class ExpressionExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*
* @return TwigFunction[]
*/
public function getFunctions()
{
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormView;
use Twig\Extension\AbstractExtension;
use Twig\TokenParser\TokenParserInterface;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\TwigTest;
Expand All @@ -29,6 +30,8 @@ class FormExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*
* @return TokenParserInterface[]
*/
public function getTokenParsers()
{
Expand All @@ -40,6 +43,8 @@ public function getTokenParsers()

/**
* {@inheritdoc}
*
* @return TwigFunction[]
*/
public function getFunctions()
{
Expand All @@ -60,6 +65,8 @@ public function getFunctions()

/**
* {@inheritdoc}
*
* @return TwigFilter[]
*/
public function getFilters()
{
Expand All @@ -71,6 +78,8 @@ public function getFilters()

/**
* {@inheritdoc}
*
* @return TwigTest[]
*/
public function getTests()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php
Expand Up @@ -57,6 +57,8 @@ public function __construct($urlHelper)

/**
* {@inheritdoc}
*
* @return TwigFunction[]
*/
public function getFunctions()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
Expand Up @@ -22,6 +22,9 @@
*/
class HttpKernelExtension extends AbstractExtension
{
/**
* @return TwigFunction[]
*/
public function getFunctions()
{
return [
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php
Expand Up @@ -31,6 +31,8 @@ public function __construct(LogoutUrlGenerator $generator)

/**
* {@inheritdoc}
*
* @return TwigFunction[]
*/
public function getFunctions()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/RoutingExtension.php
Expand Up @@ -34,6 +34,8 @@ public function __construct(UrlGeneratorInterface $generator)

/**
* {@inheritdoc}
*
* @return TwigFunction[]
*/
public function getFunctions()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/SecurityExtension.php
Expand Up @@ -50,6 +50,8 @@ public function isGranted($role, $object = null, $field = null)

/**
* {@inheritdoc}
*
* @return TwigFunction[]
*/
public function getFunctions()
{
Expand Down

0 comments on commit 320e495

Please sign in to comment.