style: auto-fix PHPCS violations via phpcbf

This commit is contained in:
peptiderepo
2026-06-16 15:17:38 +00:00
parent 49934b2c25
commit 73cd2df294
9 changed files with 120 additions and 116 deletions

View File

@@ -38,39 +38,39 @@ class PRC_Rest_Controller {
register_rest_route(
self::NAMESPACE,
'/presets',
[
array(
'methods' => 'GET',
'callback' => [ $this, 'get_presets' ],
'callback' => array( $this, 'get_presets' ),
'permission_callback' => '__return_true',
]
)
);
register_rest_route(
self::NAMESPACE,
'/presets/(?P<slug>[a-z0-9-]+)',
[
array(
'methods' => 'GET',
'callback' => [ $this, 'get_preset' ],
'callback' => array( $this, 'get_preset' ),
'permission_callback' => '__return_true',
'args' => [
'slug' => [
'args' => array(
'slug' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_title',
'required' => true,
],
],
]
),
),
)
);
register_rest_route(
self::NAMESPACE,
'/calculate',
[
array(
'methods' => 'POST',
'callback' => [ $this, 'calculate' ],
'callback' => array( $this, 'calculate' ),
'permission_callback' => '__return_true',
'args' => $this->get_calculate_args(),
]
)
);
}
@@ -107,7 +107,7 @@ class PRC_Rest_Controller {
return new \WP_Error(
'prc_preset_not_found',
__( 'Preset not found.', 'peptide-reconstitution-calculator' ),
[ 'status' => 404 ]
array( 'status' => 404 )
);
}
@@ -137,31 +137,31 @@ class PRC_Rest_Controller {
* @return array<string, array<string, mixed>>
*/
private function get_calculate_args(): array {
return [
'vial_mg' => [
return array(
'vial_mg' => array(
'type' => 'number',
'required' => true,
'sanitize_callback' => 'floatval',
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
],
'water_ml' => [
),
'water_ml' => array(
'type' => 'number',
'required' => true,
'sanitize_callback' => 'floatval',
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
],
'desired_dose' => [
),
'desired_dose' => array(
'type' => 'number',
'required' => true,
'sanitize_callback' => 'floatval',
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
],
'dose_unit' => [
),
'dose_unit' => array(
'type' => 'string',
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => fn( $v ) => in_array( $v, [ 'mcg', 'mg' ], true ),
],
];
'validate_callback' => fn( $v ) => in_array( $v, array( 'mcg', 'mg' ), true ),
),
);
}
}

View File

