mallardduck / prettier-php-runner
Reformat code using Prettier in PHP
Installs: 2 501
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- symfony/process: ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.0
- league/flysystem: ^3.0
- pestphp/pest: ^1.8
- phpunit/phpunit: ^9.5
- spatie/pest-plugin-snapshots: ^1.1
README
Prettier is an opinionated code formatter based on NodeJS that supports a variety of languages. Now you can use the power of Prettier with your PHP projects too!
\MallardDuck\PrettierPhp\PrettierHtml::format( html: '<html><body><div><h1>Heading</h1></div></body></html>' );
Installation
You can install the package via composer:
composer require mallardduck/prettier-php-runner
In your project, you should have the JavaScript package prettier
installed. You can install it via npm...
npm install prettier
... or Yarn.
yarn add prettier
Make sure you have installed Node 10 or higher.
Usage
Here's an example where we are going to highlight some PHP code.
use Spatie\ShikiPhp\Prettier; PrettierHtml::format( '<html><body><div><h1>Heading</h1></div></body></html>' );
The output is this chunk of HTML which will render beautifully in the browser:
<html> <body> <div><h1>Heading</h1></div> </body> </html>
Using Node Version Manager
Under the hood, this package will run a node command beautify your HTML input.
If you use NVM during development, then the package will be unlikely to find your version of node as it
looks for the node executable in /usr/local/bin
and /opt/homebrew/bin
.
If this is the case for you, then you should create a symlink between the node distributable in your NVM folder.
Such a command might look like this:
sudo ln -s /home/some-user/.nvm/versions/node/v17.3.1/bin/node /usr/local/bin/node
Creating this symlink will allow the package to find your NPM executable. Please note, if you change your NPM version you will have to update your symlinks accordingly.
Testing
You can run all the tests with this command:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.