Skip to content

Commit

Permalink
Рефакторинг
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 16, 2021
1 parent 887ec5f commit 6de2e8e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
6 changes: 5 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
Expand Down Expand Up @@ -53,6 +52,11 @@
<directory name="/"/>
</errorLevel>
</InvalidThrow>
<UnresolvableInclude>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</UnresolvableInclude>
<UndefinedMagicMethod>
<errorLevel type="suppress">
<directory name="/"/>
Expand Down
13 changes: 9 additions & 4 deletions src/CompilerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -218,7 +218,7 @@ private function createCacheDirectory(string $dir) : void
}

/**
* Gets the container class.
* Класс контейнера.
*
* @param string $env Окружение.
* @param boolean $debug Режим отладки.
Expand All @@ -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
)
);
}

Expand All @@ -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());
}

Expand Down
15 changes: 11 additions & 4 deletions src/DI/AbstractServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Exception;
use LogicException;
use ProklUng\ContainerBoilerplate\CompilerContainer;
use ProklUng\ContainerBoilerplate\Utils\BitrixSettingsDiAdapter;
use Symfony\Component\DependencyInjection\Container;
Expand Down Expand Up @@ -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';
}

Expand All @@ -73,7 +74,7 @@ abstract public function initContainer() : void;
* Загрузка всего хозяйства.
*
* @return void
* @throws Exception
* @throws Exception | LogicException
*/
public function load() : void
{
Expand All @@ -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);

// Кэшировать контейнер?
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Resource/FileBitrixSettingsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ public function __construct(string $resource)
*/
public function __toString(): string
{
return $this->resource;
return (string)$this->resource;
}

/**
* @return string The canonicalized, absolute path to the resource.
*/
public function getResource(): string
{
return $this->resource;
return (string)$this->resource;
}

/**
* {@inheritdoc}
*/
public function isFresh(int $timestamp): bool
{
return false !== @filemtime($this->resource) && $this->timestamp >= $timestamp;
return false !== @filemtime((string)$this->resource) && $this->timestamp >= $timestamp;
}
}

0 comments on commit 6de2e8e

Please sign in to comment.