Skip to content

Commit e822326

Browse files
Fix PHPStan type errors and coding standards
- Add @return void annotations to all methods - Fix array type hints to array<string, mixed> - Replace DOING_AJAX constant with wp_doing_ajax() - Fix ini_set parameter type from int to string - Remove error suppression operators (@) - Remove unnecessary isset() check on explode() result
1 parent 7e4ec2b commit e822326

4 files changed

Lines changed: 38 additions & 32 deletions

File tree

classes/Visualizer/Module/AI.php

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ public function __construct( Visualizer_Plugin $plugin ) {
5555
* @since 3.12.0
5656
*
5757
* @access public
58+
* @return void
5859
*/
5960
public function suppressAjaxWarnings() {
60-
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
61-
@ini_set( 'display_errors', '0' );
61+
if ( wp_doing_ajax() ) {
62+
ini_set( 'display_errors', '0' );
6263
}
6364
}
6465

@@ -68,6 +69,7 @@ public function suppressAjaxWarnings() {
6869
* @since 3.12.0
6970
*
7071
* @access public
72+
* @return void
7173
*/
7274
public function generateConfiguration() {
7375
error_log( 'Visualizer AI: generateConfiguration called' );
@@ -119,10 +121,11 @@ public function generateConfiguration() {
119121
* @since 3.12.0
120122
*
121123
* @access public
124+
* @return void
122125
*/
123126
public function analyzeChartImage() {
124127
// Prevent any output before JSON response
125-
@ini_set( 'display_errors', 0 );
128+
ini_set( 'display_errors', '0' );
126129
while ( ob_get_level() ) {
127130
ob_end_clean();
128131
}
@@ -178,13 +181,13 @@ public function analyzeChartImage() {
178181
*
179182
* @access private
180183
*
181-
* @param string $model The AI model to use.
182-
* @param string $prompt The user prompt.
183-
* @param string $chart_type The chart type.
184-
* @param array $chat_history Previous conversation history.
185-
* @param string $current_config Current manual configuration.
184+
* @param string $model The AI model to use.
185+
* @param string $prompt The user prompt.
186+
* @param string $chart_type The chart type.
187+
* @param array<string, mixed> $chat_history Previous conversation history.
188+
* @param string $current_config Current manual configuration.
186189
*
187-
* @return array|WP_Error The response with message and optional configuration.
190+
* @return array<string, mixed>|WP_Error The response with message and optional configuration.
188191
*/
189192
private function _callAIModel( $model, $prompt, $chart_type, $chat_history = array(), $current_config = '' ) {
190193
switch ( $model ) {
@@ -318,12 +321,12 @@ private function _getChartTypeOptions( $chart_type ) {
318321
*
319322
* @access private
320323
*
321-
* @param string $prompt The user prompt.
322-
* @param string $chart_type The chart type.
323-
* @param array $chat_history Previous conversation history.
324-
* @param string $current_config Current manual configuration.
324+
* @param string $prompt The user prompt.
325+
* @param string $chart_type The chart type.
326+
* @param array<string, mixed> $chat_history Previous conversation history.
327+
* @param string $current_config Current manual configuration.
325328
*
326-
* @return array|WP_Error The response with message and optional configuration.
329+
* @return array<string, mixed>|WP_Error The response with message and optional configuration.
327330
*/
328331
private function _callOpenAI( $prompt, $chart_type, $chat_history = array(), $current_config = '' ) {
329332
error_log( 'Visualizer AI: Calling OpenAI API' );
@@ -420,12 +423,12 @@ private function _callOpenAI( $prompt, $chart_type, $chat_history = array(), $cu
420423
*
421424
* @access private
422425
*
423-
* @param string $prompt The user prompt.
424-
* @param string $chart_type The chart type.
425-
* @param array $chat_history Previous conversation history.
426-
* @param string $current_config Current manual configuration.
426+
* @param string $prompt The user prompt.
427+
* @param string $chart_type The chart type.
428+
* @param array<string, mixed> $chat_history Previous conversation history.
429+
* @param string $current_config Current manual configuration.
427430
*
428-
* @return array|WP_Error The response with message and optional configuration.
431+
* @return array<string, mixed>|WP_Error The response with message and optional configuration.
429432
*/
430433
private function _callGemini( $prompt, $chart_type, $chat_history = array(), $current_config = '' ) {
431434
$api_key = get_option( 'visualizer_gemini_api_key', '' );
@@ -498,12 +501,12 @@ private function _callGemini( $prompt, $chart_type, $chat_history = array(), $cu
498501
*
499502
* @access private
500503
*
501-
* @param string $prompt The user prompt.
502-
* @param string $chart_type The chart type.
503-
* @param array $chat_history Previous conversation history.
504-
* @param string $current_config Current manual configuration.
504+
* @param string $prompt The user prompt.
505+
* @param string $chart_type The chart type.
506+
* @param array<string, mixed> $chat_history Previous conversation history.
507+
* @param string $current_config Current manual configuration.
505508
*
506-
* @return array|WP_Error The response with message and optional configuration.
509+
* @return array<string, mixed>|WP_Error The response with message and optional configuration.
507510
*/
508511
private function _callClaude( $prompt, $chart_type, $chat_history = array(), $current_config = '' ) {
509512
$api_key = get_option( 'visualizer_claude_api_key', '' );
@@ -583,7 +586,7 @@ private function _callClaude( $prompt, $chart_type, $chat_history = array(), $cu
583586
*
584587
* @param string $text The AI response text.
585588
*
586-
* @return array The parsed response with message and optional configuration.
589+
* @return array<string, mixed> The parsed response with message and optional configuration.
587590
*/
588591
private function _parseResponse( $text ) {
589592
error_log( 'Visualizer AI: Parsing response: ' . substr( $text, 0, 200 ) . '...' );
@@ -661,7 +664,7 @@ private function _parseResponse( $text ) {
661664
* @param string $model The AI model to use.
662665
* @param string $image_data Base64 encoded image data.
663666
*
664-
* @return array|WP_Error The analysis result or WP_Error on failure.
667+
* @return array<string, mixed>|WP_Error The analysis result or WP_Error on failure.
665668
*/
666669
private function _analyzeChartImageWithAI( $model, $image_data ) {
667670
error_log( 'Visualizer AI: Analyzing image with model: ' . $model );
@@ -687,7 +690,7 @@ private function _analyzeChartImageWithAI( $model, $image_data ) {
687690
*
688691
* @param string $image_data Base64 encoded image data.
689692
*
690-
* @return array|WP_Error The analysis result or WP_Error on failure.
693+
* @return array<string, mixed>|WP_Error The analysis result or WP_Error on failure.
691694
*/
692695
private function _analyzeImageWithOpenAI( $image_data ) {
693696
error_log( 'Visualizer AI: Analyzing image with OpenAI Vision' );
@@ -806,7 +809,7 @@ private function _analyzeImageWithOpenAI( $image_data ) {
806809
*
807810
* @param string $image_data Base64 encoded image data.
808811
*
809-
* @return array|WP_Error The analysis result or WP_Error on failure.
812+
* @return array<string, mixed>|WP_Error The analysis result or WP_Error on failure.
810813
*/
811814
private function _analyzeImageWithGemini( $image_data ) {
812815
error_log( 'Visualizer AI: Analyzing image with Gemini Vision' );
@@ -920,7 +923,7 @@ private function _analyzeImageWithGemini( $image_data ) {
920923
*
921924
* @param string $image_data Base64 encoded image data.
922925
*
923-
* @return array|WP_Error The analysis result or WP_Error on failure.
926+
* @return array<string, mixed>|WP_Error The analysis result or WP_Error on failure.
924927
*/
925928
private function _analyzeImageWithClaude( $image_data ) {
926929
error_log( 'Visualizer AI: Analyzing image with Claude Vision' );
@@ -937,7 +940,7 @@ private function _analyzeImageWithClaude( $image_data ) {
937940

938941
// Detect media type from data URL
939942
$media_type = 'image/jpeg';
940-
if ( isset( $image_parts[0] ) && preg_match( '/data:(image\/[^;]+)/', $image_parts[0], $matches ) ) {
943+
if ( preg_match( '/data:(image\/[^;]+)/', $image_parts[0], $matches ) ) {
941944
$media_type = $matches[1];
942945
}
943946

@@ -1050,7 +1053,7 @@ private function _analyzeImageWithClaude( $image_data ) {
10501053
*
10511054
* @param string $text The AI response text.
10521055
*
1053-
* @return array The parsed result with chart_type, title, csv_data, and styling.
1056+
* @return array<string, mixed> The parsed result with chart_type, title, csv_data, and styling.
10541057
*/
10551058
private function _parseImageAnalysisResponse( $text ) {
10561059
error_log( 'Visualizer AI: Parsing image analysis response' );

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ private function handleTabularData() {
11941194
*/
11951195
public function uploadData() {
11961196
// Prevent any PHP warnings/errors from contaminating the response
1197-
@ini_set( 'display_errors', '0' );
1197+
ini_set( 'display_errors', '0' );
11981198

11991199
// if this is being called internally from pro and VISUALIZER_DO_NOT_DIE is set.
12001200
// otherwise, assume this is a normal web request.

classes/Visualizer/Render/Page/AISettings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private function _maskAPIKey( $key ) {
5858
* @since 3.12.0
5959
*
6060
* @access protected
61+
* @return void
6162
*/
6263
protected function _renderContent() {
6364
echo '<div class="wrap">';
@@ -199,6 +200,7 @@ protected function _renderContent() {
199200
* @since 3.12.0
200201
*
201202
* @access private
203+
* @return void
202204
*/
203205
private function _saveSettings() {
204206
if ( isset( $_POST['visualizer_openai_api_key'] ) ) {

classes/Visualizer/Render/Sidebar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ protected function _renderChartControlsSettings() {
844844
* Renders AI Configuration group.
845845
*
846846
* @access protected
847+
* @return void
847848
*/
848849
protected function _renderAIConfigurationGroup() {
849850
// Check if PRO features are locked

0 commit comments

Comments
 (0)