Skip to content

Commit 926bf43

Browse files
authored
Symfony 6 (#8)
* Allowed Symfony 6 * Dropped unsupported PHP versions * Added type hints and remove redundant PHP docs
1 parent a6bfa95 commit 926bf43

11 files changed

+37
-165
lines changed

BoxDrawings.php

+2-17
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@ 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

23-
/**
24-
* @return string
25-
*/
2621
public function getStartCommentPrefix(): string
2722
{
2823
$prefix = $this->getCharset()[0];
@@ -31,9 +26,6 @@ public function getStartCommentPrefix(): string
3126
return $prefix;
3227
}
3328

34-
/**
35-
* @return string
36-
*/
3729
public function getEndCommentPrefix(): string
3830
{
3931
$prefix = $this->getCharset()[2];
@@ -42,10 +34,6 @@ public function getEndCommentPrefix(): string
4234
return $prefix;
4335
}
4436

45-
/**
46-
* @param int $length
47-
* @return void
48-
*/
4937
public function blockChanged(int $length): void
5038
{
5139
$this->length = $length;
@@ -55,9 +43,6 @@ public function blockChanged(int $length): void
5543
}
5644
}
5745

58-
/**
59-
* @return array
60-
*/
6146
private function getCharset(): array
6247
{
6348
return self::CHARSETS[$this->charsetIndex];

Bundle/DependencyInjection/OroTwigInspectorExtension.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@
1212
*/
1313
class OroTwigInspectorExtension extends Extension
1414
{
15-
/**
16-
* {@inheritDoc}
17-
*/
18-
public function load(array $configs, ContainerBuilder $container)
15+
public function load(array $configs, ContainerBuilder $container): void
1916
{
2017
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2118
$loader->load('services.yml');
2219
}
2320

24-
/**
25-
* {@inheritDoc}
26-
*/
27-
public function getAlias()
21+
public function getAlias(): string
2822
{
2923
return 'oro_twig_inspector';
3024
}

Controller/OpenTemplateController.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,22 @@
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

22-
/**
23-
* @param Environment $twig
24-
* @param FileLinkFormatter $fileLinkFormatter
25-
*/
2620
public function __construct(Environment $twig, FileLinkFormatter $fileLinkFormatter)
2721
{
2822
$this->twig = $twig;
2923
$this->fileLinkFormatter = $fileLinkFormatter;
3024
}
3125

3226
/**
33-
* @param Request $request
34-
* @param string $template
35-
* @return RedirectResponse
3627
* @throws \Twig\Error\LoaderError
3728
* @throws \Twig\Error\RuntimeError
3829
* @throws \Twig\Error\SyntaxError
3930
*/
40-
public function __invoke(Request $request, string $template)
31+
public function __invoke(Request $request, string $template): RedirectResponse
4132
{
4233
$line = $request->query->get('line', 1);
4334

DataCollector/TwigInspectorCollector.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,15 @@
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

28-
/**
29-
* {@inheritDoc}
30-
*/
31-
public function getName()
22+
public function getName(): string
3223
{
3324
return 'twig_inspector';
3425
}

Twig/DebugInfoNodeVisitor.php

+5-21
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,27 +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-
* @param Node $node
91-
* @return NodeReference
92-
*/
93-
protected function getReference(Node $node): string
80+
protected function getReference(Node $node): NodeReference
9481
{
9582
return new NodeReference($node->getAttribute('name'), $node->getTemplateName(), $node->getTemplateLine());
9683
}
9784

98-
/**
99-
* {@inheritdoc}
100-
*/
101-
public function getPriority()
85+
public function getPriority(): int
10286
{
10387
return 0;
10488
}

Twig/HtmlCommentsExtension.php

+5-46
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,16 @@ 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

32-
/**
33-
* @param RequestStack $requestStack
34-
* @param UrlGeneratorInterface $urlGenerator
35-
* @param BoxDrawings $boxDrawings
36-
*/
3727
public function __construct(
3828
RequestStack $requestStack,
3929
UrlGeneratorInterface $urlGenerator,
@@ -44,9 +34,6 @@ public function __construct(
4434
$this->boxDrawings = $boxDrawings;
4535
}
4636

47-
/**
48-
* @param NodeReference $ref
49-
*/
5037
public function start(NodeReference $ref): void
5138
{
5239
if (!$this->isEnabled($ref)) {
@@ -55,9 +42,6 @@ public function start(NodeReference $ref): void
5542
ob_start();
5643
}
5744

58-
/**
59-
* @param NodeReference $ref
60-
*/
6145
public function end(NodeReference $ref): void
6246
{
6347
if (!$this->isEnabled($ref)) {
@@ -84,10 +68,6 @@ public function end(NodeReference $ref): void
8468
echo $content;
8569
}
8670

87-
/**
88-
* @param NodeReference $ref
89-
* @return bool
90-
*/
9171
protected function isEnabled(NodeReference $ref): bool
9272
{
9373
$request = $this->requestStack->getCurrentRequest();
@@ -99,10 +79,6 @@ protected function isEnabled(NodeReference $ref): bool
9979
return '.html.twig' === substr($ref->getTemplate(), -10);
10080
}
10181

102-
/**
103-
* @param string $string
104-
* @return bool
105-
*/
10682
protected function isSupported(string $string): bool
10783
{
10884
// has HTML tags
@@ -123,44 +99,27 @@ protected function isSupported(string $string): bool
12399
return true;
124100
}
125101

126-
/**
127-
* @param NodeReference $ref
128-
* @return string
129-
*/
130102
private function getStartComment(NodeReference $ref): string
131103
{
132104
$prefix = $this->boxDrawings->getStartCommentPrefix();
133105

134106
return $this->getComment($prefix, $ref);
135107
}
136108

137-
/**
138-
* @param NodeReference $ref
139-
* @return string
140-
*/
141109
private function getEndComment(NodeReference $ref): string
142110
{
143111
$prefix = $this->boxDrawings->getEndCommentPrefix();
144112

145113
return $this->getComment($prefix, $ref);
146114
}
147115

148-
/**
149-
* @param string $prefix
150-
* @param NodeReference $ref
151-
* @return string
152-
*/
153116
protected function getComment(string $prefix, NodeReference $ref): string
154117
{
155118
$link = $this->getLink($ref);
156119

157120
return '<!-- '.$prefix.' '.$ref->getName().' ['.$link.'] #'.$ref->getId().'-->';
158121
}
159122

160-
/**
161-
* @param NodeReference $ref
162-
* @return string
163-
*/
164123
protected function getLink(NodeReference $ref): string
165124
{
166125
return $this->urlGenerator->generate(

Twig/Node/NodeEnd.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,18 +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-
/**
22-
* @param Compiler $compiler
23-
*/
24-
public function compile(Compiler $compiler)
18+
public function compile(Compiler $compiler): void
2519
{
2620
$compiler
2721
->write("\n")

Twig/Node/NodeStart.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +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-
/**
22-
* @param Compiler $compiler
23-
*/
24-
public function compile(Compiler $compiler)
21+
public function compile(Compiler $compiler): void
2522
{
2623
$compiler
2724
->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name')))

0 commit comments

Comments
 (0)