1414use MC \Parser \Token ;
1515use PDO ;
1616use PDOException ;
17+ use Tests \VisualizationTest ;
1718
1819/**
1920 * Provide a working implementation of the Google Visualization Query data source that works with a database
2021 * (or any other custom backend). The documentation for the query language itself and how to use it with Google
2122 * Visualizations can be found here: http://code.google.com/apis/visualization/documentation/querylanguage.html.
2223 *
23- * @see \Tests\ VisualizationTest
24+ * @see VisualizationTest
2425 *
2526 * @phpstan-type FieldSpec array{
2627 * type: string,
@@ -106,10 +107,8 @@ class Visualization
106107 * Create a new instance. This must be done before the library can be used. Pass in a PDO connection and
107108 * dialect if MC_Google_Visualization will handle the entire request cycle.
108109 *
109- * @param null|PDO $db the database connection to use
110- * @param string $dialect the SQL dialect to use - one of "mysql", "postgres", or "sqlite"
111- *
112- * @phpstan-param 'mysql'|'postgres'|'sqlite' $dialect
110+ * @param null|PDO $db the database connection to use
111+ * @param 'mysql'|'postgres'|'sqlite' $dialect the SQL dialect to use
113112 *
114113 * @throws Visualization_Error
115114 */
@@ -140,9 +139,7 @@ public function setDB(?PDO $db = null): void
140139 /**
141140 * Set the dialect to use when generating SQL statements.
142141 *
143- * @param string $dialect one of "mysql", "postgres", or "sqlite"
144- *
145- * @phpstan-param 'mysql'|'postgres'|'sqlite' $dialect
142+ * @param 'mysql'|'postgres'|'sqlite' $dialect the SQL dialect to use
146143 *
147144 * @throws Visualization_Error
148145 */
@@ -158,11 +155,8 @@ public function setSqlDialect(string $dialect): void
158155 /**
159156 * Change the default format string to use for a particular data type.
160157 *
161- * @param string $type the data type to change - one of "date", "datetime", "time", "boolean", or "number"
162- *
163- * @phpstan-param 'date'|'datetime'|'time'|'boolean'|'number' $type
164- *
165- * @param string $format the format string to use for the data type
158+ * @param string $format the format string to use for the data type
159+ * @param 'boolean'|'date'|'datetime'|'number'|'time' $type the data type to change
166160 *
167161 * @throws Visualization_Error
168162 */
@@ -582,7 +576,7 @@ public function getRowValues(array $row, array $meta): string
582576 $ time = strtotime ($ year .'0104 + ' .$ week .' weeks ' );
583577 assert (false !== $ time );
584578 $ monday = strtotime ('- ' .((int ) date ('w ' , $ time ) - 1 ).' days ' , $ time );
585- assert (false !== $ monday ); // @phpstan-ignore-line ; PHP < 8.0
579+ assert (false !== $ monday );
586580 [$ year , $ month , $ day ] = explode ('- ' , date ('Y-m-d ' , $ monday ));
587581 $ formatted = date ($ format , $ monday );
588582 } else {
@@ -737,7 +731,7 @@ public function getGrammar(): Def
737731 *
738732 * @throws ParseError
739733 * @throws Visualization_QueryError
740- * @throws Parser\ DefError
734+ * @throws DefError
741735 */
742736 public function parseQuery (string $ str ): array
743737 {
@@ -887,7 +881,7 @@ public function parseQuery(string $str): array
887881 *
888882 * @return string the string to output that will cause the visualization client to detect an error
889883 */
890- protected function handleError (int $ reqid , string $ detailMsg , string $ handler = 'google.visualization.Query.setResponse ' , string $ code = 'error ' , string $ summaryMsg = null ): string
884+ protected function handleError (int $ reqid , string $ detailMsg , string $ handler = 'google.visualization.Query.setResponse ' , string $ code = 'error ' , ? string $ summaryMsg = null ): string
891885 {
892886 if (null === $ summaryMsg ) {
893887 $ summaryMsg = $ detailMsg ;
@@ -1013,7 +1007,7 @@ protected function generateSQL(array &$meta): string
10131007 $ stmt = $ this ->db ->query ($ pivotSql );
10141008 assert (false !== $ stmt );
10151009 $ rows = $ stmt ->fetchAll (PDO ::FETCH_ASSOC );
1016- assert (false !== $ rows ); // @phpstan-ignore-line ; PHP < 8.0
1010+ assert (false !== $ rows );
10171011 foreach ($ rows as $ row ) {
10181012 // Create a version of all function-ed fields for each unique combination of pivot values
10191013 foreach ($ funcFields as $ field ) {
@@ -1292,7 +1286,7 @@ protected function getFieldQuote(): string
12921286 *
12931287 * @return string the SQL string for this field, with an op
12941288 */
1295- protected function getFieldSQL (string $ name , array $ spec , bool $ alias = false , string $ func = null , array $ pivot = null , array $ pivotFields = null ): string
1289+ protected function getFieldSQL (string $ name , array $ spec , bool $ alias = false , ? string $ func = null , ? array $ pivot = null , ? array $ pivotFields = null ): string
12961290 {
12971291 $ sql = $ spec ['field ' ];
12981292 $ q = $ this ->getFieldQuote ();
@@ -1360,7 +1354,7 @@ protected function addDependantCallbackFields(array $fieldSpec, array $entity, a
13601354 * @param Token $token the token or token group to recursively parse
13611355 * @param null|array $fields the collector array reference to receive the flattened select field values
13621356 */
1363- protected function parseFieldTokens (Token $ token , array &$ fields = null ): void
1357+ protected function parseFieldTokens (Token $ token , ? array &$ fields = null ): void
13641358 {
13651359 if ('* ' === $ token ->value ) {
13661360 return ;
@@ -1392,7 +1386,7 @@ protected function parseFieldTokens(Token $token, array &$fields = null): void
13921386 * @param Token $token the token or token group to parse
13931387 * @param null|array<array{type: string, value: string}> $where the collector array of tokens that make up the where clause
13941388 */
1395- protected function parseWhereTokens (Token $ token , array &$ where = null ): void
1389+ protected function parseWhereTokens (Token $ token , ? array &$ where = null ): void
13961390 {
13971391 if (!is_array ($ where )) {
13981392 $ where = [];
0 commit comments