@@ -55,40 +55,34 @@ class Visualization
5555 /**
5656 * The default entity that will be used if the "from" part of a query is left out. Setting this to null
5757 * will make a "from" clause required.
58- *
59- * @var null|string
6058 */
61- protected $ defaultEntity ;
59+ protected ? string $ defaultEntity = null ;
6260
6361 /**
6462 * The entity schema that defines which tables are exposed to visualization clients, along with their fields, joins, and callbacks.
6563 *
6664 * @var array<string, Entity>
6765 */
68- protected $ entities = [];
66+ protected array $ entities = [];
6967
7068 /**
7169 * If pivots are being used or MC_Google_Visualization is handling the whole request, this must be a PDO
7270 * connection to your database.
73- *
74- * @var null|PDO
7571 */
76- protected $ db ;
72+ protected ? PDO $ db ;
7773
7874 /**
7975 * The SQL dialect to use when auto-generating SQL statements from the parsed query tokens
8076 * defaults to "mysql". Allowed values are "mysql", "postgres", or "sqlite". Patches are welcome for the rest.
81- *
82- * @var string
8377 */
84- protected $ sqlDialect = 'mysql ' ;
78+ protected string $ sqlDialect = 'mysql ' ;
8579
8680 /**
8781 * If a format string is not provided by the query, these will be used to format values by default.
8882 *
8983 * @var array<string, string>
9084 */
91- protected $ defaultFormat = [
85+ protected array $ defaultFormat = [
9286 'date ' => 'm/d/Y ' ,
9387 'datetime ' => 'm/d/Y h:ia ' ,
9488 'time ' => 'h:ia ' ,
@@ -98,10 +92,8 @@ class Visualization
9892
9993 /**
10094 * The current supported version of the Data Source protocol.
101- *
102- * @var float
10395 */
104- protected $ version = 0.5 ;
96+ protected float $ version = 0.5 ;
10597
10698 /**
10799 * Create a new instance. This must be done before the library can be used. Pass in a PDO connection and
@@ -543,11 +535,7 @@ public function getRowValues(array $row, array $meta): string
543535 if (1 === preg_match ('#^num:(\d+)(.*)$#i ' , $ format , $ matches )) {
544536 $ digits = (int ) $ matches [1 ];
545537 $ extras = str_split ($ matches [2 ]);
546- if (2 === count ($ extras )) {
547- $ formatted = number_format ($ val , $ digits , $ extras [0 ], $ extras [1 ]);
548- } else {
549- $ formatted = number_format ($ val , $ digits );
550- }
538+ $ formatted = 2 === count ($ extras ) ? number_format ($ val , $ digits , $ extras [0 ], $ extras [1 ]) : number_format ($ val , $ digits );
551539 } elseif ('dollars ' === $ format ) {
552540 $ formatted = '$ ' .number_format ($ val , 2 );
553541 } elseif ('percent ' === $ format ) {
@@ -769,7 +757,7 @@ public function parseQuery(string $str): array
769757 $ groupby = $ token ->getValues ();
770758 array_shift ($ groupby );
771759 array_shift ($ groupby );
772- $ query ['groupby ' ] = array_filter ($ groupby );
760+ $ query ['groupby ' ] = array_filter ($ groupby, static fn (? string $ s ): bool => null !== $ s && '' !== $ s );
773761
774762 break ;
775763
@@ -779,7 +767,7 @@ public function parseQuery(string $str): array
779767 }
780768 $ pivot = $ token ->getValues ();
781769 array_shift ($ pivot );
782- $ query ['pivot ' ] = array_filter ($ pivot );
770+ $ query ['pivot ' ] = array_filter ($ pivot, static fn (? string $ s ): bool => null !== $ s && '' !== $ s );
783771
784772 break ;
785773
@@ -987,7 +975,7 @@ protected function generateSQL(array &$meta): string
987975 }
988976
989977 $ pivotSql = 'SELECT ' .implode (', ' , $ pivotFields ).' FROM ' .$ meta ['table ' ];
990- if (count ( $ pivotJoins ) > 0 ) {
978+ if ([] !== $ pivotJoins ) {
991979 $ pivotSql .= ' ' .implode (' ' , $ pivotJoins );
992980 }
993981 $ pivotSql .= ' GROUP BY ' .implode (', ' , $ pivotGroup );
@@ -1083,7 +1071,7 @@ protected function generateSQL(array &$meta): string
10831071 $ wheres [] = $ meta ['global_where ' ];
10841072 }
10851073
1086- if (count ( $ wheres ) > 0 ) {
1074+ if ([] !== $ wheres ) {
10871075 $ sql .= ' WHERE ' .implode (' AND ' , $ wheres );
10881076 }
10891077
@@ -1353,6 +1341,8 @@ protected function addDependantCallbackFields(array $fieldSpec, array $entity, a
13531341 *
13541342 * @param Token $token the token or token group to recursively parse
13551343 * @param null|array $fields the collector array reference to receive the flattened select field values
1344+ *
1345+ * @param-out array $fields
13561346 */
13571347 protected function parseFieldTokens (Token $ token , ?array &$ fields = null ): void
13581348 {
@@ -1385,6 +1375,8 @@ protected function parseFieldTokens(Token $token, ?array &$fields = null): void
13851375 *
13861376 * @param Token $token the token or token group to parse
13871377 * @param null|array<array{type: string, value: string}> $where the collector array of tokens that make up the where clause
1378+ *
1379+ * @param-out array $where
13881380 */
13891381 protected function parseWhereTokens (Token $ token , ?array &$ where = null ): void
13901382 {
0 commit comments