Skip to content

Commit 38b0394

Browse files
natewiebe13anyt
authored andcommitted
Symfony 6 Support for Twig Inspector
- Make typehint more accurate - Add type hints and remove redundant phpdocs - Fix Symfony error - Drop unsupported php versions - Allow Symfony 6
1 parent 1720c1f commit 38b0394

11 files changed

+42
-73
lines changed

Diff for: BoxDrawings.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ class BoxDrawings
1414
['', '', ''],
1515
];
1616

17-
/** @var int */
18-
private $charsetIndex = 0;
17+
private int $charsetIndex = 0;
1918

20-
/** @var int */
21-
private $length = 0;
19+
private int $length = 0;
2220

2321
public function getStartCommentPrefix(): string
2422
{

Diff for: Bundle/DependencyInjection/OroTwigInspectorExtension.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
use Symfony\Component\DependencyInjection\Loader;
88
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
99

10+
/**
11+
* Load bundle configuration and services.yml
12+
*/
1013
class OroTwigInspectorExtension extends Extension
1114
{
1215
/**
1316
* {@inheritDoc}
1417
*/
15-
public function load(array $configs, ContainerBuilder $container)
18+
public function load(array $configs, ContainerBuilder $container): void
1619
{
1720
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
1821
$loader->load('services.yml');

Diff for: Controller/OpenTemplateController.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
*/
1414
class OpenTemplateController
1515
{
16-
/** @var Environment */
17-
private $twig;
16+
private Environment $twig;
1817

19-
/** @var FileLinkFormatter */
20-
private $fileLinkFormatter;
18+
private FileLinkFormatter $fileLinkFormatter;
2119

2220
public function __construct(Environment $twig, FileLinkFormatter $fileLinkFormatter)
2321
{
@@ -26,14 +24,11 @@ public function __construct(Environment $twig, FileLinkFormatter $fileLinkFormat
2624
}
2725

2826
/**
29-
* @param Request $request
30-
* @param string $template
31-
* @return RedirectResponse
3227
* @throws \Twig\Error\LoaderError
3328
* @throws \Twig\Error\RuntimeError
3429
* @throws \Twig\Error\SyntaxError
3530
*/
36-
public function __invoke(Request $request, string $template)
31+
public function __invoke(Request $request, string $template): RedirectResponse
3732
{
3833
$line = $request->query->get('line', 1);
3934

Diff for: DataCollector/TwigInspectorCollector.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@
1111
*/
1212
class TwigInspectorCollector implements DataCollectorInterface
1313
{
14-
/**
15-
* {@inheritDoc}
16-
*/
17-
public function collect(Request $request, Response $response, \Throwable $exception = null)
14+
public function collect(Request $request, Response $response, \Throwable $exception = null): void
1815
{
1916
}
2017

21-
/**
22-
* {@inheritDoc}
23-
*/
24-
public function reset()
18+
public function reset(): void
2519
{
2620
}
2721

Diff for: Twig/DebugInfoNodeVisitor.php

+9-16
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,12 @@ class DebugInfoNodeVisitor extends AbstractNodeVisitor
1919
{
2020
protected const EXTENSION_NAME = HtmlCommentsExtension::class;
2121

22-
/**
23-
* {@inheritdoc}
24-
*/
25-
protected function doEnterNode(Node $node, Environment $env)
22+
protected function doEnterNode(Node $node, Environment $env): Node
2623
{
2724
return $node;
2825
}
2926

30-
/**
31-
* {@inheritdoc}
32-
*/
33-
protected function doLeaveNode(Node $node, Environment $env)
27+
protected function doLeaveNode(Node $node, Environment $env): Node
3428
{
3529
$varName = $this->getVarName();
3630
if ($node instanceof ModuleNode) {
@@ -78,18 +72,17 @@ protected function doLeaveNode(Node $node, Environment $env)
7872
return $node;
7973
}
8074

81-
/**
82-
* @return string
83-
*/
84-
private function getVarName()
75+
private function getVarName(): string
8576
{
8677
return sprintf('__inspector_%s', hash('sha256', self::EXTENSION_NAME));
8778
}
8879

89-
/**
90-
* {@inheritdoc}
91-
*/
92-
public function getPriority()
80+
protected function getReference(Node $node): NodeReference
81+
{
82+
return new NodeReference($node->getAttribute('name'), $node->getTemplateName(), $node->getTemplateLine());
83+
}
84+
85+
public function getPriority(): int
9386
{
9487
return 0;
9588
}

Diff for: Twig/HtmlCommentsExtension.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@ class HtmlCommentsExtension extends AbstractExtension
1414
{
1515
protected const ENABLE_FLAG_COOKIE_ID = 'twig_inspector_is_active';
1616

17-
/** @var string */
18-
private $previousContent;
17+
private ?string $previousContent = null;
1918

20-
/** @var int */
21-
private $nestingLevel = 0;
19+
private int $nestingLevel = 0;
2220

23-
/** @var RequestStack */
24-
private $requestStack;
21+
private RequestStack $requestStack;
2522

26-
/** @var UrlGeneratorInterface */
27-
private $urlGenerator;
23+
private UrlGeneratorInterface $urlGenerator;
2824

29-
/** @var BoxDrawings */
30-
private $boxDrawings;
25+
private BoxDrawings $boxDrawings;
3126

3227
private array $skipBlocks = [];
3328
private bool $skipped = false;

Diff for: Twig/Node/NodeEnd.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010
*/
1111
class NodeEnd extends Node
1212
{
13-
/**
14-
* {@inheritDoc}
15-
*/
16-
public function __construct($varName)
13+
public function __construct(string $varName)
1714
{
1815
parent::__construct([], ['var_name' => $varName]);
1916
}
2017

21-
public function compile(Compiler $compiler)
18+
public function compile(Compiler $compiler): void
2219
{
2320
$compiler
2421
->write("\n")

Diff for: Twig/Node/NodeStart.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111
class NodeStart extends Node
1212
{
13-
public function __construct($exensionName, $name, $line, $varName)
13+
public function __construct(string $extensionName, string $name, int $line, string $varName)
1414
{
1515
parent::__construct(
1616
[],
17-
['extension_name' => $exensionName, 'name'=> $name, 'line' => $line, 'var_name' => $varName]
17+
['extension_name' => $extensionName, 'name'=> $name, 'line' => $line, 'var_name' => $varName]
1818
);
1919
}
2020

21-
public function compile(Compiler $compiler)
21+
public function compile(Compiler $compiler): void
2222
{
2323
$compiler
2424
->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name')))

Diff for: Twig/NodeReference.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77
*/
88
class NodeReference
99
{
10-
/** @var string */
11-
private $name;
10+
private string $name;
1211

13-
/** @var string */
14-
private $template;
12+
private string $template;
1513

16-
/** @var int */
17-
private $line;
14+
private int $line;
1815

19-
/** @var string */
20-
private $id;
16+
private string $id;
2117

2218
public function __construct(string $name, string $template, int $line)
2319
{

Diff for: Twig/TwigInspectorExtension.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
*/
1010
class TwigInspectorExtension extends AbstractExtension
1111
{
12-
/**
13-
* {@inheritDoc}
14-
*/
15-
public function getNodeVisitors()
12+
public function getNodeVisitors(): array
1613
{
1714
return [new DebugInfoNodeVisitor()];
1815
}

Diff for: composer.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
"psr-4": {"Oro\\TwigInspector\\": ""}
1616
},
1717
"require": {
18-
"symfony/config": "^4.4.1 | ^5.0",
19-
"symfony/dependency-injection": "^4.4.1 | ^5.0",
20-
"symfony/http-kernel": "^4.4.13 | ^5.1.5",
21-
"symfony/http-foundation": "^4.4.1 | ^5.0",
22-
"symfony/routing": "^4.4.1 | ^5.0",
23-
"symfony/web-profiler-bundle": "^4.4.1 | ^5.0",
18+
"php": ">=7.4",
19+
"symfony/config": "^4.4.1 | ^5.0 | ^6.0",
20+
"symfony/dependency-injection": "^4.4.1 | ^5.0 | ^6.0",
21+
"symfony/http-kernel": "^4.4.13 | ^5.1.5 | ^6.0",
22+
"symfony/http-foundation": "^4.4.1 | ^5.0 | ^6.0",
23+
"symfony/routing": "^4.4.1 | ^5.0 | ^6.0",
24+
"symfony/web-profiler-bundle": "^4.4.1 | ^5.0 | ^6.0",
2425
"twig/twig": "^1.38 | ^2.7 | ^3.0"
2526
},
2627
"prefer-stable": true,

0 commit comments

Comments
 (0)