Skip to content

Commit b13b49e

Browse files
committed
chore: fix phpcs
1 parent 7cc40d5 commit b13b49e

5 files changed

Lines changed: 129 additions & 17 deletions

File tree

classes/Visualizer/Elementor/Widget.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function get_icon() {
6666
/**
6767
* Get widget categories.
6868
*
69-
* @return array Widget categories.
69+
* @return array<string> Widget categories.
7070
*/
7171
public function get_categories() {
7272
return array( 'general' );
@@ -75,7 +75,7 @@ public function get_categories() {
7575
/**
7676
* Get widget keywords.
7777
*
78-
* @return array Widget keywords.
78+
* @return array<string> Widget keywords.
7979
*/
8080
public function get_keywords() {
8181
return array( 'visualizer', 'chart', 'graph', 'table', 'data' );
@@ -84,7 +84,7 @@ public function get_keywords() {
8484
/**
8585
* Build the select options from all published Visualizer charts.
8686
*
87-
* @return array Associative array of chart ID => label.
87+
* @return array<int|string, string> Associative array of chart ID => label.
8888
*/
8989
private function get_chart_options() {
9090
static $options_cache = null;
@@ -132,6 +132,8 @@ private function get_chart_options() {
132132

133133
/**
134134
* Register widget controls.
135+
*
136+
* @return void
135137
*/
136138
protected function register_controls() {
137139
$this->start_controls_section(
@@ -191,6 +193,8 @@ protected function register_controls() {
191193

192194
/**
193195
* Render the widget output on the frontend.
196+
*
197+
* @return void
194198
*/
195199
protected function render() {
196200
$settings = $this->get_settings_for_display();
@@ -205,7 +209,7 @@ protected function render() {
205209

206210
// Detect Elementor edit / preview context early — needed before do_shortcode().
207211
$is_editor = \Elementor\Plugin::$instance->editor->is_edit_mode() ||
208-
\Elementor\Plugin::$instance->preview->is_preview_mode();
212+
\Elementor\Plugin::$instance->preview->is_preview_mode();
209213

210214
// In the editor, force lazy-loading off so the chart renders immediately in the
211215
// preview iframe without requiring a user-interaction event (scroll, hover, etc.).
@@ -311,9 +315,9 @@ protected function render() {
311315
/**
312316
* Ensure custom CSS class mappings are present in settings for preview rendering.
313317
*
314-
* @param array $settings Chart settings.
315-
* @param int $chart_id Chart ID.
316-
* @return array
318+
* @param array<string, mixed> $settings Chart settings.
319+
* @param int $chart_id Chart ID.
320+
* @return array<string, mixed>
317321
*/
318322
private function apply_custom_css_class_names( $settings, $chart_id ) {
319323
if ( empty( $settings['customcss'] ) || ! is_array( $settings['customcss'] ) ) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"scripts": {
3434
"format": "phpcbf --standard=phpcs.xml --report-summary --report-source",
3535
"lint": "phpcs --standard=phpcs.xml",
36-
"phpstan": "phpstan",
36+
"phpstan": "phpstan --memory-limit=2G",
3737
"phpstan:generate:baseline": "phpstan --generate-baseline --memory-limit=2G"
3838
},
3939
"minimum-stability": "dev",

index.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,26 +145,26 @@ function () {
145145

146146
// ChartJS render library.
147147
if ( ! wp_script_is( 'numeral', 'registered' ) ) {
148-
wp_register_script( 'numeral', VISUALIZER_ABSURL . 'js/lib/numeral.min.js', [], Visualizer_Plugin::VERSION, true );
148+
wp_register_script( 'numeral', VISUALIZER_ABSURL . 'js/lib/numeral.min.js', array(), Visualizer_Plugin::VERSION, true );
149149
}
150150
if ( ! wp_script_is( 'chartjs', 'registered' ) ) {
151-
wp_register_script( 'chartjs', VISUALIZER_ABSURL . 'js/lib/chartjs.min.js', [ 'numeral' ], null, true );
151+
wp_register_script( 'chartjs', VISUALIZER_ABSURL . 'js/lib/chartjs.min.js', array( 'numeral' ), null, true );
152152
}
153-
wp_enqueue_script( 'visualizer-render-chartjs-lib', VISUALIZER_ABSURL . 'js/render-chartjs.js', [ 'chartjs', 'visualizer-customization' ], Visualizer_Plugin::VERSION, true );
153+
wp_enqueue_script( 'visualizer-render-chartjs-lib', VISUALIZER_ABSURL . 'js/render-chartjs.js', array( 'chartjs', 'visualizer-customization' ), Visualizer_Plugin::VERSION, true );
154154

155155
// Google Charts render library.
156-
wp_enqueue_script( 'visualizer-google-jsapi', '//www.gstatic.com/charts/loader.js', [], null, true );
157-
wp_enqueue_script( 'visualizer-render-google-lib', VISUALIZER_ABSURL . 'js/render-google.js', [ 'visualizer-google-jsapi', 'visualizer-customization' ], Visualizer_Plugin::VERSION, true );
156+
wp_enqueue_script( 'visualizer-google-jsapi', '//www.gstatic.com/charts/loader.js', array(), null, true );
157+
wp_enqueue_script( 'visualizer-render-google-lib', VISUALIZER_ABSURL . 'js/render-google.js', array( 'visualizer-google-jsapi', 'visualizer-customization' ), Visualizer_Plugin::VERSION, true );
158158

159159
// DataTable render library + styles.
160160
if ( ! wp_script_is( 'visualizer-datatables', 'registered' ) ) {
161-
wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', [ 'jquery' ], Visualizer_Plugin::VERSION, true );
161+
wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
162162
}
163-
wp_enqueue_script( 'visualizer-render-datatables-lib', VISUALIZER_ABSURL . 'js/render-datatables.js', [ 'visualizer-datatables', 'visualizer-customization' ], Visualizer_Plugin::VERSION, true );
164-
wp_enqueue_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', [], Visualizer_Plugin::VERSION );
163+
wp_enqueue_script( 'visualizer-render-datatables-lib', VISUALIZER_ABSURL . 'js/render-datatables.js', array( 'visualizer-datatables', 'visualizer-customization' ), Visualizer_Plugin::VERSION, true );
164+
wp_enqueue_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION );
165165

166166
// Elementor widget preview handler — uses frontend/element_ready hook.
167-
wp_enqueue_script( 'visualizer-elementor-preview', VISUALIZER_ABSURL . 'js/elementor-widget-preview.js', [ 'jquery', 'elementor-frontend' ], Visualizer_Plugin::VERSION, true );
167+
wp_enqueue_script( 'visualizer-elementor-preview', VISUALIZER_ABSURL . 'js/elementor-widget-preview.js', array( 'jquery', 'elementor-frontend' ), Visualizer_Plugin::VERSION, true );
168168

169169
// Prevent Elementor's editor-preview CSS from hiding our widget.
170170
// Elementor marks widgets without a content_template() as elementor-widget-empty

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ parameters:
66
bootstrapFiles:
77
- %currentWorkingDirectory%/tests/php/static-analysis-stubs/symbols.php
88
- %currentWorkingDirectory%/tests/php/static-analysis-stubs/visualizer-pro.php
9+
- %currentWorkingDirectory%/tests/php/static-analysis-stubs/elementor.php
910
scanDirectories:
1011
- %currentWorkingDirectory%/vendor/neitanod/forceutf8
1112
- %currentWorkingDirectory%/vendor/openspout/openspout
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Stub declarations for Elementor classes used by Visualizer.
4+
* These stubs are only used for static analysis (PHPStan) and are never loaded at runtime.
5+
*/
6+
7+
namespace Elementor;
8+
9+
class Widget_Base {
10+
/**
11+
* @return string
12+
*/
13+
public function get_name() {}
14+
15+
/**
16+
* @return string
17+
*/
18+
public function get_title() {}
19+
20+
/**
21+
* @return string
22+
*/
23+
public function get_icon() {}
24+
25+
/**
26+
* @return array<string>
27+
*/
28+
public function get_categories() {}
29+
30+
/**
31+
* @return array<string>
32+
*/
33+
public function get_keywords() {}
34+
35+
/**
36+
* @return void
37+
*/
38+
protected function register_controls() {}
39+
40+
/**
41+
* @return void
42+
*/
43+
protected function render() {}
44+
45+
/**
46+
* @return array<string, mixed>
47+
*/
48+
public function get_settings_for_display() {}
49+
50+
/**
51+
* @param string $id
52+
* @param array<string, mixed> $args
53+
* @return void
54+
*/
55+
protected function start_controls_section( $id, $args = array() ) {}
56+
57+
/**
58+
* @return void
59+
*/
60+
protected function end_controls_section() {}
61+
62+
/**
63+
* @param string $id
64+
* @param array<string, mixed> $args
65+
* @return void
66+
*/
67+
protected function add_control( $id, $args = array() ) {}
68+
}
69+
70+
class Controls_Manager {
71+
const TAB_CONTENT = 'content';
72+
const SELECT = 'select';
73+
const RAW_HTML = 'raw_html';
74+
}
75+
76+
class Editor {
77+
/**
78+
* @return bool
79+
*/
80+
public function is_edit_mode() {}
81+
}
82+
83+
class Preview {
84+
/**
85+
* @return bool
86+
*/
87+
public function is_preview_mode() {}
88+
}
89+
90+
class Plugin {
91+
/** @var Plugin */
92+
public static $instance;
93+
94+
/** @var Editor */
95+
public $editor;
96+
97+
/** @var Preview */
98+
public $preview;
99+
}
100+
101+
interface Widgets_Manager_Interface {
102+
/**
103+
* @param Widget_Base $widget
104+
* @return void
105+
*/
106+
public function register( $widget );
107+
}

0 commit comments

Comments
 (0)