Skip to content

Commit c948dae

Browse files
author
zouyi6
committed
sync travis files && modify contribute announce
1 parent 994eb74 commit c948dae

File tree

3 files changed

+89
-6
lines changed

3 files changed

+89
-6
lines changed

.travis-build.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
$readMeFilepath = __DIR__ . '/README.md';
4+
$readMeFile = new SplFileObject($readMeFilepath);
5+
$readMeFile->setFlags(SplFileObject::DROP_NEW_LINE);
6+
7+
$cliRedBackground = "\033[37;41m";
8+
$cliReset = "\033[0m";
9+
$exitStatus = 0;
10+
11+
$indentationSteps = 3;
12+
$manIndex = 0;
13+
$linesWithSpaces = [];
14+
$tableOfContentsStarted = null;
15+
$currentTableOfContentsChapters = [];
16+
$chaptersFound = [];
17+
foreach ($readMeFile as $lineNumber => $line) {
18+
if (preg_match('/\s$/', $line)) {
19+
$linesWithSpaces[] = sprintf('%5s: %s', 1 + $lineNumber, $line);
20+
}
21+
if (preg_match('/^(?<depth>##+)\s(?<title>.+)/', $line, $matches)) {
22+
if (null === $tableOfContentsStarted) {
23+
$tableOfContentsStarted = true;
24+
continue;
25+
}
26+
$tableOfContentsStarted = false;
27+
28+
$chaptersFound[] = sprintf('%s [%s](#%s)',
29+
strlen($matches['depth']) === 2
30+
? sprintf(' %s.', ++$manIndex)
31+
: ' *'
32+
,
33+
$matches['title'],
34+
preg_replace(['/ /', '/[^-\w]+/'], ['-', ''], strtolower($matches['title']))
35+
);
36+
}
37+
if ($tableOfContentsStarted === true && isset($line[0])) {
38+
$currentTableOfContentsChapters[] = $line;
39+
}
40+
}
41+
42+
if (count($linesWithSpaces)) {
43+
fwrite(STDERR, sprintf("${cliRedBackground}The following lines end with a space character:${cliReset}\n%s\n\n",
44+
implode(PHP_EOL, $linesWithSpaces)
45+
));
46+
$exitStatus = 1;
47+
}
48+
49+
$currentTableOfContentsChaptersFilename = __DIR__ . '/current-chapters';
50+
$chaptersFoundFilename = __DIR__ . '/chapters-found';
51+
52+
file_put_contents($currentTableOfContentsChaptersFilename, implode(PHP_EOL, $currentTableOfContentsChapters));
53+
file_put_contents($chaptersFoundFilename, implode(PHP_EOL, $chaptersFound));
54+
55+
$tableOfContentsDiff = shell_exec(sprintf('diff --unified %s %s',
56+
escapeshellarg($currentTableOfContentsChaptersFilename),
57+
escapeshellarg($chaptersFoundFilename)
58+
));
59+
60+
@ unlink($currentTableOfContentsChaptersFilename);
61+
@ unlink($chaptersFoundFilename);
62+
63+
if (!empty($tableOfContentsDiff)) {
64+
fwrite(STDERR, sprintf("${cliRedBackground}The table of contents is not aligned:${cliReset}\n%s\n\n",
65+
$tableOfContentsDiff
66+
));
67+
$exitStatus = 1;
68+
}
69+
70+
exit($exitStatus);

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
3+
sudo: false
4+
5+
php:
6+
- nightly
7+
8+
script: php .travis-build.php
9+
10+
notifications:
11+
email: false

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Clean Code PHP
22

3+
## 翻译说明
4+
5+
本文由 php-cpm 基于 [yangweijie版本](https://github.com/yangweijie/clean-code-php)[clean-code-php](https://github.com/jupeter/clean-code-php)翻译并同步大量原文内容。
6+
7+
原文更新频率较高,我的翻译方法是直接用文本比较工具逐行对比。优先保证文字内容是最新的,再逐步提升翻译质量。
8+
9+
阅读过程中如果遇到各种链接失效、内容老旧、术语使用错误和其他翻译错误等问题,欢迎大家积极提交PR。
10+
311
## 目录
412

513
1. [介绍](#介绍)
@@ -47,12 +55,6 @@
4755

4856
## 介绍
4957

50-
本文由 php-cpm 基于 yangweijie 的[clen php code](https://github.com/jupeter/clean-code-php)翻译并同步大量原文内容,欢迎大家指正。
51-
52-
原文更新频率较高,我的翻译方法是直接用文本比较工具逐行对比。优先保证文字内容是最新的,再逐步提升翻译质量。
53-
54-
欢迎大家积极提PR。
55-
5658

5759
本文参考自 Robert C. Martin的[*Clean Code*](https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882) 书中的软件工程师的原则
5860
,适用于PHP。 这不是风格指南。 这是一个关于开发可读、可复用并且可重构的PHP软件指南。

0 commit comments

Comments
 (0)