貢獻PHP套件開源專案學到的技巧
Outline
-
自我介紹
-
什麼是開源專案?可以吃嗎?
-
開源貢獻包含了哪一些?
-
我怎麼入坑的?
-
學習到的 Modern PHP 技巧
-
多人開發心得 & 有趣的事情
-
介紹國外的開源貢獻活動
自我介紹
-
Peter
-
目前在ITRI服務
-
後端開發者
-
3+ years PHP 後端程式開發
-
PHP 5.3 → PHP 7+
-
No framework→Slim→Laravel
-
2 years 開源專案貢獻者

什麼是開源專案?
以開源專案許可下公開的專案
-
MIT License
-
GPL/GNU
-
Apache Licenese
-
etc.
什麼是開源專案貢獻?
開源貢獻活動
-
Issue submission
-
Send pull request
-
etc.
Issue submission
Report bugs

Feature requests

Official docs

Send pull request
-
在發送issue之後
-
也可以直接發送 PR
開源貢獻流程
-
發送 issue → 發送 PR
-
直接發送 PR
開源貢獻好處
-
學習技巧
-
線上多人合作
-
看code能力提升,再爛code都可以看
- 幫助別人,也幫助自己
-
不用加入公司,也可以對他們開源專案做貢獻
我是怎麼入坑的?
事情是這樣的...
當時的社群機器人很夯
我想做個問天氣機器人
我找到了bug...並發送PR
Bug

第一次就不會發送PR
還開了很多個PR...
還被指教了一番

最後還是被merged了

第一次 PR 我學會了...
-
Squash all commits to one commit
-
Explain for the changes
-
Accept request changes
等一等...
那個問天氣機器人呢?
去開源貢獻了!
不要問我問天氣機器人在哪!
因為我也不知道XD
我學到的Modern PHP技巧
從四個種類角度切入
Enhancement
Features
Fix bugs
Write docs
Enhancement
-
Test enhancement
-
Test enhancement 2 Organize src
- Add more tests
Test enhancement

Test enhancement tips
$this->assertSame(true, $resultTrue);
$this->assertSame(false, $resultFalse);
$this->assertSame(\InvalidgrumentException::class,
$resultInstance);
$this->assertSame(23, count($resultArray));
$this->assertInstanceOf('\\Psecio\\SecureDotenv\\KeySource\\KeyString',
$k);
Test enhancement tips
$this->assertTrue($resultTrue);
$this->assertFalse($resultFalse);
$this->assertInstanceOf(\InvalidgrumentException::class,
$resultInstance);
$this->assertCount(23, $resultArray);
$this->assertInstanceOf(KeyString::class, $k);
Test enhancement tips

Test enhancement tips

Organize src

Organize src

Organize src

Add more tests

Add more tests

Add more tests

Features
Add isPrimeNumber method

Add isPrimeNumber method


Initialize tests

Initialize tests

Fix bugs
- oscarotero/imagecow
- jwage/easy-csv
- jwage/purl PR#60
- jwage/purl PR#62
oscarotero/imagecow

oscarotero/imagecow


oscarotero/imagecow

oscarotero/imagecow

oscarotero/imagecow

jwage/easy-csv

jwage/easy-csv

jwage/easy-csv

jwage/easy-csv
return
(isset($this->headers) && is_array($this->headers))
&& (count($this->headers) !== count($row))
? $this->getRow() : array_combine($this->headers, $row);
jwage/purl PR#60

jwage/purl PR#60

jwage/purl PR#60
URI = scheme:[//authority]path[?query][#fragment]
jwage/purl PR#60

jwage/purl PR#62

jwage/purl PR#62

Write docs
odan/image

odan/image

odan/image

odan/image

odan/image

danielgsims/php-collections

danielgsims/php-collections

danielgsims/php-collections

Review PR
m1/Env

m1/Env

m1/Env

appzcoder/30-seconds-of-php-code

nahid/jsonq

nahid/jsonq

難→易
-
Enhancement
-
Features
-
Fix bugs
-
Write docs
貢獻前需要知道的事
貢獻步驟
-
Create issue (option)
-
Fork it
- Read the CONTRIBUTING.md
-
Create and checkout a branch
-
Add the code
-
Send PR
CONTRIBUTING.md

Coding style
.php_cs

PHP_CodeSniffer
curl -OL \
https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
php phpcs.phar --standard=PSR2 src/ tests/ --colors
Static analyzer
phpstan

psalm.xml

psalm.xml

Continuous Intergration
CI
Travis CI/.travis.yml


StyleCI/.styleci.yml

介紹國外的開源貢獻活動
Hacktoberfest
Hacktoberfest
24pullrequests
Summary
- 沒有最好,只有比較好
- Accept request changes
- 開源貢獻是多人合作的經驗
Summary
-
被人幫助,幫助別人
-
別人的感謝是繼續貢獻動力
-
讓開源專案更好
-
做國民外交
別人的感謝是繼續貢獻動力

別人的感謝是繼續貢獻動力

Any questions?

貢獻PHP套件開源專案學到的技巧
By peter279k
貢獻PHP套件開源專案學到的技巧
- 2,516