Skip to content

Commit 3b7fb6c

Browse files
committed
strict typing
1 parent 672024c commit 3b7fb6c

File tree

8 files changed

+82
-120
lines changed

8 files changed

+82
-120
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changelog
88
* Drop support for old Symfony versions
99
* Supprt PHP 8.1 - 8.3
1010
* Drop support for old PHP versions
11+
* TranslatableInterface now uses typehints, adjust your implementations accordingly.
1112
* Use DateTimeInterface instead of DateTime.
1213
* Adjust to doctrine and twig BC breaks. If you extended classes or customized services, check for old `Twig_*` classes or `Doctrine\Common\Persistence` namespace.
1314

src/DependencyInjection/Compiler/AddPublishedVotersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function process(ContainerBuilder $container): void
3939

4040
$voters = new \SplPriorityQueue();
4141
foreach ($container->findTaggedServiceIds('cmf_published_voter') as $id => $attributes) {
42-
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
42+
$priority = $attributes[0]['priority'] ?? 0;
4343
$voters->insert(new Reference($id), $priority);
4444
}
4545

src/Templating/Helper/Cmf.php

Lines changed: 62 additions & 86 deletions
Large diffs are not rendered by default.

src/Translatable/TranslatableInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ interface TranslatableInterface
2323
* @return string|bool The locale of this model or false if
2424
* translations are disabled in this project
2525
*/
26-
public function getLocale();
26+
public function getLocale(): bool|string;
2727

2828
/**
29-
* @param string|bool $locale The local for this model, or false if
29+
* @param bool|string $locale The local for this model, or false if
3030
* translations are disabled in this project
3131
*/
32-
public function setLocale($locale);
32+
public function setLocale(bool|string $locale): void;
3333
}

