snapshots = $snapshots ?? new SnapshotStore(); } /** * @inheritDoc */ public function findings( int $product_id, WC_Product $product, array $definition ): array { unset( $product ); $title = (string) ( $this->snapshots->readCurrentFieldValue( $product_id, 'title' ) ?? '' ); if ( '' === trim( $title ) ) { return array( array( 'code' => 'title_missing', 'severity' => 'warning', 'field' => 'title', 'message' => __( 'The title is empty.', 'ai-product-tools' ), 'label' => __( 'title missing', 'ai-product-tools' ), ), ); } $findings = array(); $max_chars = isset( $definition['structure']['maxChars'] ) ? (int) $definition['structure']['maxChars'] : 60; $length = TextMetrics::charCount( $title ); if ( $length > $max_chars ) { $findings[] = array( 'code' => 'title_too_long', 'severity' => 'warning', 'field' => 'title', /* translators: %1$d: measured character count. %2$d: the template's allowed character count. */ 'message' => sprintf( __( 'Title is %1$d characters; this template allows %2$d.', 'ai-product-tools' ), $length, $max_chars ), 'label' => __( 'title too long', 'ai-product-tools' ), 'measured' => $length, 'limit' => $max_chars, ); } $banned = StructureBannedPhrases::of( $definition ); $banned_finding = BannedPhraseCheck::finding( $title, $banned, 'title' ); if ( null !== $banned_finding ) { $findings[] = $banned_finding; } return $findings; } /** * @inheritDoc */ public function provenanceFieldMap(): array { return array( 'title' => 'title' ); } }