Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Utils 🐘

Essential Utilities for Modern PHP Development in VS Code.

This extension provides a collection of tools to boost your PHP productivity, focusing on code quality, standard compliance, and ease of use.

Features ✨

1. Auto Strict Types

Automatically adds declare(strict_types=1); to the top of your PHP files when you save them.

  • Ensures type safety in your projects.
  • Only adds it if missing (smart check).
  • Setting: phpUtils.autoStrictTypes (Default: true)

2. Smart File Creation (Context Menu)

Easily create PHP classes, interfaces, traits, and enums from the File Explorer context menu.

  • Namespace Resolver: Automatically detects composer.json to generate the correct namespace for your file.
  • Configurable Menu: Choose to show commands in a submenu or directly in the main context menu.
  • Visibility Control: Toggle visibility for Class, Interface, Trait, or Enum commands independently.
  • Templates: Generates clean, ready-to-use boilerplate code.

3. Advanced Import Sorter & Cleaner

Keep your use statements organized and clean. Runs automatically on save.

  • Sorting: Sorts imports alphabetically or by length.
  • Grouping: Groups imports from the same namespace.
  • Priority: Configurable priority list to keep important namespaces (like System, App) at the top.
  • Remove Unused: Automatically detects and removes unused use statements.
  • Settings:
    • phpUtils.importSorter.onSave: Enable/Disable sorting on save.
    • phpUtils.removeUnusedImports: Enable/Disable unused import removal.
    • phpUtils.importSorter.priority: Array of namespaces to prioritize.
    • phpUtils.importSorter.orderBy: alpha or length.
    • phpUtils.importSorter.sortDirection: asc or desc.

4. Apache .htaccess Support (Bonus)

Complete support for .htaccess files, which is often missing in VS Code.

  • Syntax Highlighting: Full colorization for Apache configuration files.
  • Formatting: Format your .htaccess files with proper indentation.

5. Selection Stats (Bonus)

A lightweight status bar item that shows helpful statistics about your current selection.

  • Displays Line, Column, and Character Count.
  • Shows only when you have an active selection.
  • Optimized: Uses debounce to prevent performance impact during rapid typing.

Extension Settings ⚙️

Setting Default Description
phpUtils.autoStrictTypes true Automatically add declare(strict_types=1); on save.
phpUtils.removeUnusedImports true Automatically remove unused imports on save.
phpUtils.importSorter.onSave true Automatically sort imports on save.
phpUtils.importSorter.orderBy alpha Sort order: alpha (Alphabetical) or length.
phpUtils.importSorter.priority ["System", "App"] Priority list of namespaces.
phpUtils.importSorter.sortDirection asc Sort direction: asc or desc.
phpUtils.importSorter.grouping true Group imports from the same namespace using braces.
phpUtils.formatHtaccess.enable true Enable .htaccess formatting.
phpUtils.createFile.useSubmenu false Show file creation commands in a submenu ("New PHP File...").
phpUtils.createFile.showClass true Show "New PHP Class" command.
phpUtils.createFile.showInterface false Show "New PHP Interface" command.
phpUtils.createFile.showTrait false Show "New PHP Trait" command.
phpUtils.createFile.showEnum false Show "New PHP Enum" command.

Repository & Feedback 🤝

License 📄

This project is licensed under the MIT License.

This extension is a compilation of essential tools, inspired by or directly adapted from the following open-source projects:


Installing from GitHub 📦

Users can install the extension without the Marketplace:

  1. Go to the Releases page.
  2. Download the .vsix file from the latest release assets.
  3. Open VS Code.
  4. Go to the Extensions view (Ctrl+Shift+X).
  5. Click the ... (three dots) menu at the top-right of the Extensions pane.
  6. Select "Install from VSIX...".
  7. Select the downloaded file.
  8. Reload VS Code.

Updates 🔄

Important: Since this extension is not on the Marketplace, VS Code will not auto-update it.

To update to a new version:

  1. Check the Releases page occasionally.
  2. If there is a new version/tag:
    • Download the new .vsix file.
    • Install it using the same steps as above ("Install from VSIX...").
    • VS Code will replace the old version with the new one.
    • Reload the window.

Enjoy writing better PHP code! 🚀

About

vscode-php-utils

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages