From 6de2e8e65dabf8d1d1353bcd9061b699412465a9 Mon Sep 17 00:00:00 2001 From: ProklUng Date: Fri, 16 Jul 2021 08:27:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- psalm.xml | 6 +++++- src/CompilerContainer.php | 13 +++++++++---- src/DI/AbstractServiceContainer.php | 15 +++++++++++---- src/Resource/FileBitrixSettingsResource.php | 6 +++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/psalm.xml b/psalm.xml index 56b40f0..69351e2 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,7 +6,6 @@ xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" allowStringToStandInForClass="true" - allowCoercionFromStringToClassConst="true" findUnusedPsalmSuppress="true" skipChecksOnUnresolvableIncludes="true" > @@ -53,6 +52,11 @@ + + + + + diff --git a/src/CompilerContainer.php b/src/CompilerContainer.php index 2e99ad1..117a5a5 100644 --- a/src/CompilerContainer.php +++ b/src/CompilerContainer.php @@ -185,14 +185,14 @@ public function cacheContainer( require_once $compiledContainerFile; $classCompiledContainerName = '\\'.$classCompiledContainerName; - + /** @psalm-suppress LessSpecificReturnStatement */ return new $classCompiledContainerName(); } /** * Задать ID модуля. * - * @param string $moduleId + * @param string $moduleId ID модуля. * * @return CompilerContainer */ @@ -218,7 +218,7 @@ private function createCacheDirectory(string $dir) : void } /** - * Gets the container class. + * Класс контейнера. * * @param string $env Окружение. * @param boolean $debug Режим отладки. @@ -234,7 +234,10 @@ private function getContainerClass(string $env, bool $debug) : string if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { throw new InvalidArgumentException( - sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->environment) + sprintf( + 'The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', + $env + ) ); } @@ -260,7 +263,9 @@ private function dumpContainer(ConfigCache $cache, ContainerBuilder $container, } $dumper = new PhpDumper($container); + /** @psalm-suppress UndefinedClass */ if (class_exists(\ProxyManager\Configuration::class) && class_exists(ProxyDumper::class)) { + /** @psalm-suppress InvalidArgument */ $dumper->setProxyDumper(new ProxyDumper()); } diff --git a/src/DI/AbstractServiceContainer.php b/src/DI/AbstractServiceContainer.php index 3074979..ab7d0eb 100644 --- a/src/DI/AbstractServiceContainer.php +++ b/src/DI/AbstractServiceContainer.php @@ -4,6 +4,7 @@ use Closure; use Exception; +use LogicException; use ProklUng\ContainerBoilerplate\CompilerContainer; use ProklUng\ContainerBoilerplate\Utils\BitrixSettingsDiAdapter; use Symfony\Component\DependencyInjection\Container; @@ -57,7 +58,7 @@ abstract class AbstractServiceContainer */ public function __construct() { - $this->debug = (bool)$_ENV['DEBUG'] ?? true; + $this->debug = !array_key_exists('DEBUG', $_ENV) ? true : (bool)$_ENV['DEBUG']; $this->environment = $this->debug ? 'dev' : 'prod'; } @@ -73,7 +74,7 @@ abstract public function initContainer() : void; * Загрузка всего хозяйства. * * @return void - * @throws Exception + * @throws Exception | LogicException */ public function load() : void { @@ -83,6 +84,11 @@ public function load() : void $this->createContainer(); $compilerContainer = new CompilerContainer($_SERVER['DOCUMENT_ROOT']); + + if (!$this->moduleId) { + throw new LogicException('Children of AbstractServiceContainer must define moduleId property.'); + } + $compilerContainer->setModuleId($this->moduleId); // Кэшировать контейнер? @@ -130,9 +136,10 @@ public static function getInstance() : Container /** * Экземпляр контейнера. * - * @return Container + * @return Container|null + * @throws Exception */ - public function getContainer(): Container + public function getContainer(): ?Container { return static::$container; } diff --git a/src/Resource/FileBitrixSettingsResource.php b/src/Resource/FileBitrixSettingsResource.php index 0696298..feb9601 100644 --- a/src/Resource/FileBitrixSettingsResource.php +++ b/src/Resource/FileBitrixSettingsResource.php @@ -40,7 +40,7 @@ public function __construct(string $resource) */ public function __toString(): string { - return $this->resource; + return (string)$this->resource; } /** @@ -48,7 +48,7 @@ public function __toString(): string */ public function getResource(): string { - return $this->resource; + return (string)$this->resource; } /** @@ -56,6 +56,6 @@ public function getResource(): string */ public function isFresh(int $timestamp): bool { - return false !== @filemtime($this->resource) && $this->timestamp >= $timestamp; + return false !== @filemtime((string)$this->resource) && $this->timestamp >= $timestamp; } }