Type fixes relating to DI phpstan stubs.

This commit is contained in:
Buster Neece 2024-01-14 13:51:04 -06:00
parent bbf8d56b46
commit 89b1d913a1
No known key found for this signature in database
13 changed files with 73 additions and 5 deletions

View File

@ -336,6 +336,7 @@ return [
*/
foreach ($receivers as $messageClass => $handlerClass) {
$handlers[$messageClass][] = static function ($message) use ($handlerClass, $di) {
/** @var callable $obj */
$obj = $di->get($handlerClass);
return $obj($message);
};

View File

@ -31,6 +31,10 @@ parameters:
scanDirectories:
- ./vendor/zircote/swagger-php/src/Annotations
stubFiles:
- util/phpstan_di.stub
- util/phpstan_phpdi.stub
universalObjectCratesClasses:
- App\Session\NamespaceInterface
- App\View

View File

@ -85,6 +85,9 @@ final class CallableEventDispatcher extends EventDispatcher implements CallableE
}
}
/**
* @param class-string $className
*/
public function addCallableListener(
string $eventName,
string $className,
@ -98,6 +101,9 @@ final class CallableEventDispatcher extends EventDispatcher implements CallableE
);
}
/**
* @param class-string $className
*/
public function removeCallableListener(
string $eventName,
string $className,
@ -109,6 +115,9 @@ final class CallableEventDispatcher extends EventDispatcher implements CallableE
);
}
/**
* @param class-string $className
*/
private function getCallable(
string $className,
?string $method = '__invoke'

View File

@ -8,6 +8,7 @@ use App\Container\ContainerAwareTrait;
use App\Container\EntityManagerAwareTrait;
use App\Container\EnvironmentAwareTrait;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use RecursiveDirectoryIterator;
@ -46,7 +47,10 @@ final class SetupFixturesCommand extends CommandAbstract
continue;
}
/** @var class-string $className */
$className = 'App\\Entity\\Fixture\\' . $fileName;
/** @var FixtureInterface $fixture */
$fixture = $this->di->get($className);
$loader->addFixture($fixture);

View File

@ -114,7 +114,7 @@ final class NowPlayingCommand extends AbstractSyncRunnerCommand
$lookupRaw = $this->nowPlayingCache->getLookup();
$lookup = [];
foreach ($lookupRaw as $stationRow) {
$lookup[$stationRow['short_name']] = (int)($stationRow['updated_at'] ?? 0);
$lookup[$stationRow['short_name']] = $stationRow['updated_at'];
}
$allStations = $this->em->createQuery(

View File

@ -59,7 +59,7 @@ final class ListAction implements SingleActionInterface
[$searchPhrase, $playlist, $special] = $this->parseSearchQuery(
$station,
$searchPhraseFull
$searchPhraseFull ?? ''
);
$cacheKeyParts = [

View File

@ -17,6 +17,12 @@ use App\Radio\Enums\RemoteAdapters;
/**
* Manager class for radio adapters.
*
* @phpstan-type AdapterInfo array<string, array{
* enum: AdapterTypeInterface,
* name: string,
* class: class-string|null
* }>
*/
final class Adapters
{
@ -109,10 +115,11 @@ final class Adapters
/**
* @param array<AdapterTypeInterface> $cases
* @param bool $checkInstalled
* @return mixed[]
* @return AdapterInfo
*/
private function listAdaptersFromEnum(array $cases, bool $checkInstalled = false): array
{
/** @var AdapterInfo $adapters */
$adapters = [];
foreach ($cases as $adapter) {
$adapters[$adapter->getValue()] = [
@ -130,9 +137,10 @@ final class Adapters
return true;
}
/** @var AbstractLocalAdapter $adapter */
$adapter = $this->di->get($adapterInfo['class']);
return $adapter->isInstalled();
return ($adapter instanceof AbstractLocalAdapter)
? $adapter->isInstalled()
: true;
}
);
}

View File

@ -10,5 +10,6 @@ interface AdapterTypeInterface
public function getName(): string;
/** @return class-string|null */
public function getClass(): ?string;
}

View File

@ -24,6 +24,9 @@ enum BackendAdapters: string implements AdapterTypeInterface
};
}
/**
* @return class-string<Liquidsoap>|null
*/
public function getClass(): ?string
{
return match ($this) {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Radio\Enums;
use App\Radio\Frontend\AbstractFrontend;
use App\Radio\Frontend\Icecast;
use App\Radio\Frontend\Shoutcast;
@ -27,6 +28,9 @@ enum FrontendAdapters: string implements AdapterTypeInterface
};
}
/**
* @return class-string<AbstractFrontend>|null
*/
public function getClass(): ?string
{
return match ($this) {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Radio\Enums;
use App\Radio\Remote\AbstractRemote;
use App\Radio\Remote\AzuraRelay;
use App\Radio\Remote\Icecast;
use App\Radio\Remote\Shoutcast1;
@ -31,6 +32,9 @@ enum RemoteAdapters: string implements AdapterTypeInterface
};
}
/**
* @return class-string<AbstractRemote>
*/
public function getClass(): string
{
return match ($this) {

15
util/phpstan_di.stub Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace Psr\Container;
interface ContainerInterface
{
/**
* Finds an entry of the container by its identifier and returns it.
*
* @template T
* @param class-string<T> $id Identifier of the entry to look for.
* @return T Entry.
*/
public function get(string $id);
}

15
util/phpstan_phpdi.stub Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace DI;
class Container
{
/**
* Finds an entry of the container by its identifier and returns it.
*
* @template T
* @param class-string<T> $id Identifier of the entry to look for.
* @return T Entry.
*/
public function get(string $id);
}