All Projects → staabm → phpstan-dba

staabm / phpstan-dba

Licence: MIT license
PHPStan based SQL static analysis and type inference for the database access layer

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to phpstan-dba

phpstan-wordpress
WordPress extensions for PHPStan ⛏️
Stars: ✭ 182 (+11.66%)
Mutual labels:  static-analysis, phpstan, phpstan-extension
phpstan-phpspec
PhpSpec extension for PHPStan
Stars: ✭ 19 (-88.34%)
Mutual labels:  static-analysis, phpstan, phpstan-extension
phpstan-symfony
*DEPRECATED* Symfony extension for PHPStan
Stars: ✭ 42 (-74.23%)
Mutual labels:  static-analysis, phpstan
woocommerce-stubs
WooCommerce function and class declaration stubs for static analysis.
Stars: ✭ 49 (-69.94%)
Mutual labels:  static-analysis, phpstan
Jedi
Awesome autocompletion, static analysis and refactoring library for python
Stars: ✭ 5,037 (+2990.18%)
Mutual labels:  static-analysis, type-inference
phpstan
PHP Static Analysis in Github Actions.
Stars: ✭ 41 (-74.85%)
Mutual labels:  static-analysis, phpstan
phpstan-enum
Enum class reflection extension for PHPStan
Stars: ✭ 42 (-74.23%)
Mutual labels:  phpstan, phpstan-extension
Psalm
A static analysis tool for finding errors in PHP applications
Stars: ✭ 4,523 (+2674.85%)
Mutual labels:  static-analysis, type-inference
phpstan-webmozart-assert
PHPStan extension for webmozart/assert
Stars: ✭ 132 (-19.02%)
Mutual labels:  static-analysis, phpstan
phpstan-extensions
Extensions for PHPStan
Stars: ✭ 61 (-62.58%)
Mutual labels:  static-analysis, phpstan
Phpstan
PHP Static Analysis Tool - discover bugs in your code without running it!
Stars: ✭ 10,534 (+6362.58%)
Mutual labels:  static-analysis, phpstan
phpstan-nette
Nette Framework class reflection extension for PHPStan & framework-specific rules
Stars: ✭ 87 (-46.63%)
Mutual labels:  static-analysis, phpstan
vim-phpstan
A Vim plugin for PHPStan - https://github.com/phpstan/phpstan. It calls `phpstan` to do static analysis of your PHP code and displays the errors in Vim's quickfix list.
Stars: ✭ 26 (-84.05%)
Mutual labels:  static-analysis, phpstan
OCCAM
OCCAM: Object Culling and Concretization for Assurance Maximization
Stars: ✭ 20 (-87.73%)
Mutual labels:  static-analysis
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 3,019 (+1752.15%)
Mutual labels:  static-analysis
deps-infer
Infer mvn deps from sources
Stars: ✭ 36 (-77.91%)
Mutual labels:  static-analysis
php-toolbox
🐳 A Docker image designed for PHP developers that care about code quality.
Stars: ✭ 18 (-88.96%)
Mutual labels:  phpstan
logifix
Fixing static analysis violations in Java source code using Datalog
Stars: ✭ 17 (-89.57%)
Mutual labels:  static-analysis
sonar-scala
A free and open-source SonarQube plugin for static code analysis of Scala projects.
Stars: ✭ 113 (-30.67%)
Mutual labels:  static-analysis
save-cloud
Cluster-based cloud mechanism for running SAVE framework
Stars: ✭ 30 (-81.6%)
Mutual labels:  static-analysis

phpstandba: PHPStan based SQL static analysis and type inference for the database access layer

phpstan-dba makes your phpstan static code analysis jobs aware of datatypes within your database. With this information at hand we are able to detect type inconsistencies between your domain model and database-schema. Additionally errors in code handling the results of sql queries can be detected.

This extension provides the following features, as long as you stick to the rules:

In case you are using Doctrine ORM, you might use phpstan-dba in tandem with phpstan-doctrine.

Note: At the moment only MySQL/MariaDB and PGSQL databases are supported. Technically it's not a big problem to support other databases though.

DEMO

see the 'Files Changed' tab of the DEMO-PR for a quick glance.

💌 Support phpstan-dba

Consider supporting the project, so we can make this tool even better even faster for everyone.

Installation

First, use composer to install:

composer require --dev staabm/phpstan-dba

Second, create a phpstan-dba-bootstrap.php file, which allows to you to configure phpstan-dba (this optionally includes database connection details, to introspect the database; if you would rather not do this see Record and Replay:

<?php // phpstan-dba-bootstrap.php

use staabm\PHPStanDba\DbSchema\SchemaHasherMysql;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\QueryReflection\MysqliQueryReflector;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\ReplayAndRecordingQueryReflector;
use staabm\PHPStanDba\QueryReflection\ReplayQueryReflector;
use staabm\PHPStanDba\QueryReflection\ReflectionCache;

require_once __DIR__ . '/vendor/autoload.php';

$cacheFile = __DIR__.'/.phpstan-dba.cache';

$config = new RuntimeConfiguration();
// $config->debugMode(true);
// $config->stringifyTypes(true);
// $config->analyzeQueryPlans(true);

// TODO: Put your database credentials here
$mysqli = new mysqli('hostname', 'username', 'password', 'database');

QueryReflection::setupReflector(
    new ReplayAndRecordingQueryReflector(
        ReflectionCache::create(
            $cacheFile
        ),
        // XXX alternatively you can use PdoMysqlQueryReflector instead
        new MysqliQueryReflector($mysqli),
        new SchemaHasherMysql($mysqli)

    ),
    $config
);

Note: Configuration for PGSQL is pretty similar

Third, create or update your phpstan.neon file so bootstrapFiles includes phpstan-dba-bootstrap.php.

If you are not using phpstan/extension-installer, you will also need to include dba.neon.

Your phpstan.neon might look something like:

parameters:
  level: 8
  paths:
    - src/
  bootstrapFiles:
    - phpstan-dba-bootstrap.php

includes:
  - ./vendor/staabm/phpstan-dba/config/dba.neon

Finally, run phpstan, e.g.

./vendor/bin/phpstan analyse -c phpstan.neon

Read more

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].