I am using PHPCS and PHPCBF for WordPress development in VS Code.
( as per instructions mentioned in https://github.com/tommcfarlin/phpcs-wpcs-vscode )
While PHPCBF is formatting the codes as per WPCS, I still feel that the code looks really ugly, especially when Html tags are present in the PHP document.
When I use Intelephense to format the Php codes, the code looks visually pleasant including properly indented Html tags. The tradeoff of using Intelephense is that the code is not WPCS compliant anymore. There is an option to include WordPress as stubs in Intelephense but that is only for including WordPress specific functions and not related to formatting.
Some issues faced while formatting with Intelephense are:
- No space after opening and before the closing parenthesis, (phpcs)
- There must be no blank line before the file comment (phpcs)
<?php
// this is a blank line inserted by Intelephense which is causing error no.2 provided in summary above
/**
* This is a sample file
*
* @package something.
* something something
* something something
*/
get_header();
if (have_posts()) {
while (have_posts()) {
// No space is inserted by Intelephense After opening and before Closing parenthesis which is causing error no.1 provided in summary above
the_post(); ?>
<h2>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a>
</h2>
<?php the_content(); ?>
<hr>
<?php
}
}
get_footer();
?>