tests/Functional/DependencyInjection/CmfCoreExtensionTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
class CmfCoreExtensionTest extends TestCase
2020
{
21-
/**
22-
* @var ContainerBuilder
23-
*/
24-
private $container;
21+
private ContainerBuilder $container;
2522

2623
protected function setUp(): void
2724
{

tests/Functional/Templating/Helper/CmfHierarchyTest.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,8 @@
2121

2222
class CmfHierarchyTest extends BaseTestCase
2323
{
24-
/**
25-
* @var AuthorizationCheckerInterface|MockObject
26-
*/
27-
private $publishWorkflowChecker;
28-
29-
/**
30-
* @var Cmf
31-
*/
32-
private $helper;
24+
private MockObject&AuthorizationCheckerInterface $publishWorkflowChecker;
25+
private Cmf $helper;
3326

3427
public function setUp(): void
3528
{
@@ -39,14 +32,14 @@ public function setUp(): void
3932
$this->publishWorkflowChecker = $this->createMock(AuthorizationCheckerInterface::class);
4033
$this->publishWorkflowChecker
4134
->method('isGranted')
42-
->will($this->returnValue(true))
35+
->willReturn(true)
4336
;
4437

4538
$this->helper = new Cmf($this->publishWorkflowChecker);
4639
$this->helper->setDoctrineRegistry($dbManager->getRegistry(), 'default');
4740
}
4841

49-
public function testGetDescendants()
42+
public function testGetDescendants(): void
5043
{
5144
$this->assertEquals([], $this->helper->getDescendants(null));
5245

@@ -60,7 +53,7 @@ public function testGetDescendants()
6053
/**
6154
* @dataProvider getPrevData
6255
*/
63-
public function testGetPrev($expected, $path, $anchor = null, $depth = null, $class = 'Doctrine\ODM\PHPCR\Document\Generic')
56+
public function testGetPrev(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null, string $class = Generic::class): void
6457
{
6558
$prev = $this->helper->getPrev($path, $anchor, $depth);
6659
if (null === $expected) {
@@ -71,7 +64,7 @@ public function testGetPrev($expected, $path, $anchor = null, $depth = null, $cl
7164
}
7265
}
7366

74-
public static function getPrevData()
67+
public static function getPrevData(): array
7568
{
7669
return [
7770
[null, null],
@@ -99,7 +92,7 @@ public static function getPrevData()
9992
/**
10093
* @dataProvider getNextData
10194
*/
102-
public function testGetNext($expected, $path, $anchor = null, $depth = null, $class = Generic::class)
95+
public function testGetNext(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null, string $class = Generic::class): void
10396
{
10497
$next = $this->helper->getNext($path, $anchor, $depth);
10598
if (null === $expected) {
@@ -110,7 +103,7 @@ public function testGetNext($expected, $path, $anchor = null, $depth = null, $cl
110103
}
111104
}
112105

113-
public static function getNextData()
106+
public static function getNextData(): array
114107
{
115108
return [
116109
[null, null],
@@ -139,7 +132,7 @@ public static function getNextData()
139132
/**
140133
* @dataProvider getPrevLinkableData
141134
*/
142-
public function testGetPrevLinkable($expected, $path, $anchor = null, $depth = null)
135+
public function testGetPrevLinkable(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null): void
143136
{
144137
$prev = $this->helper->getPrevLinkable($path, $anchor, $depth);
145138
if (null === $expected) {
@@ -150,7 +143,7 @@ public function testGetPrevLinkable($expected, $path, $anchor = null, $depth = n
150143
}
151144
}
152145

153-
public static function getPrevLinkableData()
146+
public static function getPrevLinkableData(): array
154147
{
155148
// TODO: expand test case
156149
return [
@@ -164,7 +157,7 @@ public static function getPrevLinkableData()
164157
/**
165158
* @dataProvider getNextLinkableData
166159
*/
167-
public function testGetNextLinkable($expected, $path, $anchor = null, $depth = null)
160+
public function testGetNextLinkable(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null): void
168161
{
169162
$next = $this->helper->getNextLinkable($path, $anchor, $depth);
170163
if (null === $expected) {
@@ -175,7 +168,7 @@ public function testGetNextLinkable($expected, $path, $anchor = null, $depth = n
175168
}
176169
}
177170

178-
public static function getNextLinkableData()
171+
public static function getNextLinkableData(): array
179172
{
180173
// TODO: expand test case
181174
return [

tests/Functional/Twig/ServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class ServiceTest extends BaseTestCase
1818
{
19-
public function testContainer()
19+
public function testContainer(): void
2020
{
2121
/** @var \Twig\Environment $twig */
2222
$twig = $this->getContainer()->get('test.service_container')->get('twig');

tests/Unit/Twig/Extension/CmfExtensionTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,17 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Cmf\Bundle\CoreBundle\Templating\Helper\Cmf;
1717
use Symfony\Cmf\Bundle\CoreBundle\Twig\Extension\CmfExtension;
18-
use Twig\Environment;
19-
use Twig\Loader\ArrayLoader;
2018

2119
class CmfExtensionTest extends TestCase
2220
{
2321
private Cmf&MockObject $cmfHelper;
24-
private Environment $env;
2522
private CmfExtension $cmfExtension;
2623

2724
public function setUp(): void
2825
{
2926
$this->cmfHelper = $this->createMock(Cmf::class);
3027

3128
$this->cmfExtension = new CmfExtension($this->cmfHelper);
32-
$this->env = new Environment(new ArrayLoader([]));
33-
$this->env->addExtension($this->cmfExtension);
3429
}
3530

3631
/**
@@ -54,7 +49,7 @@ public function testFunctions($methodName, array $methodArguments, $helperMethod
5449
public function getFunctionsData(): array
5550
{
5651
return [
57-
['isPublished', ['document1']],
52+
['isPublished', [$this]],
5853
['isLinkable', ['document1']],
5954
['getChild', ['parent', 'name']],
6055
['getChildren', ['parent', true], 'getChildren', ['parent', true, false, null, false, null]],

0 commit comments

Comments
 (0)