Skip to content

Commit b01144d

Browse files
committedJun 14, 2023
style: format php code
1 parent 3807c9b commit b01144d

File tree

75 files changed

+321
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+321
-180
lines changed
 

‎lcof/面试题05. 替换空格/Solution.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ class Solution {
44
* @return String
55
*/
66
function replaceSpace($s) {
7-
$rs = "";
7+
$rs = '';
88
for ($i = 0; $i < strlen($s); $i++) {
9-
if ($s[$i] === " ") $rs = $rs."%20";
10-
else $rs = $rs.$s[$i];
9+
if ($s[$i] === ' ') {
10+
$rs = $rs . '%20';
11+
} else {
12+
$rs = $rs . $s[$i];
13+
}
1114
}
1215
return $rs;
1316
}
14-
}
17+
}

‎run_format.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,38 @@ def format_py():
7777
os.remove(p2)
7878

7979

80+
def format_php():
81+
for root, _, files in os.walk(path):
82+
for name in files:
83+
if name.endswith('.php'):
84+
p1 = root + '/' + name
85+
with open(p1, 'r', encoding='utf-8') as f:
86+
content = f.read()
87+
content = '<?php\n' + content
88+
with open(p1, 'w', encoding='utf-8') as f:
89+
f.write(content)
90+
command = f'npx prettier --write "**/*.php"'
91+
os.system(command)
92+
for root, _, files in os.walk(path):
93+
for name in files:
94+
if name.endswith('.php'):
95+
p1 = root + '/' + name
96+
with open(p1, 'r', encoding='utf-8') as f:
97+
content = f.read()
98+
content = content.replace('<?php\n', '')
99+
with open(p1, 'w', encoding='utf-8') as f:
100+
f.write(content)
101+
102+
80103
def git_add():
81104
"""Git add all files"""
82105
command = 'git add .'
83106
os.system(command)
84107

85108

86109
if __name__ == '__main__':
87-
clang_format()
88-
prettier_format()
110+
# clang_format()
111+
# prettier_format()
89112
# format_py()
90113
# git_add()
114+
format_php()

0 commit comments

Comments
 (0)