Skip to content

added phpstan-dba analysis extension - #4984

Closed
staabm wants to merge 56 commits into
mainfrom
query-analytics
Closed

staabm wants to merge 56 commits into
mainfrom
query-analytics

Conversation

@staabm

@staabm staabm commented Dec 30, 2021 •

Copy link
Copy Markdown
Member

Todo/Offen

  • aktuell nutzen wir noch php 7.4 in den CI builds. phpstan-dba benötigt mindestens php8.0

@gharlan

gharlan commented Dec 30, 2021

Copy link
Copy Markdown
Member

Bei uns haben ja eigentlich alle Queries einen dynamischen Tabellennamen, wie rex::getTable('article') oder rex::getTablePrefix().'article'. Funktioniert das damit auch?

@staabm

staabm commented Dec 31, 2021

Copy link
Copy Markdown
Member Author

Im detail noch nicht getestet.

Variablen im query sind kein problem, siehe https://github.com/staabm/phpstan-dba/blob/8c42e3874f80489ce09cd62853ccd1ec1acdac8f/tests/data/pdo.php#L52

bzgl der tabellen, denke ich müsste ich eine dynamische return-type extension schreiben, da wir ja den konkreten tabellen-namen zur analyse zeit kennen.. müssen ihn phpstan nur mitteilen

