• Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WordPress extensions for PHPStan ⛏️

WordPress extensions for PHPStan

Packagist stats Packagist Tweet Build Status PHPStan

Static analysis for the WordPress ecosystem.

Installation

Add this package to your project.

composer require --dev szepeviktor/phpstan-wordpress

Make PHPStan find it automatically using phpstan/extension-installer.

composer require --dev phpstan/extension-installer

Or manually include it in your phpstan.neon.

includes:
    - vendor/szepeviktor/phpstan-wordpress/extension.neon

Configuration

Needs no extra configuration. 😃 Simply configure PHPStan - for example - this way.

parameters:
    level: 5
    paths:
        - plugin.php
        - inc/

Please read PHPStan Config Reference.

💡 Use Composer autoloader or a custom autoloader!

Support my work

Please consider supporting my work.

Sponsor

Thank you!

Usage

Just start the analysis: vendor/bin/phpstan analyze then fix an error and GOTO 10!

You find further information in the examples directory e.g. examples/phpstan.neon.dist

Usage in WooCommerce webshops

Please see WooCommerce Stubs

What this extension does

  • Makes it possible to run PHPStan on WordPress plugins and themes
  • Loads php-stubs/wordpress-stubs package
  • Provides dynamic return type extensions for many core functions
  • Defines some core constants
  • Handles special functions and classes e.g. is_wp_error()
  • Validates the optional docblock that precedes a call to apply_filters() and treats the type of its first @param as certain

Usage of an apply_filters() docblock

WordPress core - and the wider WordPress ecosystem - uses PHPDoc docblocks in a non-standard manner to document the parameters passed to apply_filters(). Example:

/**
 * Filters the page title when creating an HTML drop-down list of pages.
 *
 * @param string  $title Page title.
 * @param WP_Post $page  Page data object.
 */
$title = apply_filters( 'list_pages', $title, $page );

This extension understands these docblocks when they're present in your code and uses them to instruct PHPStan to treat the return type of the filter as certain, according to the first @param tag. In the example above this means PHPStan treats the type of $title as string.

To make the best use of this feature, ensure that the type of the first @param tag in each of these such docblocks is accurate and correct.

Make your code testable

  • Write clean OOP code: 1 class per file, no other code in class files outside class Name { ... }
  • Structure your code: uniform class names (WPCS or PSR-4), keep classes in a separate directory inc/
  • Add proper PHPDoc blocks to classes, properties, methods, functions, and calls to apply_filters()
  • Choose your main plugin file parts.
  • Avoid using core constants, use core functions
  • Avoid bad parts of PHP
    • functions: eval, extract, compact, list
    • type juggling: $a = '15'; if ($a) ...
  • If you need robust code try avoiding all kinds of type juggling (e.g. if needs a boolean), see Variable handling functions
  • If you are not bound by PHP 5 consider following Neutron Standard
  • Do not enable exit_error in WP_CLI::launch or WP_CLI::runcommand to keep your code testable

Dirty corner (FAQ)

WordPress uses conditional function and class definition for override purposes. Use sed command to exclude function stubs when they are previously defined.

sed -i -e 's#function is_gd_image#function __is_gd_image#' vendor/php-stubs/wordpress-stubs/wordpress-stubs.php

More Repositories

1

debian-server-tools

Tools and living docs 🧬 for Debian-based servers and Web Applications
Shell
460
star
2

w3-total-cache-fixed

A community driven build of W3 Total Cache. The aim is to continuously incorporate fixes, improvements, and enhancements over the official WordPress release of W3 Total Cache.
PHP
237
star
3

waf4wordpress

WAF for WordPress 🔥 with 60+ security checks and weekly updates
PHP
115
star
4

wordpress-plugin-construction

Tools 🧰 for developing and running WordPress websites
PHP
89
star
5

wordpress-speedtest

VPS Speedtest for WordPress with 160 results: 🏆 UpCloud (raw memory and CPU benchmark)
PHP
48
star
6

windows-workstation

Prepare my Windows 10 workstation
JavaScript
40
star
7

wordpress-website-lifecycle

How to work with WordPress 📅 for long years
PHP
40
star
8

starter-plugin

Template for WordPress plugins, it took 7️⃣ years to write
PHP
35
star
9