@@ -22,7 +22,7 @@ class PRC_Autoloader {
* @return void
*/
public static function register(): void {
spl_autoload_register( [ __CLASS__, 'autoload' ] );
spl_autoload_register( array( __CLASS__, 'autoload' ) );
}
/**

View File

@@ -27,7 +27,7 @@ class PRC_Cache_Listener {
* @return void Side effect: registers action hooks.
*/
public static function register(): void {
$callback = [ __CLASS__, 'invalidate' ];
$callback = array( __CLASS__, 'invalidate' );
// Dosing row lifecycle — affects calculator presets.
add_action( 'pr_core_after_dosing_row_publish', $callback );

View File

@@ -29,17 +29,17 @@ class PRC_Calculator {
public static function boot(): void {
// Frontend shortcode — always available.
$shortcode = new PRC_Shortcode();
add_action( 'init', [ $shortcode, 'register' ] );
add_action( 'init', array( $shortcode, 'register' ) );
// REST API — serves presets to the JS calculator.
add_action( 'rest_api_init', [ new PRC_Rest_Controller(), 'register_routes' ] );
add_action( 'rest_api_init', array( new PRC_Rest_Controller(), 'register_routes' ) );
// Cache invalidation — keep presets in sync with PR Core dosing data.
PRC_Cache_Listener::register();
// Admin notice when PR Core is absent.
if ( is_admin() && ! self::is_pr_core_active() ) {
add_action( 'admin_notices', [ __CLASS__, 'render_pr_core_notice' ] );
add_action( 'admin_notices', array( __CLASS__, 'render_pr_core_notice' ) );
}
}
@@ -70,7 +70,7 @@ class PRC_Calculator {
}
// Only show on plugins page and the calculator's own pages.
$show_on = [ 'plugins', 'settings_page_prc-settings' ];
$show_on = array( 'plugins', 'settings_page_prc-settings' );
if ( ! in_array( $screen->id, $show_on, true ) ) {
return;
}

View File

@@ -27,11 +27,11 @@ class PRC_Default_Presets {
* @return array<int, array<string, mixed>>
*/
public static function get_all(): array {
return [
[
return array(
array(
'slug' => 'bpc-157',
'name' => 'BPC-157',
'vial_sizes_mg' => [ 5, 10 ],
'vial_sizes_mg' => array( 5, 10 ),
'default_vial_mg' => 5,
'recommended_water_ml' => 2.0,
'dose_range_min' => 200,
@@ -41,11 +41,11 @@ class PRC_Default_Presets {
'evidence_strength' => 'observational',
'dosing_row_count' => 0,
'source' => 'default',
],
[
),
array(
'slug' => 'tb-500',
'name' => 'TB-500',
'vial_sizes_mg' => [ 2, 5, 10 ],
'vial_sizes_mg' => array( 2, 5, 10 ),
'default_vial_mg' => 5,
'recommended_water_ml' => 2.0,
'dose_range_min' => 2000,
@@ -55,11 +55,11 @@ class PRC_Default_Presets {
'evidence_strength' => 'preclinical',
'dosing_row_count' => 0,
'source' => 'default',
],
[
),
array(
'slug' => 'semaglutide',
'name' => 'Semaglutide',
'vial_sizes_mg' => [ 2, 5, 10 ],
'vial_sizes_mg' => array( 2, 5, 10 ),
'default_vial_mg' => 5,
'recommended_water_ml' => 2.0,
'dose_range_min' => 0.25,
@@ -69,11 +69,11 @@ class PRC_Default_Presets {
'evidence_strength' => 'meta-analysis',
'dosing_row_count' => 0,
'source' => 'default',
],
[
),
array(
'slug' => 'cjc-1295-dac',
'name' => 'CJC-1295 (DAC)',
'vial_sizes_mg' => [ 2, 5 ],
'vial_sizes_mg' => array( 2, 5 ),
'default_vial_mg' => 2,
'recommended_water_ml' => 1.0,
'dose_range_min' => 1000,
@@ -83,11 +83,11 @@ class PRC_Default_Presets {
'evidence_strength' => 'preclinical',
'dosing_row_count' => 0,
'source' => 'default',
],
[
),
array(
'slug' => 'ipamorelin',
'name' => 'Ipamorelin',
'vial_sizes_mg' => [ 2, 5 ],
'vial_sizes_mg' => array( 2, 5 ),
'default_vial_mg' => 5,
'recommended_water_ml' => 2.0,
'dose_range_min' => 100,
@@ -97,11 +97,11 @@ class PRC_Default_Presets {
'evidence_strength' => 'preclinical',
'dosing_row_count' => 0,
'source' => 'default',
],
[
),
array(
'slug' => 'pt-141',
'name' => 'PT-141 (Bremelanotide)',
'vial_sizes_mg' => [ 2, 10 ],
'vial_sizes_mg' => array( 2, 10 ),
'default_vial_mg' => 10,
'recommended_water_ml' => 2.0,
'dose_range_min' => 500,
@@ -111,11 +111,11 @@ class PRC_Default_Presets {
'evidence_strength' => 'rct-large',
'dosing_row_count' => 0,
'source' => 'default',
],
[
),
array(
'slug' => 'mk-677',
'name' => 'MK-677 (Ibutamoren)',
'vial_sizes_mg' => [ 15, 30 ],
'vial_sizes_mg' => array( 15, 30 ),
'default_vial_mg' => 30,
'recommended_water_ml' => 3.0,
'dose_range_min' => 10,
@@ -125,11 +125,11 @@ class PRC_Default_Presets {
'evidence_strength' => 'rct-small',
'dosing_row_count' => 0,
'source' => 'default',
],
[
),
array(
'slug' => 'ghrp-6',
'name' => 'GHRP-6',
'vial_sizes_mg' => [ 5, 10 ],
'vial_sizes_mg' => array( 5, 10 ),
'default_vial_mg' => 5,
'recommended_water_ml' => 2.0,
'dose_range_min' => 100,
@@ -139,7 +139,7 @@ class PRC_Default_Presets {
'evidence_strength' => 'preclinical',
'dosing_row_count' => 0,
'source' => 'default',
],
];
),
);
}
}

View File

@@ -52,13 +52,13 @@ class PRC_Math {
? $desired_dose / 1000
: $desired_dose;
$concentration_mg_per_ml = self::concentration_mg_per_ml( $vial_mg, $water_ml );
$concentration_mg_per_ml = self::concentration_mg_per_ml( $vial_mg, $water_ml );
$concentration_mcg_per_unit = self::concentration_mcg_per_unit( $vial_mg, $water_ml );
$injection_ml = self::injection_volume_ml( $dose_mg, $concentration_mg_per_ml );
$syringe_units = self::syringe_units( $injection_ml );
$doses_per_vial = self::doses_per_vial( $vial_mg, $dose_mg );
$injection_ml = self::injection_volume_ml( $dose_mg, $concentration_mg_per_ml );
$syringe_units = self::syringe_units( $injection_ml );
$doses_per_vial = self::doses_per_vial( $vial_mg, $dose_mg );
return [
return array(
'concentration_mg_per_ml' => round( $concentration_mg_per_ml, 4 ),
'concentration_mcg_per_unit' => round( $concentration_mcg_per_unit, 2 ),
'injection_volume_ml' => round( $injection_ml, 4 ),
@@ -69,7 +69,7 @@ class PRC_Math {
'desired_dose_mg' => round( $dose_mg, 4 ),
'desired_dose_display' => $desired_dose,
'dose_unit' => $dose_unit,
];
);
}
/**

View File

@@ -89,19 +89,19 @@ class PRC_Preset_Provider {
// could fail to autoload (e.g. fatal error in PR Core bootstrap).
// Fall back to empty array so the caller merges in defaults gracefully.
if ( ! class_exists( 'PR_Core_Peptide_Repository' ) || ! class_exists( 'PR_Core_Dosing_Repository' ) ) {
return [];
return array();
}
$peptide_repo = new PR_Core_Peptide_Repository();
$dosing_repo = new PR_Core_Dosing_Repository();
$peptides = $peptide_repo->find_all( [ 'posts_per_page' => 100 ] );
$presets = [];
$peptides = $peptide_repo->find_all( array( 'posts_per_page' => 100 ) );
$presets = array();
foreach ( $peptides as $peptide ) {
$rows = $dosing_repo->find_by_peptide(
$peptide->id,
[ 'route' => 'subcutaneous' ]
array( 'route' => 'subcutaneous' )
);
if ( empty( $rows ) ) {
@@ -141,26 +141,26 @@ class PRC_Preset_Provider {
$display_name = '';
if ( method_exists( $peptide, 'to_array' ) ) {
$arr = $peptide->to_array();
$arr = $peptide->to_array();
$display_name = $arr['display_name'] ?? $peptide->title ?? '';
} else {
$display_name = $peptide->title ?? '';
}
return [
'slug' => $peptide->slug,
'name' => $display_name ?: $peptide->title,
'vial_sizes_mg' => $vial_sizes,
'default_vial_mg' => $vial_sizes[0] ?? 5,
'recommended_water_ml' => $this->recommend_water_ml( $vial_sizes[0] ?? 5 ),
'dose_range_min' => ! empty( $dose_mins ) ? min( $dose_mins ) : null,
'dose_range_max' => ! empty( $dose_maxs ) ? max( $dose_maxs ) : null,
'dose_unit' => $dose_unit,
'typical_frequency' => $this->most_common_frequency( $rows ),
'evidence_strength' => $peptide->evidence_strength ?? 'preclinical',
'dosing_row_count' => count( $rows ),
'source' => 'pr_core',
];
return array(
'slug' => $peptide->slug,
'name' => $display_name ?: $peptide->title,
'vial_sizes_mg' => $vial_sizes,
'default_vial_mg' => $vial_sizes[0] ?? 5,
'recommended_water_ml' => $this->recommend_water_ml( $vial_sizes[0] ?? 5 ),
'dose_range_min' => ! empty( $dose_mins ) ? min( $dose_mins ) : null,
'dose_range_max' => ! empty( $dose_maxs ) ? max( $dose_maxs ) : null,
'dose_unit' => $dose_unit,
'typical_frequency' => $this->most_common_frequency( $rows ),
'evidence_strength' => $peptide->evidence_strength ?? 'preclinical',
'dosing_row_count' => count( $rows ),
'source' => 'pr_core',
);
}
/**
@@ -176,10 +176,10 @@ class PRC_Preset_Provider {
* @return float[] Standard vial sizes in mg.
*/
private function infer_vial_sizes( array $dose_mins, array $dose_maxs, string $dose_unit ): array {
$standard_sizes = [ 2, 5, 10, 15, 30 ];
$standard_sizes = array( 2, 5, 10, 15, 30 );
if ( empty( $dose_mins ) && empty( $dose_maxs ) ) {
return [ 5, 10 ];
return array( 5, 10 );
}
// Convert everything to mg for comparison.
@@ -187,12 +187,12 @@ class PRC_Preset_Provider {
$all_doses = array_merge( $dose_mins, $dose_maxs );
foreach ( $all_doses as $dose ) {
$mg = ( 'mcg' === $dose_unit ) ? $dose / 1000 : $dose;
$mg = ( 'mcg' === $dose_unit ) ? $dose / 1000 : $dose;
$max_dose_mg = max( $max_dose_mg, $mg );
}
// Pick vials that hold at least 10 doses at the max dose level.
$viable = [];
$viable = array();
foreach ( $standard_sizes as $size ) {
if ( $max_dose_mg > 0 && ( $size / $max_dose_mg ) >= 5 ) {
$viable[] = $size;
@@ -200,7 +200,7 @@ class PRC_Preset_Provider {
}
// Fallback: return two middle sizes if heuristic found nothing.
return ! empty( $viable ) ? array_slice( $viable, 0, 3 ) : [ 5, 10 ];
return ! empty( $viable ) ? array_slice( $viable, 0, 3 ) : array( 5, 10 );
}
/**

View File

@@ -34,7 +34,7 @@ class PRC_Shortcode {
* @return void Side effect: registers shortcode.
*/
public function register(): void {
add_shortcode( 'prc_calculator', [ $this, 'render' ] );
add_shortcode( 'prc_calculator', array( $this, 'render' ) );
}
/**
@@ -47,11 +47,11 @@ class PRC_Shortcode {
* @param array<string, string>|string $atts Shortcode attributes.
* @return string HTML output.
*/
public function render( $atts = [] ): string {
public function render( $atts = array() ): string {
$atts = shortcode_atts(
[
array(
'peptide' => '', // Pre-select a peptide by slug.
],
),
$atts,
'prc_calculator'
);
@@ -81,14 +81,14 @@ class PRC_Shortcode {
wp_enqueue_style(
'prc-calculator',
PRC_PLUGIN_URL . 'assets/css/calculator.css',
[],
array(),
PRC_VERSION
);
wp_enqueue_script(
'prc-calculator',
PRC_PLUGIN_URL . 'assets/js/calculator.js',
[],
array(),
PRC_VERSION,
true
);
@@ -96,23 +96,27 @@ class PRC_Shortcode {
// Pass presets and config to JS — all REST endpoints are public-read,
// so no nonce is needed. The restUrl is provided for future use.
$provider = new PRC_Preset_Provider();
wp_localize_script( 'prc-calculator', 'prcConfig', [
'presets' => $provider->get_all_presets(),
'restUrl' => esc_url_raw( rest_url( 'prc/v1' ) ),
'syringeUnits' => 100, // Must match PRC_Math::SYRINGE_UNITS_PER_ML and calculator.js SYRINGE_UNITS_PER_ML.
'i18n' => [
'selectPeptide' => __( 'Select a peptide…', 'peptide-reconstitution-calculator' ),
'customEntry' => __( 'Custom / Manual Entry', 'peptide-reconstitution-calculator' ),
'calculate' => __( 'Calculate', 'peptide-reconstitution-calculator' ),
'reset' => __( 'Reset', 'peptide-reconstitution-calculator' ),
'concentration' => __( 'Concentration', 'peptide-reconstitution-calculator' ),
'injectionVol' => __( 'Injection Volume', 'peptide-reconstitution-calculator' ),
'syringeUnits' => __( 'Syringe Units', 'peptide-reconstitution-calculator' ),
'dosesPerVial' => __( 'Doses Per Vial', 'peptide-reconstitution-calculator' ),
'perUnit' => __( 'per unit', 'peptide-reconstitution-calculator' ),
'disclaimer' => __( 'For informational purposes only. Not medical advice. Always consult a qualified healthcare professional.', 'peptide-reconstitution-calculator' ),
],
] );
wp_localize_script(
'prc-calculator',
'prcConfig',
array(
'presets' => $provider->get_all_presets(),
'restUrl' => esc_url_raw( rest_url( 'prc/v1' ) ),
'syringeUnits' => 100, // Must match PRC_Math::SYRINGE_UNITS_PER_ML and calculator.js SYRINGE_UNITS_PER_ML.
'i18n' => array(
'selectPeptide' => __( 'Select a peptide…', 'peptide-reconstitution-calculator' ),
'customEntry' => __( 'Custom / Manual Entry', 'peptide-reconstitution-calculator' ),
'calculate' => __( 'Calculate', 'peptide-reconstitution-calculator' ),
'reset' => __( 'Reset', 'peptide-reconstitution-calculator' ),
'concentration' => __( 'Concentration', 'peptide-reconstitution-calculator' ),
'injectionVol' => __( 'Injection Volume', 'peptide-reconstitution-calculator' ),
'syringeUnits' => __( 'Syringe Units', 'peptide-reconstitution-calculator' ),
'dosesPerVial' => __( 'Doses Per Vial', 'peptide-reconstitution-calculator' ),
'perUnit' => __( 'per unit', 'peptide-reconstitution-calculator' ),
'disclaimer' => __( 'For informational purposes only. Not medical advice. Always consult a qualified healthcare professional.', 'peptide-reconstitution-calculator' ),
),
)
);
$this->assets_enqueued = true;
}
@@ -155,7 +159,7 @@ class PRC_Shortcode {
<select id="prc-vial-select" class="prc-field__input prc-field__input--half"></select>
<div class="prc-field__custom-wrap">
<input type="number" id="prc-vial-mg" class="prc-field__input prc-field__input--half"
step="0.1" min="0.1" placeholder="5" />
step="0.1" min="0.1" placeholder="5" />
<span class="prc-field__unit"><?php esc_html_e( 'mg', 'peptide-reconstitution-calculator' ); ?></span>
</div>
</div>
@@ -168,7 +172,7 @@ class PRC_Shortcode {
</label>
<div class="prc-field__row">
<input type="number" id="prc-water-ml" class="prc-field__input"
step="0.1" min="0.1" placeholder="2.0" />
step="0.1" min="0.1" placeholder="2.0" />
<span class="prc-field__unit"><?php esc_html_e( 'mL', 'peptide-reconstitution-calculator' ); ?></span>
</div>
</div>
@@ -180,7 +184,7 @@ class PRC_Shortcode {
</label>
<div class="prc-field__row">
<input type="number" id="prc-desired-dose" class="prc-field__input"
step="any" min="0" placeholder="250" />
step="any" min="0" placeholder="250" />
<select id="prc-dose-unit" class="prc-field__input prc-field__input--unit">
<option value="mcg">mcg</option>
<option value="mg">mg</option>

View File

@@ -37,9 +37,9 @@ PRC_Autoloader::register();
/* ── Activation / Deactivation ────────────────────────────────────────── */
register_activation_hook( __FILE__, [ 'PRC_Activator', 'activate' ] );
register_deactivation_hook( __FILE__, [ 'PRC_Deactivator', 'deactivate' ] );
register_activation_hook( __FILE__, array( 'PRC_Activator', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'PRC_Deactivator', 'deactivate' ) );
/* ── Boot ─────────────────────────────────────────────────────────────── */
add_action( 'plugins_loaded', [ 'PRC_Calculator', 'boot' ] );
add_action( 'plugins_loaded', array( 'PRC_Calculator', 'boot' ) );