项目创意来源于2月22日Twitter的一个热门的黑Java的段子,看到段子后当即动手,实现了这个 Pythonic PHP Code Formatter。
这个工具可以自动化地把PHP中讨厌的分号以及花括号对齐到右侧(原文如此),让PHP代码看起来就像Python!
但是请注意这只是一个玩具,使用该格式化工具会让你的代码变得难以维护,千万请不要在生产环境中使用!
格式化完毕的代码会长这样:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// base class with member properties and methodsclass Vegetable {
public $edible ;
public $color ;
function Vegetable($edible, $color = "green") {
$this->edible = $edible ;
$this->color = $color ;}
function is_edible() {
return $this->edible ;}
function what_color() {
return $this->color ;}}
// end of class Vegetable// extends the base classclass Spinach extends Vegetable {
public $cooked = false ;
function Spinach() {
$this->Vegetable(true, "green") ;}
function cook_it() {
$this->cooked = true ;}
function is_cooked() {
return $this->cooked ;}}
// end of class Spinach?> |
在线演示地址: http://www.94cb.com/Pythonic-PHP-Code-Formatter
Github地址: https://github.com/lincanbin/Pythonic-PHP-Code-Formatter

代码格式化前:

代码格式化后:







