Skip to content

Latest commit

 

History

History
90 lines (67 loc) · 3.63 KB

rules.md

File metadata and controls

90 lines (67 loc) · 3.63 KB

Advanced Usage / Re-Using phpstan-dba PHPStan for custom query APIs

For custom/non-standard query APIs the PHPStan rules shipped with phpstan-dba can be configured.

use SyntaxErrorInPreparedStatementMethodRule for your custom classes

Reuse the SyntaxErrorInPreparedStatementMethodRule within your PHPStan configuration to detect syntax errors in prepared queries, by registering a service:

services:
    -
        class: staabm\PHPStanDba\Rules\SyntaxErrorInPreparedStatementMethodRule
        tags: [phpstan.rules.rule]
        arguments:
            classMethods:
                - 'My\Connection::preparedQuery'
                - 'My\PreparedStatement::__construct'

the callable format is class::method. phpstan-dba assumes the method takes a query-string as a 1st and the parameter-values as a 2nd argument.

use SyntaxErrorInQueryMethodRule for your custom classes

Reuse the SyntaxErrorInQueryMethodRule within your PHPStan configuration to detect syntax errors in queries, by registering a service:

services:
    -
        class: staabm\PHPStanDba\Rules\SyntaxErrorInQueryMethodRule
        tags: [phpstan.rules.rule]
        arguments:
            classMethods:
                - 'myClass::query#0'
                - 'anotherClass::takesAQuery#2'

the callable format is class::method#parameterIndex, while the parameter-index defines the position of the query-string argument.

use SyntaxErrorInQueryFunctionRule for your custom functions

Reuse the SyntaxErrorInQueryFunctionRule within your PHPStan configuration to detect syntax errors in queries, by registering a service:

services:
    -
        class: staabm\PHPStanDba\Rules\SyntaxErrorInQueryFunctionRule
        tags: [phpstan.rules.rule]
        arguments:
            functionNames:
                - 'Deployer\runMysqlQuery#0'

the callable format is functionName#parameterIndex, while the parameter-index defines the position of the query-string argument.

use DoctrineKeyValueStyleRule for your custom classes

Reuse the DoctrineKeyValueStyleRule within your PHPStan configuration to detect syntax errors in class methods that construct queries from table and column name variables, by registering a service: The rule is designed around doctrine's data-retrieval-and-manipulation-api.

services:
    -
        class: staabm\PHPStanDba\Rules\DoctrineKeyValueStyleRule
        tags: [phpstan.rules.rule]
        arguments:
            classMethods:
                - 'My\Connection::truncate'
                - 'My\Connection::insert#1'
                - 'My\Connection::delete#1'
                - 'My\Connection::update#1,2'

the callable format is class::method#arrayArgIndex,arrayArgIndex. phpstan-dba assumes the method takes a table name as the 1st argument and any listed argument indices are arrays with column name keys and column value values.

use QueryPlanAnalyzerRule for your custom classes

Reuse the QueryPlanAnalyzerRule within your PHPStan configuration to detect syntax errors in queries, by registering a service:

-
    class: staabm\PHPStanDba\Rules\QueryPlanAnalyzerRule
    tags: [phpstan.rules.rule]
    arguments:
        classMethods:
            - 'myClass::query#0'
            - 'anotherClass::takesAQuery#2'

the callable format is class::method#parameterIndex, while the parameter-index defines the position of the query-string argument.

see also Query Plan Analysis