add missing type hints

Cette révision appartient à :
Daniel Seifert 2023-11-23 15:01:44 +01:00
Parent 5e573a2435
révision 53a9effeac
Signé par: DanielS
ID de la clé GPG: 8A7C4C6ED1915C6F
6 fichiers modifiés avec 110 ajouts et 57 suppressions

Voir le fichier

@ -14,12 +14,12 @@
declare(strict_types=1);
use D3\DIContainerHandler\d3DicHandler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Container;
/**
* @return ContainerBuilder
* @return Container
*/
function d3GetOxidDIC(): ContainerBuilder
function d3GetOxidDIC(): Container
{
return d3DicHandler::getInstance();
}

Voir le fichier

@ -21,6 +21,7 @@ use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Facts\Config\ConfigFile;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@ -29,30 +30,32 @@ class d3DicHandler implements d3DicHandlerInterface
{
/**
* instance
* @var array
* @var null|Container
*/
protected static $_instance;
protected static ?Container $_instance = null;
public static $circularReferenceMethodNames = array(
'getViewConfig'
);
public static array $circularReferenceMethodNames = ['getViewConfig'];
/**
* get instance
* @return ContainerBuilder
*
* @return Container
* @throws Exception
*/
public static function getInstance()
public static function getInstance(): Container
{
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$caller = $trace[1];
$functionName = $caller['function'];
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames)))
{
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
throw oxNew(
Exception::class,
'method '.$functionName." can't use DIC due the danger of circular reference"
);
}
if (null == self::$_instance) {
if (null === self::$_instance) {
$oDicHandler = oxNew(d3DicHandler::class);
self::$_instance = $oDicHandler->buildContainer();
}
@ -62,17 +65,21 @@ class d3DicHandler implements d3DicHandlerInterface
/**
* get instance
* @return ContainerBuilder
*
* @return Container
* @throws Exception
*/
public static function getUncompiledInstance()
public static function getUncompiledInstance(): Container
{
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$caller = $trace[1];
$functionName = $caller['function'];
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames)))
{
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
throw oxNew(
Exception::class,
'method '.$functionName." can't use DIC due the danger of circular reference"
);
}
$oDicHandler = oxNew(d3DicHandler::class);
@ -81,7 +88,7 @@ class d3DicHandler implements d3DicHandlerInterface
return self::$_instance;
}
public static function removeInstance()
public static function removeInstance(): void
{
self::$_instance = null;
}
@ -89,30 +96,35 @@ class d3DicHandler implements d3DicHandlerInterface
/**
* @return Config
*/
public function d3GetConfig()
public function d3GetConfig(): Config
{
return Registry::getConfig();
}
public function d3GetCacheFilePath()
public function d3GetCacheFilePath(): string
{
return $this->d3GetConfig()->getConfigParam('sCompileDir').'/d3DicContainer_'.Registry::getConfig()->getShopId().'.php';
return $this->d3GetConfig()->getConfigParam('sCompileDir').'/d3DicContainer_'.
Registry::getConfig()->getShopId().'.php';
}
/**
* @return d3DIContainerCache|object
* @return Container
*/
public function d3GetCacheContainer()
public function d3GetCacheContainer(): Container
{
require_once $this->d3GetCacheFilePath();
return oxNew(d3DIContainerCache::class);
/** @var Container $container */
$container = oxNew(d3DIContainerCache::class); /** @phpstan-ignore-line */
return $container;
}
/**
* @param $container
* @param ContainerBuilder $container
*
* @return YamlFileLoader
*/
public function d3GetFileLoader($container)
public function d3GetFileLoader(ContainerBuilder $container): YamlFileLoader
{
/** @var YamlFileLoader $fileLoader */
$fileLoader = oxNew(YamlFileLoader::class,
@ -124,9 +136,11 @@ class d3DicHandler implements d3DicHandlerInterface
}
/**
* @param $container
* @param ContainerBuilder $container
*
* @throws Exception
*/
public function loadFiles($container)
public function loadFiles(ContainerBuilder $container): void
{
$loader = $this->d3GetFileLoader($container);
@ -141,17 +155,19 @@ class d3DicHandler implements d3DicHandlerInterface
/**
* @param bool $compileAndDump
* @return ContainerBuilder
*
* @return Container
* @throws Exception
*/
public function buildContainer(bool $compileAndDump = true)
public function buildContainer(bool $compileAndDump = true): Container
{
if ((bool) Registry::get( ConfigFile::class)->getVar( 'iDebug')) startProfile(__METHOD__);
if (Registry::get( ConfigFile::class)->getVar( 'iDebug')) startProfile(__METHOD__);
$config = $this->d3GetConfig();
if ($config->isProductiveMode()
&& false == $config->getConfigParam('iDebug')
&& (false == defined('OXID_PHP_UNIT') || true == defined('D3_MODCFG_TEST'))
if ( $config->isProductiveMode()
&& ! $config->getConfigParam( 'iDebug' )
&& ( ! defined( 'OXID_PHP_UNIT' ) || defined( 'D3_MODCFG_TEST' ) )
&& file_exists($this->d3GetCacheFilePath())
) {
$container = $this->d3GetCacheContainer();
@ -162,19 +178,19 @@ class d3DicHandler implements d3DicHandlerInterface
if ($compileAndDump) {
$container->compile();
if (false == defined('OXID_PHP_UNIT')) {
if ( ! defined( 'OXID_PHP_UNIT' ) ) {
$dumper = new PhpDumper($container);
file_put_contents($this->d3GetCacheFilePath(), $dumper->dump(array('class' => 'd3DIContainerCache')));
}
}
}
if ((bool) Registry::get( ConfigFile::class)->getVar( 'iDebug')) stopProfile(__METHOD__);
if (Registry::get( ConfigFile::class)->getVar( 'iDebug')) stopProfile(__METHOD__);
return $container;
}
public function getContainerBuilder()
public function getContainerBuilder(): ContainerBuilder
{
return oxNew(ContainerBuilder::class);
}

Voir le fichier

@ -15,10 +15,12 @@ declare(strict_types=1);
namespace D3\DIContainerHandler;
use Symfony\Component\DependencyInjection\Container;
/**
* Interface d3DicHandlerInterface
*/
interface d3DicHandlerInterface
{
public static function getInstance();
public static function getInstance(): ?Container;
}

Voir le fichier

@ -18,11 +18,12 @@ namespace D3\DIContainerHandler;
class d3DicUtilities
{
/**
* @param $classNameSpace
* @param bool $additional
* @param string $classNameSpace
* @param string|null $additional
*
* @return string
*/
public static function getServiceId($classNameSpace, $additional = false)
public static function getServiceId(string $classNameSpace, ?string $additional = null): string
{
return strtolower(
($additional ? $additional.'.' : '').
@ -31,11 +32,12 @@ class d3DicUtilities
}
/**
* @param $classNameSpace
* @param $argumentName
* @param string $classNamespace
* @param string $argumentName
*
* @return string
*/
public static function getArgumentId($classNamespace, $argumentName)
public static function getArgumentId(string $classNamespace, string $argumentName): string
{
return strtolower(
$classNamespace.

Voir le fichier

@ -15,15 +15,17 @@ declare(strict_types=1);
namespace D3\DIContainerHandler;
use InvalidArgumentException;
class definitionFileContainer
{
public const TYPE_YAML = 'yml';
protected $definitionFiles = [
protected array $definitionFiles = [
self::TYPE_YAML => []
];
protected $allowedTypes = [
protected array $allowedTypes = [
self::TYPE_YAML
];
@ -32,30 +34,49 @@ class definitionFileContainer
$this->addYamlDefinitions('d3/modcfg/Config/services.yaml');
}
public function addDefinitions($definitionFile, $type)
/**
* @param string $definitionFile
* @param string $type
*
* @return void
*/
public function addDefinitions(string $definitionFile, string $type): void
{
if (!in_array($type, $this->allowedTypes)) {
throw new \InvalidArgumentException('invalid definition file type');
throw new InvalidArgumentException( 'invalid definition file type');
}
$this->definitionFiles[$type][md5($definitionFile)] = $definitionFile;
}
public function addYamlDefinitions($definitionFile)
/**
* @param string $definitionFile
*
* @return void
*/
public function addYamlDefinitions(string $definitionFile): void
{
$this->addDefinitions($definitionFile, self::TYPE_YAML);
}
public function getDefinitions($type)
/**
* @param string $type
*
* @return array
*/
public function getDefinitions(string $type): array
{
if (!in_array($type, $this->allowedTypes)) {
throw new \InvalidArgumentException('invalid definition file type');
throw new InvalidArgumentException( 'invalid definition file type');
}
return $this->definitionFiles[$type];
}
public function getYamlDefinitions()
/**
* @return array
*/
public function getYamlDefinitions(): array
{
return $this->getDefinitions(self::TYPE_YAML);
}
@ -64,17 +85,17 @@ class definitionFileContainer
* @param string $definitionFile
* @return bool
*/
public function has($definitionFile): bool
public function has(string $definitionFile): bool
{
return isset($this->definitionFiles[md5($definitionFile)]);
}
public function getAll()
public function getAll(): array
{
return $this->definitionFiles;
}
public function clear()
public function clear(): void
{
$this->definitionFiles = [];
}

12
phpstan.neon Fichier normal
Voir le fichier

@ -0,0 +1,12 @@
parameters:
scanFiles:
- ../../oxid-esales/oxideshop-ce/source/bootstrap.php
- ../../oxid-esales/oxideshop-ce/source/oxfunctions.php
- ../../oxid-esales/oxideshop-ce/source/overridablefunctions.php
paths:
- .
level: 0
phpVersion: 80300
checkMissingIterableValueType: false
featureToggles:
disableRuntimeReflectionProvider: true