wordpress-autoloaded

🔟% Faster WordPress ⚡ without unconditional class loading + Composer
Shell
29
star
10

composer-envato

Composer plugin for Envato 💚 Install WordPress themes and plugins from ThemeForest‎‎ and CodeCanyon
PHP
28
star
11

tiny-cache

🚄 Cache WordPress post content, template part, translations and nav menu output in persistent object cache
PHP
27
star
12

wplib

wp-cli wrapper shell scripts to manage multiple sites with sudo
Shell
26
star
13

auto-login

Automatically log in to WordPress during development - an MU plugin
PHP
22
star
14

composer-managed-wordpress

Install and manage WordPress with Composer 👨‍🚀
Shell
18
star
15

github-link

GitHub Link WordPress plugin
PHP
15
star
16

WordPress-the-good-parts

A sustainable and modernized version of WordPress core.
PHP
13
star
17

tiny-cdn

Use an origin pull CDN with very few lines of code - WordPress plugin
PHP
13
star
18

very-clean-code

How to code without future problems ⚪
11
star
19

RootFiles

Important files in the document root which get downloaded without links.
PHP
11
star
20

acf-get

Strongly typed Advanced Custom Fields get_field function variants
PHP
11
star
21

Toolkit4WP

OOP toolkit 🔧 for daily tasks in WordPress development.
PHP
10
star
22

phpcs-psr-12-neutron-hybrid-ruleset

My useful frankenstein PHPCS ruleset 👓 for OOP WordPress development
PHP
10
star
23

plugin-installer-speedup

WordPress Plugin Installer Speedup
PHP
9
star
24

infrastructure-for-hosting-web-applications

My policies on hosting anything web-related 💾
9
star
25

WPHW

WordPress the hard way, plugin refactoring
PHP
9
star
26

monit-services

Michael Fladischer's monit plugins (mirror)
9
star
27

SentencePress

A set of words that is complete in itself. - OOP wrappers for WordPress
PHP
8
star
28

image-factory

Advanced real-time image optimization with mozjpeg on your server - WordPress plugin
PHP
8
star
29

unique-email-address

Normalize an email address 📨
PHP
7
star
30

option-inspector

Option Inspector plugin for WordPress
PHP
7
star
31

resource-versioning

It’s important to make resources (images, scripts, stylesheets, etc.) cacheable.
PHP
6
star
32

rectorize

Run rectorphp/rector on PHP 8.0 code to downgrade it
PHP
6
star
33

wordpress-persistent-admin-notices

Persistent admin notices for WordPress.
PHP
5
star
34

uninformative-words

Variable names you should avoid 👺
5
star
35

github-repository-inspection

Viktor attacks your repository with a 🔎
5
star
36

injector-php-7

Recursive dependency injector for PHP 7.4
PHP
5
star
37

wp-cli-check-update

Check wp-cli version for update via Github API
PHP
4
star
38

smtp-uri

SMTP URI WordPress plugin
PHP
4
star
39

phive

Install PHIVE in GitHub Actions
Shell
4
star
40

package-path

Get full installation path of any Composer package
PHP
3
star
41

hosting-check

Hosting (webspace) checker
Shell
3
star
42

how-to-operate

THis is hot stuff on people working with web applications 🌶
3
star
43

svn-updater

Enables installation of a WordPress plugin's SVN trunk version.
PHP
3
star
44

byte-level-care

Living with zero problems while developing your web application
Dockerfile
3
star
45

svg-validator

Validate SVG files in your GitHub Actions workflow
Shell
3
star
46

ip-info

IP address info - an HTML app
HTML
3
star
47

running-laravel

Running Laraval framework-based web applications for long years 🪘
PHP
3
star
48

github-next-example-block

Block for your README (React)
TypeScript
2
star
49

wordpress-install

Install and manage WordPress with Composer in agency-type projects
2
star
50

ISO-3166-orszagnevek-magyarul

Ország- és területnevek magyarul 🇭🇺
Shell
2
star
51

html-validate

Mirror of html-validate npm package
TypeScript
2
star
52

frontend-debugger

Frontend Debugger WordPress plugin
PHP
2
star
53

smart-image-resize-test

Fork of https://wordpress.org/plugins/smart-image-resize/ WordPress plugin
PHP
2
star
54

