Skip to content

Commit 6de2e8e

Browse files
committed
Рефакторинг
1 parent 887ec5f commit 6de2e8e

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

psalm.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
88
allowStringToStandInForClass="true"
9-
allowCoercionFromStringToClassConst="true"
109
findUnusedPsalmSuppress="true"
1110
skipChecksOnUnresolvableIncludes="true"
1211
>
@@ -53,6 +52,11 @@
5352
<directory name="/"/>
5453
</errorLevel>
5554
</InvalidThrow>
55+
<UnresolvableInclude>
56+
<errorLevel type="suppress">
57+
<directory name="/"/>
58+
</errorLevel>
59+
</UnresolvableInclude>
5660
<UndefinedMagicMethod>
5761
<errorLevel type="suppress">
5862
<directory name="/"/>

src/CompilerContainer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ public function cacheContainer(
185185
require_once $compiledContainerFile;
186186

187187
$classCompiledContainerName = '\\'.$classCompiledContainerName;
188-
188+
/** @psalm-suppress LessSpecificReturnStatement */
189189
return new $classCompiledContainerName();
190190
}
191191

192192
/**
193193
* Задать ID модуля.
194194
*
195-
* @param string $moduleId
195+
* @param string $moduleId ID модуля.
196196
*
197197
* @return CompilerContainer
198198
*/
@@ -218,7 +218,7 @@ private function createCacheDirectory(string $dir) : void
218218
}
219219

220220
/**
221-
* Gets the container class.
221+
* Класс контейнера.
222222
*
223223
* @param string $env Окружение.
224224
* @param boolean $debug Режим отладки.
@@ -234,7 +234,10 @@ private function getContainerClass(string $env, bool $debug) : string
234234

235235
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) {
236236
throw new InvalidArgumentException(
237-
sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->environment)
237+
sprintf(
238+
'The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.',
239+
$env
240+
)
238241
);
239242
}
240243

@@ -260,7 +263,9 @@ private function dumpContainer(ConfigCache $cache, ContainerBuilder $container,
260263
}
261264

262265
$dumper = new PhpDumper($container);
266+
/** @psalm-suppress UndefinedClass */
263267
if (class_exists(\ProxyManager\Configuration::class) && class_exists(ProxyDumper::class)) {
268+
/** @psalm-suppress InvalidArgument */
264269
$dumper->setProxyDumper(new ProxyDumper());
265270
}
266271

src/DI/AbstractServiceContainer.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Exception;
7+
use LogicException;
78
use ProklUng\ContainerBoilerplate\CompilerContainer;
89
use ProklUng\ContainerBoilerplate\Utils\BitrixSettingsDiAdapter;
910
use Symfony\Component\DependencyInjection\Container;
@@ -57,7 +58,7 @@ abstract class AbstractServiceContainer
5758
*/
5859
public function __construct()
5960
{
60-
$this->debug = (bool)$_ENV['DEBUG'] ?? true;
61+
$this->debug = !array_key_exists('DEBUG', $_ENV) ? true : (bool)$_ENV['DEBUG'];
6162
$this->environment = $this->debug ? 'dev' : 'prod';
6263
}
6364

@@ -73,7 +74,7 @@ abstract public function initContainer() : void;
7374
* Загрузка всего хозяйства.
7475
*
7576
* @return void
76-
* @throws Exception
77+
* @throws Exception | LogicException
7778
*/
7879
public function load() : void
7980
{
@@ -83,6 +84,11 @@ public function load() : void
8384

8485
$this->createContainer();
8586
$compilerContainer = new CompilerContainer($_SERVER['DOCUMENT_ROOT']);
87+
88+
if (!$this->moduleId) {
89+
throw new LogicException('Children of AbstractServiceContainer must define moduleId property.');
90+
}
91+
8692
$compilerContainer->setModuleId($this->moduleId);
8793

8894
// Кэшировать контейнер?
@@ -130,9 +136,10 @@ public static function getInstance() : Container
130136
/**
131137
* Экземпляр контейнера.
132138
*
133-
* @return Container
139+
* @return Container|null
140+
* @throws Exception
134141
*/
135-
public function getContainer(): Container
142+
public function getContainer(): ?Container
136143
{
137144
return static::$container;
138145
}

src/Resource/FileBitrixSettingsResource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ public function __construct(string $resource)
4040
*/
4141
public function __toString(): string
4242
{
43-
return $this->resource;
43+
return (string)$this->resource;
4444
}
4545

4646
/**
4747
* @return string The canonicalized, absolute path to the resource.
4848
*/
4949
public function getResource(): string
5050
{
51-
return $this->resource;
51+
return (string)$this->resource;
5252
}
5353

5454
/**
5555
* {@inheritdoc}
5656
*/
5757
public function isFresh(int $timestamp): bool
5858
{
59-
return false !== @filemtime($this->resource) && $this->timestamp >= $timestamp;
59+
return false !== @filemtime((string)$this->resource) && $this->timestamp >= $timestamp;
6060
}
6161
}

0 commit comments

Comments
 (0)