@@ -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 ' );
0 commit comments