This document tracks the progress of adding PHP type declarations throughout the codebase. For current priorities, see docs/todo-priority-list.md and the Task memory bank.
- Add return type declarations to all methods
- Add parameter type hints where applicable
- Improve code quality and IDE support
- Enable better static analysis
Status: ✅ Complete Lines Modified: 573 lines Methods Updated: 19 methods
All methods now have proper type declarations:
getDefaultInputDefinition(): InputDefinitiongetDefaultCommands(): arraygetMODX(): ?\MODX\Revolution\modXgetCwd(): Returnsstring|false(matchinggetcwd())loadMODX($config): Returns\MODX\Revolution\modX|falseinitialize(\MODX\Revolution\modX $modx): \MODX\Revolution\modXgetService(string $name = '', array $params = array()): ?objectgetExcludedCommands(): arraydoRun(InputInterface $input, OutputInterface $output): intrunWithAlias(string $alias, InputInterface $input, OutputInterface $output): intrunWithAliasGroup(array $group, InputInterface $input, OutputInterface $output): intrunInSSHMode(InputInterface $input, OutputInterface $output): intrunWithSSH(string $sshString, InputInterface $input, OutputInterface $output): int- All protected/private helper methods
Benefits:
- Clear return types for all public APIs
- Better IDE autocompletion
- Safer refactoring
- PHPStan-compatible
Status: 🔄 Pending Priority: High Estimated Effort: 2 hours
Methods to update (~25 methods):
getApplication(): \MODX\CLI\Applicationrun(InputInterface $input, OutputInterface $output): intinit(): boolexecute(InputInterface $input, OutputInterface $output): intprocess(): intcall(string $command, array $arguments = array()): intcallSilent(string $command, array $arguments = array()): intconfirm(string $question, bool $default = true): boolask(string $question, ?string $default = null): stringsecret(string $question, bool $fallback = true): stringline(string $string): voidinfo(string $string): voidcomment(string $string): voidquestion(string $string): voiderror(string $string): voidgetArguments(): arraygetOptions(): arrayisSSHMode(): boolgetOutput(): OutputInterfacegetMODX(): ?\MODX\Revolution\modXgetRunStats(): stringconvertBytes(int $bytes): stringisEnabled(): bool
Status: 🔄 Pending Priority: High Estimated Effort: 2 hours
Methods to update (~15 methods):
process(): intprocessResponse(array $response = array()): intbeforeRun(array &$properties = array(), array &$options = array()): mixedgetExistingObject(string $class, int $id): ?\xPDO\Om\xPDOObjectprePopulateFromExisting(array &$properties, string $class, int $id, array $fieldMap = array()): boolapplyDefaults(array &$properties, array $defaults = array()): voidaddOptionsToProperties(array &$properties, array $optionKeys, array $typeMap = array()): voiddecodeResponse(\MODX\Revolution\Processors\ProcessorResponse &$response): arrayprocessArray(string $key, string $type = 'option'): arraygetOptions(): arrayhandleColumns(): voidprocessRow(array $record = array()): arrayparseValue(mixed $value, string $column): mixedrenderBoolean($value): string(also needs param type)renderObject(string $class, $pk, string $column): mixed
Status: 🔄 Pending Priority: Medium Estimated Effort: 1 hour
src/Configuration/Base.php- 10 methodssrc/Configuration/Instance.php- 8 methodssrc/Configuration/Extension.php- 6 methodssrc/Configuration/Component.php- 6 methodssrc/Configuration/ExcludedCommands.php- 5 methods
Estimated Effort: 4 hours total
src/API/MODX_CLI.php- Already has some type hints, needs completionsrc/API/CommandRegistry.php- 6 methodssrc/API/HookRegistry.php- 5 methodssrc/API/CommandRunner.php- 3 methodssrc/API/CommandPublisher.php- 4 methodssrc/API/ClosureCommand.php- 5 methodssrc/API/HookableCommand.php- 4 methods
Estimated Effort: 5 hours total
126 command files need type declarations. Most extend ProcessorCmd or ListProcessor, so once base classes are done, commands will be easier.
Priority: Low (do after base classes) Estimated Effort: 20-30 hours (can be done incrementally)
src/SSH/Handler.php- 8 methodssrc/Alias/Resolver.php- 6 methodssrc/Formatter/*.php- Various formatterssrc/Configuration/Yaml/YamlConfig.php- 5 methods
Estimated Effort: 6 hours total
- src/Application.php
- src/Command/BaseCmd.php
- src/Command/ProcessorCmd.php
- src/Command/ListProcessor.php
- All Configuration classes
- All API classes
- SSH and Alias classes
- Update commands in batches:
- Resource commands
- Template/Chunk/Snippet commands
- User/Package commands
- System commands
- Config commands
- Fix any PHPStan issues
- Update all tests
- Final review
After each phase:
- Run PHPStan:
composer analyse - Run unit tests:
composer test:unit - Run integration tests:
composer test:integration - Fix any issues before proceeding
// Void methods
public function configure(): void
// Boolean methods
protected function init(): bool
public function isEnabled(): bool
// String methods
protected function getCommandName(): string
public function getHelp(): string
// Array methods
protected function getOptions(): array
public function getArguments(): array
// Integer methods (exit codes)
public function execute(InputInterface $input, OutputInterface $output): int
protected function process(): int
// Nullable returns
public function getMODX(): ?\MODX\Revolution\modX
public function getObject(string $class, int $id): ?\xPDO\Om\xPDOObject
// Mixed (only when truly necessary)
public function getOption(string $key): mixed// Primitives
public function setName(string $name): void
public function setEnabled(bool $enabled): void
public function setLimit(int $limit): void
// Nullable primitives
public function ask(string $question, ?string $default = null): string
// Arrays
public function setProperties(array $properties): void
public function mergeOptions(array $options = array()): void
// Objects
public function setModx(\MODX\Revolution\modX $modx): void
public function run(InputInterface $input, OutputInterface $output): int
// Unions (PHP 8.0+) - not yet, we're on 7.4
// For now use mixed or PHPDoc- ✅ All 19 methods have return types
- ✅ All parameters have type hints
- ✅ Clearer API contracts
- ✅ Better IDE support
- ✅ PHPStan level 5 compatible
- Immediate: Complete BaseCmd.php type declarations
- This Week: Complete ProcessorCmd.php and ListProcessor.php
- Next Week: Configuration and API classes
- Ongoing: Command classes in batches
PHPStan is now configured (phpstan.neon.dist) and can be run with:
composer analyseCurrent level: 5 (will increase to 6+ as type declarations are added)
Expected PHPStan errors to fix:
- Missing return types (decreasing as we add them)
- Parameter type mismatches
- Potential null pointer issues
- Undefined property access
- Type declarations are backwards compatible with PHP 7.4
- Some methods return
mixedwhich is not available in PHP 7.4, use PHPDoc instead - Union types (PHP 8.0) not used yet, will be added during PHP 8 migration
- Nullable types (?) are available and used where appropriate
voidreturn type is used for methods that don't return values
Overall Progress: 0.8% (1/126 files complete) Core Classes Progress: 25% (1/4 files complete) Estimated Completion: 4-5 weeks
Last Updated: 2025-11-18