Skip to content

Commit c40aa8e

Browse files
committed
Container::getComponents() parameters removed (BC break)
1 parent 71321c9 commit c40aa8e

6 files changed

Lines changed: 11 additions & 161 deletions

File tree

phpstan.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,8 @@ parameters:
1717
count: 5
1818
path: src/ComponentModel/Component.php
1919

20-
- # iterator wrapping is not expressible in return type
21-
message: '#^Method Nette\\ComponentModel\\Container\:\:getComponents\(\) should return array\<int\|string, Nette\\ComponentModel\\IComponent\> but returns CallbackFilterIterator\<mixed, mixed, RecursiveIteratorIterator\<Nette\\ComponentModel\\RecursiveComponentIterator\>\>\|RecursiveIteratorIterator\<Nette\\ComponentModel\\RecursiveComponentIterator\>\.$#'
22-
identifier: return.type
23-
count: 1
24-
path: src/ComponentModel/Container.php
25-
2620
- # IContainer::getComponent() has optional $throw parameter in implementation
2721
message: '#^Method Nette\\ComponentModel\\IContainer\:\:getComponent\(\) invoked with 2 parameters, 1 required\.$#'
2822
identifier: arguments.count
2923
count: 1
3024
path: src/ComponentModel/Container.php
31-
32-
- # duck-typing: IComponent may be IContainer with getComponents()
33-
message: '#^Call to an undefined method Nette\\ComponentModel\\IComponent\:\:getComponents\(\)\.$#'
34-
identifier: method.notFound
35-
count: 1
36-
path: src/ComponentModel/RecursiveComponentIterator.php

src/ComponentModel/Container.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,17 @@ protected function createComponent(string $name): ?IComponent
171171

172172
/**
173173
* Returns all immediate child components.
174-
* @return array<int|string, IComponent>
174+
* @return IComponent[]
175175
*/
176-
final public function getComponents(): iterable
176+
final public function getComponents(): array
177177
{
178-
$filterType = func_get_args()[1] ?? null;
179-
if (func_get_args()[0] ?? null) { // back compatibility
180-
$iterator = new RecursiveComponentIterator($this->components);
181-
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
182-
if ($filterType) {
183-
$iterator = new \CallbackFilterIterator($iterator, fn($item) => $item instanceof $filterType);
184-
}
185-
return $iterator;
178+
if (func_get_args()[0] ?? null) {
179+
throw new Nette\DeprecatedException(__METHOD__ . '() with recursive flag is deprecated. Use getComponentTree() instead.');
186180
}
187-
188-
return $filterType
189-
? array_filter($this->components, fn($item) => $item instanceof $filterType)
190-
: $this->components;
181+
if (func_get_args()[1] ?? null) {
182+
throw new Nette\DeprecatedException('Using Container::getComponents() with filter type is deprecated.');
183+
}
184+
return $this->components;
191185
}
192186

193187

src/ComponentModel/IContainer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getComponent(string $name): ?IComponent;
3434

3535
/**
3636
* Returns immediate child components.
37-
* @return array<int|string, IComponent>
37+
* @return IComponent[]
3838
*/
39-
function getComponents(): iterable;
39+
function getComponents(): array;
4040
}

src/ComponentModel/RecursiveComponentIterator.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/ComponentModel/Container.getComponents.phpt

Lines changed: 0 additions & 87 deletions
This file was deleted.

tests/types/component-types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function testContainer(TestContainer $container): void
112112
);
113113

114114
assertType(
115-
'array<int|string, Nette\ComponentModel\IComponent>',
115+
'array<Nette\ComponentModel\IComponent>',
116116
$container->getComponents(),
117117
);
118118

0 commit comments

Comments
 (0)