@@ -82,7 +82,7 @@ public function hasMessage()
public function getName($id)
{
$this->sql->setQuery('

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh ich denke hier muss ich im phpstan-dba noch support für placeholder im sql einbauen

Comment on lines +145 to +151
php redaxo/bin/console package:install phpmailer --ansi
php redaxo/bin/console package:install cronjob --ansi
php redaxo/bin/console package:install cronjob/article_status --ansi
php redaxo/bin/console package:install cronjob/optimize_tables --ansi
php redaxo/bin/console package:install debug --ansi
php redaxo/bin/console package:install structure/history --ansi
php redaxo/bin/console package:install structure/version --ansi

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alle packages installieren, damit das db schema vollständig ist

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bedeutet das, dass man zukünftig auch lokal beim Ausführen von phpstan eine bestimmte DB-Konstellation braucht?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();
}

private function resolveTypeFromString(string $vartype): ?Type

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gharlan könntest du hier mal drüber schauen was hier noch fehlt, damit diese extension hier "genauso schlau" ist wie die im psalm-plugin?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenn ich das richtig sehe, sind vor allem die Typen in Array-Struktur nicht implementiert. Also sowas.

@staabm

staabm commented Jan 17, 2022 •

Copy link
Copy Markdown
Member Author

das sieht schonmal sehr gut aus.

offen:

  • was ist mit diesen errors
    grafik

-> in getValue ist der return-type nicht bekannt in https://github.com/redaxo/redaxo/blob/c9e667d630870942dfa5568bf7be56c8a89661db/redaxo/src/addons/structure/plugins/content/pages/modules.actions.php#L137-L142

-> hier könnte via phpstan-dba der daten-type der datenbank spalte zurückgegeben werden


@staabm

staabm commented Jan 20, 2022

Copy link
Copy Markdown
Member Author

das aktuelle analyse result zeigt schön, wo phpstan aktuell keine typen kennt (d.h. ggf. fehlen paar phpdocs oder extensions damit er unseren code besser versteht)

------ ------------------------------------------------------------------------------------------
  Line   addons\cronjob\lib\manager_sql.php
 ------ ------------------------------------------------------------------------------------------
  84     Query error: Unknown column 'name12' in 'field list' (1054).
  270    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\cronjob\plugins\article_status\lib\cronjob.php
 ------ ------------------------------------------------------------------------------------------
  23     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  41     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  71     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  77     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\mediapool\pages\media.detail.php
 ------ ------------------------------------------------------------------------------------------
  31     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  64     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  102    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\metainfo\boot.php
 ------ ------------------------------------------------------------------------------------------
  77     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------
  Line   addons\metainfo\functions\function_metainfo.php
 ------ ------------------------------------------------------------------------------------------------------
  83     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  93     Unresolvable Query: Cannot simulate parameter value for type: mixed~0|0.0|''|'0'|array{}|false|null.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  101    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  160    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\metainfo\lib\handler\media_handler.php
 ------ ------------------------------------------------------------------------------------------
  191    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------
  Line   addons\metainfo\lib\table_expander.php
 ------ ------------------------------------------------------------------------------------------------------------
  58     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  238    Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB
         server version for the right syntax to use near '1 WHERE name = '1' LIMIT 0' at line 1

         Simulated query: SELECT * FROM 1 WHERE name = '1' LIMIT 0 (1064).
 ------ ------------------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\structure\boot.php
 ------ ------------------------------------------------------------------------------------------
  82     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\structure\plugins\content\boot.php
 ------ ------------------------------------------------------------------------------------------
  32     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------
  Line   addons\structure\plugins\content\pages\modules.actions.php
 ------ -----------------------------------------------------------------------------------------------
  175    Comparison operation "==" between 3 and array|bool|float|int|string|null results in an error.
  182    Comparison operation "==" between 7 and array|bool|float|int|string|null results in an error.
  189    Comparison operation "==" between 7 and array|bool|float|int|string|null results in an error.
 ------ -----------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------
  Line   addons\structure\plugins\content\pages\templates.php
 ------ ----------------------------------------------------------------
  83     Query error: Unknown column 'ighjjd' in 'where clause' (1054).
 ------ ----------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\structure\plugins\history\lib\article_slice_history.php
 ------ ------------------------------------------------------------------------------------------
  26     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  59     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  73     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  84     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  87     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\structure\plugins\version\boot.php
 ------ ------------------------------------------------------------------------------------------
  75     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   addons\structure\plugins\version\lib\revision.php
 ------ ------------------------------------------------------------------------------------------
  23     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  26     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  62     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   core\lib\login\backend_login.php
 ------ ------------------------------------------------------------------------------------------
  109    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  132    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  135    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
  149    Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------
  Line   core\lib\sql\sql.php
 ------ -------------------------------------------------------
  459    Unreachable statement - code above always terminates.
 ------ -------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   core\tests\login\backend_login_test.php
 ------ ------------------------------------------------------------------------------------------
  30     Unresolvable Query: Cannot simulate parameter value for type: mixed.
         💡 Make sure all variables involved have a non-mixed type and array-types are specified.
 ------ ------------------------------------------------------------------------------------------


@staabm staabm mentioned this pull request Jan 21, 2022
Comment thread phpstan.neon.dist
Comment on lines +62 to +81
class: staabm\PHPStanDba\Rules\SyntaxErrorInPreparedStatementMethodRule
tags: [phpstan.rules.rule]
arguments:
classMethods:
- 'rex_sql::setQuery'
- 'rex_sql::setDBQuery'
- 'rex_sql::getArray'
- 'rex_sql::getDBArray'

-
class: staabm\PHPStanDba\Rules\SyntaxErrorInQueryMethodRule
tags: [phpstan.rules.rule]
arguments:
classMethods:
- 'rex_sql::setQuery#0'
- 'rex_sql::setDBQuery#0'
- 'rex_sql::getArray#0'
- 'rex_sql::getDBArray#0'
- 'rex_sql::prepareQuery#0'
- 'rex_sql::getQueryType#0'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aufgrund von staabm/phpstan-dba#245 kann hier ggf. die doppelte konfiguration in SyntaxErrorInPreparedStatementMethodRule und SyntaxErrorInQueryMethodRule jetzt wegfallen

@staabm staabm mentioned this pull request Jun 11, 2022
@staabm

staabm commented Jun 19, 2022

Copy link
Copy Markdown
Member Author

habe phpstan-dba jetzt im rahmen von rexstan integriert

@staabm staabm closed this Jun 19, 2022
@staabm
staabm deleted the query-analytics branch June 19, 2022 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants