PHP beautifcation support
Glavin001 opened this issue · 16 comments
👍
@m1ga have you tried the PHP-Beautifier on it's own, from PIP? I just want to confirm that it works correctly, on it's own and as expected by yourself (a PHP user), before I go down that path.
@Glavin001 yes I've tried (pear) PHP-Bautifier from the command line and it looks fine. Haven't had the time to look at the options yet but even with the standard settings it looks fine!
The (atom) php-beautifier isn't working because of https://github.com/sdwood/php-beautifier/issues/3
Hah, pear. As you can see, I am not a PHP user myself 😉.
I'll see if I can get it working soon.
Installing pear
for Mac: http://coolestguidesontheplanet.com/installing-pear-osx-10-9-mavericks-osx10-810-7/
@m1ga could you give me a little sample snippet of PHP code, before and after beautification? So I can do some test.
I am trying with:
$t=date("H");
if ($t<"10") {
echo "Have a good morning!";
} elseif ($t<"20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
However it does not change after beautifying..
Update: turns out you must have the <?php
and ?>
in the file, as well. Totally forgot. Silly me.
sure
<?php
if (!isset($_SESSION)) session_start();
require_once("sql.req.php");
// friend requests
$q = $mysqli->query("");
$num = $q->num_rows;
echo '<a href="notifications.php">';
if ($num>0) { echo '<i class="fa fa-star white"></i>';
}else { echo '<i class="fa fa-star-o"></i>'; }
echo '</a>';
// new messages
$q = $mysqli->query("");
$num = $q->num_rows;
echo '<a href="messages.php">';
if ($num>0) {
echo '<i class="fa fa-envelope white"></i>';
}else {
echo '<i class="fa fa-envelope-o"></i>';
}
echo '</a>';
?>
Thank you, @m1ga.
On my Mac it is not working cleanly:
$ php_beautifier --indent_spaces test.php test.php.out
PHP Strict Standards: Non-static method Console_Getopt::readPHPArgv() should not be called statically in /Users/glavin/pear/bin/php_beautifier on line 70
PHP Strict Standards: Non-static method Console_Getopt::getopt() should not be called statically in /Users/glavin/pear/bin/php_beautifier on line 84
PHP Strict Standards: Non-static method Console_Getopt::doGetopt() should not be called statically in /Users/glavin/pear/share/pear/Console/Getopt.php on line 92
PHP Strict Standards: Non-static method PEAR::isError() should not be called statically in /Users/glavin/pear/share/pear/Console/Getopt.php on line 109
PHP Strict Standards: Non-static method Console_Getopt::_parseLongOption() should not be called statically in /Users/glavin/pear/share/pear/Console/Getopt.php on line 153
PHP Strict Standards: Non-static method PEAR::isError() should not be called statically in /Users/glavin/pear/share/pear/Console/Getopt.php on line 154
PHP Strict Standards: Non-static method PEAR::isError() should not be called statically in /Users/glavin/pear/bin/php_beautifier on line 85
So instead of using stdout, have php_beautify pipe to file.
Note: Use https://github.com/bruce/node-temp for creating temporary file that will receive output.
I'm getting these warnings too but the test.php.out file looks good.
@m1ga for the time being, until @karolyi has reviewed the Pull Request, you can use my fork:
# Clone fork repo
git clone git@github.com:Glavin001/atom-beautify.git
# Change into repo directory
cd atom-beautify/
# Install dependencies
npm install
# Uninstall old atom-beautify, if applicable
apm uninstall atom-beautify
# Link and use this atom-beautify
apm link
# Update dependencies
npm install
# Restart atom
Let me know if there is anything else.
I can't use php_beautifier cause of temporary file of current active session... I'm on Ubuntu 14.04 with php 5.6 and latest version of atom. All php_beautifier dependencies have installed and they're working correctly from terminal.
Please see giving error:
Command failed: /bin/sh -c [ -f ~/.bash_profile ] && source ~/.bash_profile;[ -f ~/.bashrc ] && source ~/.bashrc;php "/usr/bin/php_beautifier " --input "/tmp/input115014-12433-1i2xoqb" --output "/tmp/115014-12433-1ke9sic" /bin/sh: 1: source: not found
I've watched carefully "/tmp/" directory. But there's no file created during any session... How to solve this?
@Batmandakh I have the same error.
+1 same error with tmp files
Sounds like for some reason source ~/.bashrc;
is not working on your Ubuntu computer.
The afflicting lines of code can be found at: https://github.com/Glavin001/atom-beautify/blob/master/lib/langs/cli-beautify.coffee#L45-L50
If you can comment out those lines in your local installation of Atom Beautify, that should fix it. You will have to manually set the path of php_beautifier
in the Atom Beautify Package Settings.
#164 will solve this.
Whenever I try to use your package to beautify my php file it throws me this.
spawn php ENOENT
spawn php ENOENT
Hide Stack Trace
Error: spawn php ENOENT
at exports._errnoException (util.js:734:11)
at Process.ChildProcess._handle.onexit (child_process.js:1035:32)
at child_process.js:1127:20
at process._tickCallback (node.js:357:13)
Is it because of wrong configuration?