* Initial plan * Implement code refactoring, pre-commit enhancements, and documentation improvements Co-authored-by: ivuorinen <11024+ivuorinen@users.noreply.github.com> * chore(deps): update pre-commit hooks to latest versions Co-authored-by: ivuorinen <11024+ivuorinen@users.noreply.github.com> * docs: fix markdown linting issues in README and CONTRIBUTING Co-authored-by: ivuorinen <11024+ivuorinen@users.noreply.github.com> * feat(pre-commit): add editorconfig-checker for code style validation - Add editorconfig-checker hook to validate .editorconfig rules - Update .editorconfig to allow 200 char lines in markdown files (aligns with markdownlint config) - Fix .secrets.baseline to have proper final newline - All files now pass editorconfig validation Co-authored-by: ivuorinen <11024+ivuorinen@users.noreply.github.com> * chore: copilot cr fix in phpenv.fish Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ivuorinen <11024+ivuorinen@users.noreply.github.com> Co-authored-by: Ismo Vuorinen <ismo@ivuorinen.net> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
7.6 KiB
Contributing to phpenv.fish
Thank you for your interest in contributing to phpenv.fish! This document provides guidelines and instructions for contributors.
Table of Contents
- Development Setup
- Code Architecture
- Making Changes
- Testing
- Code Quality
- Performance Guidelines
- Submitting Changes
Development Setup
Prerequisites
- Fish Shell 3.0+
- Homebrew (for PHP version management)
- jq (JSON processor)
- Git
Installation for Development
-
Fork and clone the repository:
git clone https://github.com/YOUR-USERNAME/phpenv.fish.git cd phpenv.fish -
Link the development version to your Fish config:
# Create backup of existing installation if any mv ~/.config/fish/functions/phpenv.fish ~/.config/fish/functions/phpenv.fish.backup 2>/dev/null || true # Link development version ln -sf $PWD/functions/phpenv.fish ~/.config/fish/functions/phpenv.fish ln -sf $PWD/completions/phpenv.fish ~/.config/fish/completions/phpenv.fish ln -sf $PWD/conf.d/phpenv.fish ~/.config/fish/conf.d/phpenv.fish -
Install dependencies:
brew install jq brew tap shivammathur/php brew tap shivammathur/extensions -
Set up pre-commit hooks:
pip install pre-commit pre-commit install
Testing Changes
Since this is a Fish shell plugin, test changes by:
# Reload the function after changes
source functions/phpenv.fish
# Test basic commands
phpenv help
phpenv versions
phpenv current
phpenv doctor
# Test specific functionality
phpenv install 8.3 # if not already installed
phpenv use 8.3
phpenv list
Code Architecture
Core Components
-
Main Dispatcher (
functions/phpenv.fish)- Entry point function that routes commands to internal functions
- All subcommands are implemented as
__phpenv_*functions - Version detection logic in
__phpenv_detect_version
-
Completions (
completions/phpenv.fish)- Provides tab completions for all commands
- Fetches available versions dynamically from shivammathur/setup-php
-
Configuration (
conf.d/phpenv.fish)- Sets up Fish universal variables on load
- Handles PATH initialization
Key Design Patterns
- Performance Focus: Direct directory checks instead of
brew list(100-1000x faster) - Fish Universal Variables: Used for configuration persistence
- Homebrew Integration: Uses shivammathur taps for PHP/extension installation
- Version File Priority:
.php-version>.tool-version>composer.json> global > system
Version Detection Flow
- Check for
.php-versionfile (exact version) - Check for
.tool-versionfile (parse PHP line) - Check
composer.jsonfor PHP constraints (semver resolution) - Use global version from Fish universal variable
- Fall back to system PHP
Making Changes
Adding a New Command
- Add case in main
phpenvfunction switch statement - Implement
__phpenv_<command>function - Add completions in
completions/phpenv.fish - Update help text in
__phpenv_help
Example:
# In main phpenv function
case mynewcommand
__phpenv_mynewcommand $phpenv_args
# New function implementation
function __phpenv_mynewcommand
# Implementation here
end
Modifying Version Detection
- Edit
__phpenv_detect_versionfunction - Maintain priority order of version sources
- Test with various project configurations
Working with Homebrew Integration
- PHP versions:
shivammathur/php/php@<version> - Extensions:
shivammathur/extensions/<extension>@<php-version> - Check formula existence before operations
Testing
Manual Testing
Test all major functionality:
# Version management
phpenv install 8.3
phpenv use 8.3
phpenv local 8.2
phpenv global 8.3
# Extension management
phpenv extensions install xdebug
phpenv extensions list
# Configuration
phpenv config set auto-switch true
phpenv config list
# Diagnostics
phpenv doctor
phpenv current
phpenv which php
Edge Cases
Test edge cases:
- Missing jq dependency
- Network connectivity issues
- Invalid version files
- Corrupt installations
- Missing Homebrew taps
Code Quality
Pre-commit Hooks
The repository uses several pre-commit hooks for code quality:
- Security:
detect-secrets,gitleaks,checkov - Shell:
shellcheck,shfmt - Format:
markdownlint,yamllint - General: File format validation, trailing whitespace removal
Run hooks manually:
pre-commit run --all-files
Code Style Requirements
- Maximum line length: 120 characters (enforced by
.editorconfig) - Use LF line endings
- UTF-8 encoding
- Trim trailing whitespace
- Insert final newline
Fish Shell Best Practices
- Use local variables (
set -l) for function scope - Use session variables (
set -g) for per-shell configuration - Use universal variables (
set -U) only for persistent settings - Prefix all internal functions with
__phpenv_ - Use descriptive variable names with
phpenv_prefix - Handle errors gracefully with proper return codes
Performance Guidelines
Optimization Principles
- Cache expensive operations (API calls, filesystem checks)
- Unify repeated patterns into helper functions
- Use session variables instead of universal where possible
- Minimize network requests and subprocess calls
Caching System
The codebase uses intelligent caching:
__phpenv_version_cache: 5-minute cache for API version data__phpenv_cellar_cache: Permanent cache for Homebrew Cellar path
PATH Management Best Practices
- Always check
PHPENV_ORIGINAL_PATHexists before modification - Use debouncing for automatic operations
- Validate PHP paths before setting
- Provide restoration mechanism (
phpenv use system) - Clean up temporary variables in error cases
Helper Functions
Use unified helper functions to avoid code duplication:
__phpenv_parse_version_field: Single function for all jq parsing__phpenv_ensure_taps: Unified Homebrew tap management__phpenv_get_tap_formulas: Shared formula listing logic
Submitting Changes
Pull Request Process
-
Create a branch from
main:git checkout -b feature/my-improvement -
Make focused changes:
- Keep changes small and focused
- Follow the existing code style
- Add tests if applicable
-
Run quality checks:
pre-commit run --all-files shellcheck functions/phpenv.fish -
Test thoroughly:
- Test all affected functionality
- Test edge cases
- Test on different environments if possible
-
Commit with clear messages:
git commit -m "feat: add new command for X functionality" -
Submit pull request:
- Provide clear description of changes
- Reference any related issues
- Include testing instructions
Commit Message Format
Follow conventional commits:
feat:for new featuresfix:for bug fixesdocs:for documentation changesperf:for performance improvementsrefactor:for code refactoringtest:for adding tests
Code Review
All changes require code review. The maintainer will:
- Review for code quality and style
- Test functionality
- Check performance impact
- Verify documentation updates
Getting Help
- Issues: Open a GitHub issue for bugs or feature requests
- Discussions: Use GitHub Discussions for questions
- Documentation: Check the README and CLAUDE.md files
Thank you for contributing to phpenv.fish! 🐟