Slide 1

Slide 1 text

Let’s Build a Composer Package Ben Ramsey
 24 Oct 2019 • php[world]

Slide 2

Slide 2 text

Hi. I’m Ben. - Organizer at Nashville PHP - Open source advocate - ramsey/uuid library - Craft beer nerd - @ramsey on Twitter - @[email protected] on Mastodon

Slide 3

Slide 3 text

- Learn the properties of a “good” package - Create a package - Push your package to a repository - Connect your repo to Travis CI & Coveralls - Publish your package on Packagist You will:

Slide 4

Slide 4 text

Requirements. - PHP 7.2+ - Composer

Slide 5

Slide 5 text

Homebrew: brew.sh 
 brew install [email protected] export PATH="/usr/local/opt/[email protected]/bin:$PATH" php -v macOS

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Web Platform Installer:
 microsoft.com/web/downloads/platform.aspx php -v Windows

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Use your favorite package manager. *nix

Slide 11

Slide 11 text

Composer Install Composer: getcomposer.org/download php composer.phar --version Or composer --version

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Getting started.

Slide 15

Slide 15 text

What problem do you want to solve?

Slide 16

Slide 16 text

You own the code. How do you want others to use it?

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

- MIT license - BSD 2-Clause “Simplified” - Apache License 2.0 - GNU Library or “Lesser” General Public License (LGPL)

Slide 19

Slide 19 text

Now we can begin.

Slide 20

Slide 20 text

The project.

Slide 21

Slide 21 text

github.com/ramsey/php-library-skeleton

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Let’s Build!

Slide 24

Slide 24 text

Maintaining your package.

Slide 25

Slide 25 text

- Add your tests/ directory - Add your docs/ directory - Add your phpunit.xml.dist file Add anything that shouldn’t be bundled into the distribution when someone requires your package with Composer. .gitattributes

Slide 26

Slide 26 text

.gitattributes export-ignore .github/ export-ignore .gitignore export-ignore .travis.yml export-ignore docs/ export-ignore phpstan.neon export-ignore phpunit.xml.dist export-ignore tests/ export-ignore

Slide 27

Slide 27 text

- PHPUnit, Atoum, Kahlan, etc. - Aim for sufficient code coverage - Make it easy to run your tests:
 composer test Testing.

Slide 28

Slide 28 text

- PHPStan, Exakat, Phan, Psalm, PHP Inspections (JetBrains), etc. - Finds errors in your code without running it - Especially helpful when multiple people are working on the same project Static analysis.

Slide 29

Slide 29 text

- PSR-12, Symfony, CakePHP, WordPress, etc. - Use PHP_CodeSniffer to ensure your code follows your chosen standards - Catch standards issues before code review Coding standards.

Slide 30

Slide 30 text

- Just like with npm and package.json, Composer supports custom scripts - Custom scripts can help your contributors - Use them to consolidate tools into simple, easy-to-remember commands Scripts.

Slide 31

Slide 31 text

"scripts": { "lint": "parallel-lint src tests", "phpcs": "phpcs src tests --standard=psr12 -sp --colors", "phpstan": [ "phpstan analyse src -c phpstan.neon --level max --no-progress", "phpstan analyse tests -c phpstan.neon --level 4 --no-progress" ], "phpunit": "phpunit --verbose --colors=always", "phpunit-ci": "phpunit --coverage-clover build/logs/clover.xml", "phpunit-coverage": "phpunit --coverage-html build/coverage", "test": ["@lint", "@phpcs", "@phpstan", "@phpunit"], "test-ci": ["@lint", "@phpcs", "@phpstan", "@phpunit-ci"] }

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

- Tells your users what has changed between versions - Log changes, no matter how big or small - Log what you’ve added, changed, deprecated, removed, fixed, & secured Changelog.

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

- Follow semantic versioning - Backwards-compatibility breaks? - Major release - New features that don’t break BC? - Minor release - Bug fixes that don’t break BC? - Patch release Versioning.

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Building your community.

Slide 38

Slide 38 text

Readme.

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Contributing.

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Templates.

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Code of conduct.

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Automation.

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Publishing.

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Enjoy the FOSS community.

Slide 52

Slide 52 text

Use a welcoming voice.

Slide 53

Slide 53 text

Build up. Don’t tear down.

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

LINKS TO RESOURCES 1. Composer: https://getcomposer.org/ 2. Packagist: https://packagist.org/ 3. Open Source Licenses: https://opensource.org/licenses 4. ramsey/php-library-skeleton: https://github.com/ramsey/php-library-skeleton 5. PHP Framework Interoperability Group: http://www.php-fig.org/ 6. PHP Package Development Standards: http://php-pds.com/ 7. Semantic Versioning: http://semver.org/ 8. PHP CodeSniffer: https://github.com/squizlabs/PHP_CodeSniffer 9. PHPUnit: https://phpunit.de/ 10. phpstan: https://github.com/phpstan/phpstan 11. Travis CI: https://travis-ci.org/ 12. CHANGELOG.md: http://keepachangelog.com 13. Code of Conduct - Contributor Covenant: http://contributor-covenant.org/ - Citizen Code of Conduct: http://citizencodeofconduct.org/ 14. CONTRIBUTING.md: http://mozillascience.github.io/working-open-workshop/contributing/ 15. Open Source Guides: https://opensource.guide/ 16. A Beginner’s Guide to Creating a Readme: https://changelog.com/posts/a-beginners-guide-to-creating-a-readme 17. Use .gitattributes: https://blog.madewithlove.be/post/gitattributes/

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

benramsey.com @ramsey github.com/ramsey [email protected] THANK YOU. ANY QUESTIONS? If you want to talk more, feel free to contact me. Let’s Build a Composer Package Copyright © 2019 Ben Ramsey This work is licensed under Creative Commons Attribution- ShareAlike 4.0 International. For uses not covered under this license, please contact the author. Ramsey, Ben. “Let’s Build a Composer Package” php[world]. Sheraton Tysons Hotel, Tysons, VA. 24 Oct. 2019. Conference presentation. This presentation was created using Keynote. The text is set in Chunk Five and Helvetica Neue. The source code is set in Menlo. The iconography is provided by Font Awesome. Unless otherwise noted, all photographs are from Unsplash or Pixabay and are used with permission. @[email protected]