Skip to content

Commit

Permalink
Fix all PHPStan warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Nov 13, 2024
1 parent aa2593f commit de9b9e9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ parameters:
analyseAndScan:
- vendor
ignoreErrors:
- '#Static property ArchiPro\\Silverstripe\\EventDispatcher\\Service\\EventService::\$listeners is never read, only written\.#'
- '#Static property ArchiPro\\Silverstripe\\EventDispatcher\\Service\\EventService::\$loaders is never read, only written\.#'
- '#Static property .* is never read, only written\.#'
- '#Offset \d+ does not exist on array\{\}#'
7 changes: 5 additions & 2 deletions tests/php/Extension/EventDispatchExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\ORM\DataObject;

class EventDispatchExtensionTest extends SapphireTest
{
/** @var string */
protected static $fixture_file = 'EventDispatchExtensionTest.yml';

/** @var class-string<DataObject>[] */
protected static $extra_dataobjects = [
SimpleDataObject::class,
VersionedDataObject::class,
];

/** @var DataObjectEvent[] */
private static array $events = [];
/** @var DataObjectEvent<DataObject>[] */
protected static array $events = [];

public static function setUpBeforeClass(): void
{
Expand Down
6 changes: 4 additions & 2 deletions tests/php/Listener/DataObjectEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
*/
class DataObjectEventListenerTest extends SapphireTest
{
/** @var class-string<DataObject>[] */
protected static $extra_dataobjects = [
SimpleDataObject::class,
VersionedDataObject::class,
];

private array $receivedEvents = [];
/** @var DataObjectEvent<DataObject>[] */
protected array $receivedEvents = [];

protected function setUp(): void
{
Expand Down Expand Up @@ -127,7 +129,7 @@ function (DataObjectEvent $event) {
public function testSelfRegister(): void
{
// Create a mock event service
/** @var MockObject|ListenerProvider $provider */
/** @var MockObject&ListenerProvider $provider */
$provider = $this->createMock(ListenerProvider::class);
$provider->expects($this->once())
->method('addListener')
Expand Down
4 changes: 4 additions & 0 deletions tests/php/Mock/SimpleDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
use ArchiPro\Silverstripe\EventDispatcher\Extension\EventDispatchExtension;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\Extension;

/**
* @property string $Title
*/
class SimpleDataObject extends DataObject implements TestOnly
{

private static string $table_name = 'EventDispatcher_SimpleDataObject';

/** @var array<string, string> */
private static array $db = [
'Title' => 'Varchar',
];

/** @var class-string<Extension<DataObject>>[] */
private static array $extensions = [
EventDispatchExtension::class,
];
Expand Down
3 changes: 3 additions & 0 deletions tests/php/Mock/VersionedDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ArchiPro\Silverstripe\EventDispatcher\Extension\EventDispatchExtension;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\Extension;
use SilverStripe\Versioned\Versioned;

/**
Expand All @@ -16,10 +17,12 @@ class VersionedDataObject extends DataObject implements TestOnly
{
private static string $table_name = 'EventDispatcher_VersionedDataObject';

/** @var array<string, string> */
private static array $db = [
'Title' => 'Varchar',
];

/** @var class-string<Extension<DataObject>>[] */
private static array $extensions = [
EventDispatchExtension::class,
Versioned::class,
Expand Down
5 changes: 5 additions & 0 deletions tests/php/TestListenerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
/**
* This test loader will listen for the event provided in the constructor
* and set the eventFired property to true when the event is fired.
*
* @template T of object
*/
class TestListenerLoader implements ListenerLoaderInterface
{
public bool $loaded = false;
public bool $eventFired = false;

/**
* @param class-string<T> $eventName
*/
public function __construct(
private string $eventName
) {
Expand Down

0 comments on commit de9b9e9

Please sign in to comment.