All Projects → mglaman → Phpstan Drupal

mglaman / Phpstan Drupal

Licence: mit
Extension for PHPStan to allow analysis of Drupal code.

Projects that are alternatives of or similar to Phpstan Drupal

Phpmd
PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.
Stars: ✭ 1,992 (+1953.61%)
Mutual labels:  static-analysis, hacktoberfest
Vulny Code Static Analysis
Python script to detect vulnerabilities inside PHP source code using static analysis, based on regex
Stars: ✭ 207 (+113.4%)
Mutual labels:  static-analysis, hacktoberfest
Codeclimate
Code Climate CLI
Stars: ✭ 2,273 (+2243.3%)
Mutual labels:  static-analysis, hacktoberfest
Abaplint
Standalone linter for ABAP
Stars: ✭ 111 (+14.43%)
Mutual labels:  static-analysis, hacktoberfest
Freki
🐺 Malware analysis platform
Stars: ✭ 285 (+193.81%)
Mutual labels:  static-analysis, hacktoberfest
Config Lint
Command line tool to validate configuration files
Stars: ✭ 118 (+21.65%)
Mutual labels:  static-analysis, hacktoberfest
Spotbugs
SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.
Stars: ✭ 2,569 (+2548.45%)
Mutual labels:  static-analysis, hacktoberfest
Checkov
Prevent cloud misconfigurations during build-time for Terraform, Cloudformation, Kubernetes, Serverless framework and other infrastructure-as-code-languages with Checkov by Bridgecrew.
Stars: ✭ 3,572 (+3582.47%)
Mutual labels:  static-analysis, hacktoberfest
Revive
🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
Stars: ✭ 3,139 (+3136.08%)
Mutual labels:  static-analysis, hacktoberfest
Larastan
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.
Stars: ✭ 3,554 (+3563.92%)
Mutual labels:  static-analysis, hacktoberfest
Drupal Check
Check Drupal code for deprecations and discover bugs via static analysis
Stars: ✭ 252 (+159.79%)
Mutual labels:  hacktoberfest, drupal
Huskyci
Performing security tests inside your CI
Stars: ✭ 398 (+310.31%)
Mutual labels:  static-analysis, hacktoberfest
Nginxconfig.io
⚙️ NGINX config generator on steroids 💉
Stars: ✭ 14,983 (+15346.39%)
Mutual labels:  hacktoberfest, drupal
Find Sec Bugs
The SpotBugs plugin for security audits of Java web applications and Android applications. (Also work with Kotlin, Groovy and Scala projects)
Stars: ✭ 1,748 (+1702.06%)
Mutual labels:  static-analysis, hacktoberfest
Composer Drupal Optimizations
Saves memory and CPU cycles when you run `composer update`
Stars: ✭ 144 (+48.45%)
Mutual labels:  hacktoberfest, drupal
Tfsec
Security scanner for your Terraform code
Stars: ✭ 3,622 (+3634.02%)
Mutual labels:  static-analysis, hacktoberfest
Horusec
Horusec is an open source tool that improves identification of vulnerabilities in your project with just one command.
Stars: ✭ 311 (+220.62%)
Mutual labels:  static-analysis, hacktoberfest
Terraform Security Scan
Run a security scan on your terraform with the very nice https://github.com/liamg/tfsec
Stars: ✭ 64 (-34.02%)
Mutual labels:  static-analysis, hacktoberfest
Kogito Examples
Kogito examples - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
Stars: ✭ 96 (-1.03%)
Mutual labels:  hacktoberfest
Sharedchamber
Android Secure SharedPreferences Using Facebook Conceal Encryption
Stars: ✭ 96 (-1.03%)
Mutual labels:  hacktoberfest

phpstan-drupal

Tests CircleCI

Extension for PHPStan to allow analysis of Drupal code.

Sponsors

undpaul Intracto

Would you like to sponsor?

Usage

When you are using phpstan/extension-installer, phpstan.neon will be automatically included.

Otherwise add phpstan.neon to your Drupal project.

Make sure it has

includes:
	- vendor/mglaman/phpstan-drupal/extension.neon

Enabling rules one-by-one

If you don't want to start using all the available strict rules at once but only one or two, you can! Just don't include the whole rules.neon from this package in your configuration, but look at its contents and copy only the rules you want to your configuration under the services key:

services:
	-
		class: PHPStan\Rules\Drupal\PluginManager\PluginManagerSetsCacheBackendRule
		tags:
			- phpstan.rules.rule

Excluding tests from analysis

To exclude tests from analysis, add the following parameter

parameters:
	excludes_analyse:
		- *Test.php
		- *TestBase.php

Deprecation testing

Add the deprecation rules to your Drupal project's dependencies

composer require --dev phpstan/phpstan-deprecation-rules

Edit your phpstan.neon to look like the following:

includes:
	- vendor/mglaman/phpstan-drupal/extension.neon
	- vendor/phpstan/phpstan-deprecation-rules/rules.neon

To only handle deprecation testing, use a phpstan.neon like this:

parameters:
	customRulesetUsed: true
	reportUnmatchedIgnoredErrors: false
	# Ignore phpstan-drupal extension's rules.
	ignoreErrors:
		- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
		- '#Plugin definitions cannot be altered.#'
		- '#Missing cache backend declaration for performance.#'
		- '#Plugin manager has cache backend specified but does not declare cache tags.#'
includes:
	- vendor/mglaman/phpstan-drupal/extension.neon
	- vendor/phpstan/phpstan-deprecation-rules/rules.neon

Adapting to your project

Specifying your Drupal project's root

By default, the PHPStan Drupal extension will try to determine your Drupal project's root directory based on the working directory that PHPStan is checking. If this is not working properly, you can explicitly define the Drupal project's root directory using the drupal.drupal_root parameter.

parameters:
    drupal:
        drupal_root: /path/to/drupal

You can also use container parameters. For instance you can always set it to the current working directory.

parameters:
    drupal:
        drupal_root: %currentWorkingDirectory%

Entity storage mappings.

The EntityTypeManagerGetStorageDynamicReturnTypeExtension service helps map dynamic return types. This inspects the passed entity type ID and tries to return a known storage class, besides the default EntityStorageInterface. The default mapping can be found in extension.neon. For example:

parameters:
    drupal:
        entityTypeStorageMapping:
            node: Drupal\node\NodeStorage
            taxonomy_term: Drupal\taxonomy\TermStorage
            user: Drupal\user\UserStorage

To add support for custom entities, you may add the same definition in your project's phpstan.neon. See the following example for adding a mapping for Search API:

parameters:
    drupal:
        entityTypeStorageMapping:
            search_api_index: Drupal\search_api\Entity\SearchApiConfigEntityStorage
            search_api_server: Drupal\search_api\Entity\SearchApiConfigEntityStorage
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].