chore(2meet-data-optimizer): make the hardening branch pass PHPStan and PHPCS
Anti-EAV Lint + Quality Gate / anti-eav-lint (pull_request) Successful in 14s
Tests / PHP Lint (pull_request) Successful in 1m0s
Tests / PHPCS (pull_request) Successful in 1m15s
Tests / Unit Tests (pull_request) Successful in 57s
Tests / Integration Tests (pull_request) Successful in 1m14s
Tests / PHPStan (pull_request) Successful in 34s
Anti-EAV Lint + Quality Gate / anti-eav-lint (pull_request) Successful in 14s
Tests / PHP Lint (pull_request) Successful in 1m0s
Tests / PHPCS (pull_request) Successful in 1m15s
Tests / Unit Tests (pull_request) Successful in 57s
Tests / Integration Tests (pull_request) Successful in 1m14s
Tests / PHPStan (pull_request) Successful in 34s
- CI PHPStan (level 6, baseline for pre-existing debt) failed on 35 errors in
code added on hardening/2.0: missing iterable value types (PHPDoc only), a
redundant method_exists() in uninstall.php, and the new WP-CLI commands
registered as array('Class', 'instanceMethod') — now array(new Class(), ...)
- Local runs had been masked by a PHPStan tmpDir shared with the act CI runner
(cached container pointing at a removed phar); use a private tmpDir
- Verify: phpstan (private tmpDir) no errors, phpcs clean on changed files,
phpunit Unit 658 OK; dev22 (running this branch) CLI post-status-sync /
bridge-restore-native dry runs OK
This commit is contained in:
@@ -31,10 +31,10 @@ final class TMDO_Entity_Registry {
|
||||
/** @var array<int, array{type:string, group:string, fields:array}> 待建表的 Schema 清單 */
|
||||
private static array $pending_schemas = array();
|
||||
|
||||
/** @var array<string, array<string, array>> 實體類型 → meta_key → 欄位定義(僅未限定 post_type 的群組)*/
|
||||
/** @var array<string, array<string, array<string, mixed>>> 實體類型 → meta_key → 欄位定義(僅未限定 post_type 的群組)*/
|
||||
private static array $unscoped_index = array();
|
||||
|
||||
/** @var array<string, array<string, array<string, array>>> 實體類型 → post_type → meta_key → 欄位定義 */
|
||||
/** @var array<string, array<string, array<string, array<string, mixed>>>> 實體類型 → post_type → meta_key → 欄位定義 */
|
||||
private static array $scoped_index = array();
|
||||
|
||||
/** @var array<string, array<string, string[]>> 實體類型 → 群組名 → 限定的 post_type */
|
||||
@@ -43,10 +43,10 @@ final class TMDO_Entity_Registry {
|
||||
/** @var array<string, array<string, array<string, string[]>>> 實體類型 → 群組名 → 索引名 → 欄位 key */
|
||||
private static array $indexes = array();
|
||||
|
||||
/** @var array<string, array> "entity/group" → 同名群組以不同定義重複註冊的紀錄 */
|
||||
/** @var array<string, array<string, mixed>> "entity/group" → 同名群組以不同定義重複註冊的紀錄 */
|
||||
private static array $collisions = array();
|
||||
|
||||
/** @var array<string, array> "entity/group" → 從 wpdo_registry_meta 還原的孤兒群組 */
|
||||
/** @var array<string, array<string, mixed>> "entity/group" → 從 wpdo_registry_meta 還原的孤兒群組 */
|
||||
private static array $restored = array();
|
||||
|
||||
/** 合法的欄位型別 */
|
||||
@@ -119,7 +119,7 @@ final class TMDO_Entity_Registry {
|
||||
* - unique (bool) 唯一索引
|
||||
* - options (array) enum 選項
|
||||
* - label (string) 顯示名稱
|
||||
* @param array $args 選填:post_types (string[]) — 群組只套用於這些 post_type。
|
||||
* @param array<string, mixed> $args 選填:post_types (string[]) — 群組只套用於這些 post_type。
|
||||
* 多個群組共用 meta_key 時,依 post 本身的類型決定歸屬;
|
||||
* 不屬於任何宣告 post_type 的 post 不受管理(走原生 meta)。
|
||||
* 不列入欄位定義,所以不影響 schema hash 與衝突比對。
|
||||
@@ -183,6 +183,8 @@ final class TMDO_Entity_Registry {
|
||||
|
||||
/**
|
||||
* 驗證並正規化欄位定義(略過缺 key/type 或型別不合法者)。
|
||||
* @param array<int, array<string, mixed>> $fields
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private static function normalize_fields( string $entity_type, string $group_name, array $fields ): array {
|
||||
$normalized = array();
|
||||
@@ -229,6 +231,7 @@ final class TMDO_Entity_Registry {
|
||||
*
|
||||
* @param string[] $native_keys 原生 meta 仍有資料、不可還原的 key。
|
||||
* @return bool 有登錄任何欄位時為 true
|
||||
* @param array<int, array<string, mixed>> $fields
|
||||
*/
|
||||
public static function restore_group( string $entity_type, string $group_name, array $fields, array $native_keys = array() ): bool {
|
||||
if ( ! isset( self::$adapters[ $entity_type ] ) || isset( self::$groups[ $entity_type ][ $group_name ] ) ) {
|
||||
@@ -286,6 +289,7 @@ final class TMDO_Entity_Registry {
|
||||
* 供不帶 post_type 的查詢使用;另外依是否限定 post_type 分別建索引。
|
||||
*
|
||||
* @param string[] $post_types 群組限定的 post_type;空陣列表示不限定。
|
||||
* @param array<string, mixed> $field
|
||||
*/
|
||||
private static function index_field( string $entity_type, array $field, array $post_types ): void {
|
||||
self::$field_index[ $entity_type ][ $field['key'] ] = $field;
|
||||
@@ -312,6 +316,8 @@ final class TMDO_Entity_Registry {
|
||||
* 記錄同名群組衝突(每個 entity/group 每請求一筆),並寫入 warning。
|
||||
*
|
||||
* 註冊每個請求都會跑,warning 以 transient 節流為每天一次,避免灌爆 wpdo_errors。
|
||||
* @param array<int, array<string, mixed>> $existing
|
||||
* @param array<int, array<string, mixed>> $incoming
|
||||
*/
|
||||
private static function record_collision( string $entity_type, string $group_name, array $existing, array $incoming ): void {
|
||||
$id = $entity_type . '/' . $group_name;
|
||||
|
||||
@@ -648,6 +648,7 @@ final class TMDO_Hook_Bus {
|
||||
* 欄位定義查詢;post meta 依該 post 本身的 post_type 解析(見 TMDO_Entity_Registry::get_field())。
|
||||
*
|
||||
* 先做不帶 post_type 的查詢:大多數 key 不受管理,可省下 get_post_type()。
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private static function field_for( string $type, int $object_id, string $meta_key ): ?array {
|
||||
$field_def = TMDO_Entity_Registry::get_field( $type, $meta_key );
|
||||
|
||||
Reference in New Issue
Block a user