mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-10 04:02:42 +02:00
Ran `make rector-fix` (deadCode + codeQuality prepared sets) over the PSR-4 class trees (Core/Domain/Cli/Infrastructure). Net -600 lines: dead-code removal and the empty-if/else collapse (the feedback_simplify_empty_else pattern this adoption targeted). 99 files mechanically transformed. The output was reviewed against the full test suite + PHPStan + a targeted scan; this commit is the CORRECTED pass (no broken state in history): - FIX (Rector bug): its boolean inversion dropped the parens around an assignment-in-condition — `if (($rKey = array_search(...)) === false)` became `if ($rKey = array_search(...) !== false)`, assigning the bool to $rKey and unsetting the wrong array offset. Restored parens in 7 sites (BouquetService, ChannelService, CategoryService). PHPStan caught only 1 of the 7; the rest were silent. Added BouquetServiceTest as a regression (proven to fail on the broken form). - FIX (pre-existing, same class): GroupService::removeGroupFromUsers had the identical dropped-parens bug already in the tree — corrected here too. - FIX: ServersCronJob::pingServer returns floor() (float) under an `: int` return type — added an (int) cast. - ACCEPT: LocallyCalledStaticMethodToNonStaticRector converted 25 locally-called private static helpers to instance methods (behaviour-preserving; call sites rewritten). Updated MonitorCommandTest's reflection helper to invoke on a constructor-less instance. Verified: PHPStan level 5 clean (0), suite 691 tests / 0 errors. NOTE: do not re-run `make rector-fix` on this tree without first skipping the inversion rule — the dropped-parens bug is deterministic and would return.
69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace XcVm\Infrastructure\Database;
|
|
|
|
use XcVm\Core\Database\DatabaseHandler;
|
|
|
|
/**
|
|
* DatabaseFactory — создание, хранение и закрытие глобального подключения к БД.
|
|
*
|
|
* Singleton-реестр: entry points вызывают set($db), потребители — get().
|
|
*
|
|
* @package XC_VM_Infrastructure_Database
|
|
* @author Divarion_D <https://github.com/Divarion-D>
|
|
* @copyright 2025-2026 Vateron Media
|
|
* @link https://github.com/Vateron-Media/XC_VM
|
|
* @license AGPL-3.0 https://www.gnu.org/licenses/agpl-3.0.html
|
|
*/
|
|
|
|
class DatabaseFactory {
|
|
/** @var DatabaseHandler|null */
|
|
private static $instance;
|
|
|
|
/**
|
|
* Сохраняет экземпляр DatabaseHandler в singleton-реестре.
|
|
*/
|
|
public static function set(DatabaseHandler $db): void {
|
|
self::$instance = $db;
|
|
}
|
|
|
|
/**
|
|
* Возвращает текущий DatabaseHandler.
|
|
*/
|
|
public static function get(): ?DatabaseHandler {
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Создаёт DatabaseHandler из config.ini и кладёт в global $db + singleton.
|
|
*/
|
|
public static function connect() {
|
|
global $db;
|
|
|
|
if (is_object($db) && method_exists($db, 'ping') && $db->ping()) {
|
|
self::$instance = $db;
|
|
return;
|
|
}
|
|
|
|
if (is_object($db)) {
|
|
$db->close_mysql();
|
|
$db = null;
|
|
}
|
|
|
|
$db = new DatabaseHandler();
|
|
self::$instance = $db;
|
|
}
|
|
|
|
/**
|
|
* Закрывает глобальное подключение к БД.
|
|
*/
|
|
public static function close() {
|
|
global $db;
|
|
if (is_object($db)) {
|
|
$db->close_mysql();
|
|
$db = null;
|
|
}
|
|
self::$instance = null;
|
|
}
|
|
}
|