Skip to content

Commit fcf8d0f

Browse files
authored
Merge pull request #511 from mglaman/gh509
2 parents 55c3f43 + 1bba9cf commit fcf8d0f

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

stubs/Drupal/Core/Field/FieldItemList.stub

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ namespace Drupal\Core\Field;
44

55
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
66

7+
/**
8+
* @template T of \Drupal\Core\Field\FieldItemInterface
9+
* @extends ItemList<T>
10+
* @implements FieldItemListInterface<T>
11+
*/
712
class FieldItemList extends ItemList implements FieldItemListInterface {
813

914
/**
1015
* @return \Drupal\Core\Field\FieldItemInterface
1116
*/
12-
protected function createItem($offset = 0, $value = NULL): \Drupal\Core\Field\FieldItemInterface {
17+
protected function createItem(int $offset = 0, ?mixed $value = NULL): \Drupal\Core\Field\FieldItemInterface {
1318
}
1419

1520
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Drupal\Core\TypedData\Plugin\DataType;
4+
5+
use Drupal\Core\TypedData\ComplexDataInterface;
6+
use Drupal\Core\TypedData\ListInterface;
7+
use Drupal\Core\TypedData\TypedData;
8+
use Drupal\Core\TypedData\TypedDataInterface;
9+
10+
/**
11+
* @template T of TypedDataInterface
12+
* @implements \IteratorAggregate<int, T>
13+
* @implements ListInterface<T>
14+
*/
15+
class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
16+
}

tests/src/StubTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace mglaman\PHPStanDrupal\Tests;
6+
7+
use PHPStan\Analyser\Error;
8+
use PHPStan\PhpDoc\StubFilesProvider;
9+
use PHPStan\PhpDoc\StubValidator;
10+
use PHPStan\Testing\PHPStanTestCase;
11+
12+
final class StubTest extends PHPStanTestCase
13+
{
14+
use AdditionalConfigFilesTrait;
15+
16+
public function testValid(): void {
17+
$stubFilesProvider = self::getContainer()
18+
->getByType(StubFilesProvider::class);
19+
// @phpstan-ignore-next-line
20+
$projectStubFiles = $stubFilesProvider->getProjectStubFiles();
21+
22+
$stubValidators = self::getContainer()
23+
->getByType(StubValidator::class);
24+
// @phpstan-ignore-next-line
25+
$stubErrors = $stubValidators->validate($projectStubFiles, true);
26+
$errorsAsArrays = array_map(
27+
static fn (Error $error) => $error->jsonSerialize(),
28+
$stubErrors
29+
);
30+
self::assertEquals(
31+
[],
32+
$errorsAsArrays,
33+
var_export($errorsAsArrays, true)
34+
);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)