Skip to content

Commit 09883ad

Browse files
authored
Issue #4: Fix missing return types that cause warnings with Symfony 5.4 (#5)
1 parent 9a42c46 commit 09883ad

File tree

8 files changed

+45
-22
lines changed

8 files changed

+45
-22
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"symfony/framework-bundle": "^4.0|^5.0",
2525
"symfony/property-access": "^4.0|^5.0",
2626
"symfony/translation-contracts": "^1.0|^2.0",
27+
"symfony/yaml": "^4.0|^5.0",
2728
"twig/twig": "^2.10|^3.0"
2829
},
2930
"require-dev": {

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Configuration implements ConfigurationInterface
1010
/**
1111
* {@inheritdoc}
1212
*/
13-
public function getConfigTreeBuilder()
13+
public function getConfigTreeBuilder(): TreeBuilder
1414
{
1515
$builder = new TreeBuilder('slope_it_breadcrumb');
1616
$builder->getRootNode()

src/DependencyInjection/SlopeItBreadcrumbExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class SlopeItBreadcrumbExtension extends Extension
1212
/**
1313
* {@inheritdoc}
1414
*/
15-
public function getAlias()
15+
public function getAlias(): string
1616
{
1717
return 'slope_it_breadcrumb';
1818
}
1919

2020
/**
2121
* {@inheritdoc}
2222
*/
23-
public function load(array $configs, ContainerBuilder $container)
23+
public function load(array $configs, ContainerBuilder $container): void
2424
{
2525
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2626
$loader->load('services.yml');

src/EventListener/BreadcrumbListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(BreadcrumbBuilder $breadcrumbBuilder, Reader $annota
2525
$this->annotationReader = $annotationReader;
2626
}
2727

28-
public function onKernelController(ControllerEvent $event)
28+
public function onKernelController(ControllerEvent $event): void
2929
{
3030
// In case controller is not an array (e.g. a closure or an invokable class), we can't do anything.
3131
if (!is_array($event->getController())) {

src/Service/BreadcrumbItemProcessor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public function __construct(
4747
$this->requestStack = $requestStack;
4848
}
4949

50+
/**
51+
* @param array<string, mixed> $variables
52+
*/
5053
public function process(BreadcrumbItem $item, array $variables): ProcessedBreadcrumbItem
5154
{
5255
// Process the label
@@ -85,6 +88,8 @@ public function process(BreadcrumbItem $item, array $variables): ProcessedBreadc
8588

8689
/**
8790
* Returns the value contained in the variable name (with optional property path) of the given expression.
91+
*
92+
* @return mixed
8893
*/
8994
private function parseValue(string $expression, array $variables)
9095
{

src/SlopeItBreadcrumbBundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace SlopeIt\BreadcrumbBundle;
44

55
use SlopeIt\BreadcrumbBundle\DependencyInjection\SlopeItBreadcrumbExtension;
6+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
67
use Symfony\Component\HttpKernel\Bundle\Bundle;
78

89
class SlopeItBreadcrumbBundle extends Bundle
910
{
1011
/**
1112
* {@inheritdoc}
1213
*/
13-
public function getContainerExtension()
14+
public function getContainerExtension(): ?ExtensionInterface
1415
{
1516
return new SlopeItBreadcrumbExtension();
1617
}

src/Twig/BreadcrumbExtension.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ class BreadcrumbExtension extends AbstractExtension
2525
*/
2626
private $template;
2727

28-
/**
29-
* @param BreadcrumbBuilder $builder
30-
* @param BreadcrumbItemProcessor $itemProcessor
31-
* @param string $template
32-
*/
33-
public function __construct(BreadcrumbBuilder $builder, BreadcrumbItemProcessor $itemProcessor, $template)
28+
public function __construct(BreadcrumbBuilder $builder, BreadcrumbItemProcessor $itemProcessor, string $template)
3429
{
3530
$this->builder = $builder;
3631
$this->itemProcessor = $itemProcessor;
@@ -39,8 +34,9 @@ public function __construct(BreadcrumbBuilder $builder, BreadcrumbItemProcessor
3934

4035
/**
4136
* {@inheritDoc}
37+
* @return TwigFunction[]
4238
*/
43-
public function getFunctions()
39+
public function getFunctions(): array
4440
{
4541
return [
4642
new TwigFunction(
@@ -55,20 +51,12 @@ public function getFunctions()
5551
];
5652
}
5753

58-
/**
59-
* {@inheritDoc}
60-
*/
61-
public function getName()
54+
public function getName(): string
6255
{
6356
return 'slope_it_breadcrumb';
6457
}
6558

66-
/**
67-
* Returns the rendered breadcrumb.
68-
*
69-
* @return string
70-
*/
71-
public function renderBreadcrumb(Environment $twig, array $context)
59+
public function renderBreadcrumb(Environment $twig, array $context): string
7260
{
7361
$breadcrumb = [];
7462
foreach ($this->builder->getItems() as $item) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace SlopeIt\Tests\BreadcrumbBundle\DependencyInjection;
5+
6+
use PHPUnit\Framework\TestCase;
7+
use SlopeIt\BreadcrumbBundle\DependencyInjection\SlopeItBreadcrumbExtension;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
10+
class SlopeItBreadcrumbExtensionTest extends TestCase
11+
{
12+
/**
13+
* @test
14+
*/
15+
public function its_template_can_be_overridden_via_configuration()
16+
{
17+
$container = new ContainerBuilder();
18+
19+
$extension = new SlopeItBreadcrumbExtension();
20+
$config = [
21+
'template' => 'some-template.html.twig',
22+
];
23+
24+
$extension->load([$config], $container);
25+
26+
$this->assertSame('some-template.html.twig', $container->getParameter('slope_it_breadcrumb.template'));
27+
}
28+
}

0 commit comments

Comments
 (0)