Skip to content

Align doc types admin with WordPress coding standard#16

Merged
erseco merged 1 commit intomainfrom
feature/fix-code-to-pass-linter-checks
Oct 13, 2025
Merged

Align doc types admin with WordPress coding standard#16
erseco merged 1 commit intomainfrom
feature/fix-code-to-pass-linter-checks

Conversation

@erseco
Copy link
Copy Markdown
Collaborator

@erseco erseco commented Oct 13, 2025

Summary

  • reformat admin/class-resolate-doc-types.php to follow the WordPress Coding Standards with tabs, docblocks, and consistent array indentation
  • document the local PHP_CodeSniffer workflow in AGENTS.md so developers can auto-fix with phpcbf before linting with phpcs

Testing

  • ./vendor/bin/phpcbf --standard=.phpcs.xml.dist (fails: No such file or directory)
  • ./vendor/bin/phpcs --standard=.phpcs.xml.dist (fails: No such file or directory)

https://chatgpt.com/codex/tasks/task_e_68ed7929f00883228c8ac360c3c1d942

Comment on lines +28 to +98
* @param string $hook Current hook suffix.
*/
public function enqueue_assets( $hook ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( ! $screen || 'edit-resolate_doc_type' !== $screen->id ) {
return;
}

wp_enqueue_media();
wp_enqueue_script( 'jquery' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script(
'resolate-doc-types',
plugins_url( 'admin/js/resolate-doc-types.js', RESOLATE_PLUGIN_FILE ),
array( 'jquery', 'underscore', 'wp-color-picker' ),
RESOLATE_VERSION,
true
);
wp_enqueue_style(
'resolate-doc-types',
plugins_url( 'admin/css/resolate-doc-types.css', RESOLATE_PLUGIN_FILE ),
array(),
RESOLATE_VERSION
);
wp_enqueue_media();
wp_enqueue_script( 'jquery' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script(
'resolate-doc-types',
plugins_url( 'admin/js/resolate-doc-types.js', RESOLATE_PLUGIN_FILE ),
array( 'jquery', 'underscore', 'wp-color-picker' ),
RESOLATE_VERSION,
true
);
wp_enqueue_style(
'resolate-doc-types',
plugins_url( 'admin/css/resolate-doc-types.css', RESOLATE_PLUGIN_FILE ),
array(),
RESOLATE_VERSION
);

$term_id = isset( $_GET['tag_ID'] ) ? intval( $_GET['tag_ID'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$schema = array();
$template_id = 0;
$template_ext = '';
if ( $term_id > 0 ) {
$schema = get_term_meta( $term_id, 'schema', true );
if ( ! is_array( $schema ) ) {
$schema = get_term_meta( $term_id, 'resolate_type_fields', true );
if ( ! is_array( $schema ) ) {
$schema = array();
}
}
$template_id = intval( get_term_meta( $term_id, 'resolate_type_template_id', true ) );
$template_ext = sanitize_key( (string) get_term_meta( $term_id, 'resolate_type_template_type', true ) );
}
$term_id = isset( $_GET['tag_ID'] ) ? intval( $_GET['tag_ID'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$schema = array();
$template_id = 0;
$template_ext = '';
if ( $term_id > 0 ) {
$schema = get_term_meta( $term_id, 'schema', true );
if ( ! is_array( $schema ) ) {
$schema = get_term_meta( $term_id, 'resolate_type_fields', true );
if ( ! is_array( $schema ) ) {
$schema = array();
}
}
$template_id = intval( get_term_meta( $term_id, 'resolate_type_template_id', true ) );
$template_ext = sanitize_key( (string) get_term_meta( $term_id, 'resolate_type_template_type', true ) );
}

$schema_slugs = array();
foreach ( $schema as $item ) {
if ( is_array( $item ) && ! empty( $item['slug'] ) ) {
$schema_slugs[] = sanitize_key( $item['slug'] );
}
}
$schema_slugs = array();
foreach ( $schema as $item ) {
if ( is_array( $item ) && ! empty( $item['slug'] ) ) {
$schema_slugs[] = sanitize_key( $item['slug'] );
}
}

wp_localize_script(
'resolate-doc-types',
'resolateDocTypes',
array(
'ajax' => array(
'url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'resolate_doc_type_template' ),
),
'i18n' => array(
'select' => __( 'Seleccionar archivo', 'resolate' ),
'remove' => __( 'Eliminar', 'resolate' ),
'fieldsDetected' => __( 'Campos detectados', 'resolate' ),
'noFields' => __( 'No se encontraron campos en la plantilla.', 'resolate' ),
'typeDocx' => __( 'Plantilla DOCX', 'resolate' ),
'typeOdt' => __( 'Plantilla ODT', 'resolate' ),
'typeUnknown' => __( 'Formato desconocido', 'resolate' ),
'diffAdded' => __( 'Campos nuevos', 'resolate' ),
'diffRemoved' => __( 'Campos eliminados', 'resolate' ),
),
'schema' => $schema_slugs,
'templateId' => $template_id,
'templateExt'=> $template_ext,
)
);
}
wp_localize_script(
'resolate-doc-types',
'resolateDocTypes',
array(
'ajax' => array(
'url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'resolate_doc_type_template' ),
),
'i18n' => array(
'select' => __( 'Seleccionar archivo', 'resolate' ),
'remove' => __( 'Eliminar', 'resolate' ),
'fieldsDetected' => __( 'Campos detectados', 'resolate' ),
'noFields' => __( 'No se encontraron campos en la plantilla.', 'resolate' ),
'typeDocx' => __( 'Plantilla DOCX', 'resolate' ),
'typeOdt' => __( 'Plantilla ODT', 'resolate' ),
'typeUnknown' => __( 'Formato desconocido', 'resolate' ),
'diffAdded' => __( 'Campos nuevos', 'resolate' ),
'diffRemoved' => __( 'Campos eliminados', 'resolate' ),
),
'schema' => $schema_slugs,
'templateId' => $template_id,
'templateExt' => $template_ext,
)

Check warning

Code scanning / PHPMD

Code Size Rules: CyclomaticComplexity Warning

The method enqueue_assets() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
@erseco erseco merged commit 1e237bd into main Oct 13, 2025
3 of 4 checks passed
@erseco erseco deleted the feature/fix-code-to-pass-linter-checks branch November 30, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants