Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ provenance, and `gh attestation verify` is what reads that. mise installs it, bu
can log it in — the check goes over the API, so `mise run install` stops on a logged-out
`gh` rather than letting `verify` fail later. There is no
second PHP — composer and the e2e run on the bundled frankenphp (`./bin/frankenphp
php-cli`), and `.cache/composer.phar` is fetched like `phpstan.phar`. `app/composer.json`
php-cli`), `.cache/composer.phar` is downloaded, and phpstan is a composer dev dependency
beside its strict rules. `app/composer.json`
and `package.json` with their lockfiles are the source of truth; `app/vendor/` and
`node_modules/` are built, not committed, and `dg/composer-cleaner` slims `app/vendor/` for
a production build.
Expand Down
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,8 @@ checksums:
# Analysis tools are pinned like everything else, so a green build stays green for a
# reason rather than because a linter happened not to ship a new rule today.
GOLANGCI_VERSION = v2.12.2
PHPSTAN_VERSION = 2.2.5
COMPOSER_VERSION = 2.10.2

.cache/phpstan.phar:
@mkdir -p .cache
curl -fsSL --retry 3 --retry-delay 2 -o $@ https://github.com/phpstan/phpstan/releases/download/$(PHPSTAN_VERSION)/phpstan.phar

.cache/composer.phar:
@mkdir -p .cache
curl -fsSL --retry 3 --retry-delay 2 -o $@ https://getcomposer.org/download/$(COMPOSER_VERSION)/composer.phar
Expand Down Expand Up @@ -214,8 +209,19 @@ app/vendor: app/composer.json app/composer.lock bin/frankenphp$(EXE) .cache/comp
# --debug is not for debugging: phpstan's parallel workers shell out to a `php` binary,
# and there deliberately is none here -- we run it through the frankenphp we download.
# 2G because adminer.php is 500 KB of minified source on very long lines.
phpstan: bin/frankenphp$(EXE) .cache/phpstan.phar app/adminer.php app/vendor
./bin/frankenphp$(EXE) php-cli .cache/phpstan.phar analyse -c phpstan.neon \
# A composer dev dependency, not a download: the strict rules are a phpstan extension and
# have to match its version, and composer.lock pins the pair the way upstream adminer does.
# phpstan.restarted: phpstan restarts itself through PHP_BINARY to load its native extension
# or retune OPcache, and under frankenphp's php-cli that is empty, so the restart fails and
# takes the run with it. The value is what its own restart sets, so it skips it. An ini file
# for the reason WIN_INI is one.
PHPSTAN_INI = .cache/phpstan-ini
$(PHPSTAN_INI)/phpstan.ini:
@mkdir -p $(dir $@)
printf 'phpstan.restarted=1\n' > $@

phpstan: bin/frankenphp$(EXE) app/adminer.php app/vendor $(PHPSTAN_INI)/phpstan.ini
PHP_INI_SCAN_DIR=$(PHPSTAN_INI) ./bin/frankenphp$(EXE) php-cli app/vendor/phpstan/phpstan/phpstan.phar analyse -c phpstan.neon \
--no-progress --debug --memory-limit=2G

# The conventions phpstan does not judge: every property a native type (a bare @var is not
Expand Down
7 changes: 0 additions & 7 deletions app/AdminerDesktop.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,4 @@ function handlePost(): void {
}
Adminer\redirect($_SERVER["REQUEST_URI"]);
}

/** Adminer's plugin translations, keyed by dotted ID. Populated in the constructor from the
* per-language files under app/src/I18n/plugin/; Adminer's Plugin::lang() reads this as
* $translations[LANG], with en.php the base an untranslated ID falls back to.
* @var array<string,array<string,string>>
*/
protected $translations = []; // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint -- overrides adminer's untyped Adminer\Plugin::$translations, which PHP forbids narrowing
}
2 changes: 2 additions & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"behat/behat": "^4.0",
"dg/composer-cleaner": "^2.2",
"nette/tester": "^2.5",
"phpstan/phpstan": "2.3.1",
"phpstan/phpstan-strict-rules": "2.1.0",
"playwright-php/playwright": "^1.2",
"slevomat/coding-standard": "^8.16",
"squizlabs/php_codesniffer": "^4.0"
Expand Down
118 changes: 117 additions & 1 deletion app/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions phpstan-plugin.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/** Adminer's own phpdoc for what we override, which phpstan cannot read from adminer.php:
* the compiler strips doc-comments, so every type there is mixed. Copied from the release's
* adminer/include/plugin.inc.php. Read by phpstan only (stubFiles in phpstan.neon).
*/

namespace Adminer;

abstract class Plugin {
/** @var array<literal-string, string|list<string>>[] */
protected $translations = [];
}
33 changes: 33 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
includes:
- app/vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
# Only what we wrote; everything excluded below ships verbatim from the adminer
# release and is not ours to report on.
Expand Down Expand Up @@ -30,6 +33,10 @@ parameters:
- app/adminer.php
- phpstan-stubs.php

# Adminer's phpdoc for the members we override; see the file.
stubFiles:
- phpstan-plugin.stub

# Level 6 adds the missing-type checks: every parameter, return and property in our own
# code carries a type. The adminer hooks we override (head, css, csp, navigation, ...)
# carry @param/@return phpdoc rather than native types — adminer's base leaves them
Expand All @@ -38,6 +45,32 @@ parameters:
# treats the superglobal as open-keyed, so an access is never "possibly undefined".
level: 6

# Upstream adminer's stricter set (conf/phpstan.neon there), so code written next to
# adminer is held to the same bar adminer holds itself to.
checkNullables: true # level 8
checkUninitializedProperties: true # typed property without a default value
checkDynamicProperties: true # property not declared in the class
checkFunctionNameCase: true
checkMissingCallableSignature: true # callable without the types of its parameters
reportAnyTypeWideningInVarTag: true # @var widening the inferred type
reportMaybesInMethodSignatures: true # nullable parameter and return types of overridden methods
reportMaybesInPropertyPhpDocTypes: true
reportStaticMethodSignatures: true

strictRules:
allRules: false
closureUsesThis: true
disallowedBacktick: true
disallowedImplicitArrayCreation: true
dynamicCallOnStaticMethod: true
illegalConstructorMethodCall: true
matchingInheritedMethodNames: true
switchConditionsMatchingType: true
# rules.neon enables these outside strictRules, so they are set back as upstream does
polluteScopeWithLoopInitialAssignments: true
polluteScopeWithAlwaysIterableForeach: true
reportWrongPhpDocTypeInVarTag: false

# Defined once per request by whichever driver the URL names; phpstan otherwise takes the
# first define() in adminer.php ("pgsql") for the only value and calls every check of it
# always true.
Expand Down
Loading