gitify

Convert WordPress-versioned zip release archives to a tagged git repo
Shell
2
star
55

acf-custom-database-tables-test

Static analysis for Advanced Custom Fields: Custom Database Tables
PHP
2
star
56

debian-normalized

My very first normalized Debian Docker image
Shell
2
star
57

composer-theme-fusion

Composer plugin for ThemeFusion ⬢
PHP
2
star
58

multipart-robotstxt-editor

Customize your WordPress site's robots.txt and include remote content to it.
PHP
2
star
59

zdkimfilter

"z" DKIM filter for Courier-MTA using the OpenDKIM Project's library
C
2
star
60

systemjs-example

Usage example for conditional resource loading in WordPress websites
JavaScript
2
star
61

phpstan-phpdoc

PHPDoc and typehint checks **only** for PHPStan 📜
2
star
62

wp-cli-database-prefix-command

Perform operations on prefixed database tables, a wp-cli package
PHP
2
star
63

courier-pythonfilter

Courier pythonfilter (mirror)
Python
1
star
64

fruit-alphabet

🍏 🍌 🍒
1
star
65

phive-action-example

An example on how to use PHIVE in GitHub Actions
1
star
66

html2text

Convert HTML to Markdown-formatted text.http://www.aaronsw.com/2002/html2text/
Python
1
star
67

KATA

KATÁ-s lettem! Kisadózó vállalkozások tételes adója
1
star
68

courier-pythonfilter-custom

Email correction and spam filters for the Courier MTA
Python
1
star
69

shared-hosting-aid

When you must touch websites on shared hosting
PHP
1
star
70

getter-setter

You 👨‍💻 don't have to write/generate getter and setter methods anymore!
PHP
1
star
71

machine-language

Machine Language WordPress plugin: Toggles human and machine language (aka IDs) on admin pages
PHP
1
star
72

Seo-Panel

World's first seo control panel for multiple websites
PHP
1
star
73

bandwidth

Bandwidth: a memory bandwidth benchmark
1
star
74

browser-feelings

The modern browser is an untameable, pulsating ball of goo.
1
star
75

lean-filter

Adblock Plus filter
Shell
1
star
76

OOP4WordPress

OOP API-s for WordPress
1
star
77

amd-window

Helps depending on the window object
JavaScript
1
star
78

VoIP

☢️ Telefonálás mikrohullámok nélkül
1
star
79

typos-on-you

Run Typos on any GitHub repository
1
star
80

phpstan-editorlink

Editor link error formatter for PHPStan
PHP
1
star
81

Unified-Post-Types

WordPress plugin to unify your custom post types.
PHP
1
star
82

DMARC-XML-Schema

Official DMARC XML Schema from RFC-7489
1
star
83

wp-cli-readme-command

Validate readme.txt of themes and plugins
PHP
1
star
84

szepeviktor

About Viktor 🟣
1
star
85

wp-cli-option-list-command

wp-cli-option-list-command
PHP
1
star
86

phive-install

GitHub action to install PHP tools with PHIVE
1
star
87

szepeviktor.github.io

A Debian mirror for modern webservers
Shell
1
star
88

water-in-the-air

I like water getting in the air 💧💧💧
1
star
89

zero-bytes-theme

Zero Bytes theme for WordPress
PHP
1
star
90

Watcher

Watcher-getzze
Python
1
star
91

keyboard

What makes a keyboard useful for you.
1
star
92

google-tag-manager-tag-lister

List tags of Google Tag Manager
Shell
1
star
93

mkpasswd

Encrypt a password as crypt(3) libc function does: with salt and hashed
JavaScript
1
star
94

fast-forward-youtube-ads

⏩ Bookmarklet for YouTube with two JavaScript function calls only
1
star
95

woocommerce-critical-vulnerability-sql-injection

Difference between WooCommerce release 5.5.0 and 5.5.1
PHP
1
star
96

phpcs-ruleset-validator

GitHub action for PHPCS rulesets
Shell
1
star
97

custom-sucuri

Custom settings for Sucuri Scanner WordPress plugin
PHP
1
star
98

spruce-reporter

🇭🇺 Report browser UA, IP address, UTC time
HTML
1
star