Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The PHP Package Checklist (Lone Star PHP 2016)

The PHP Package Checklist (Lone Star PHP 2016)

Composer has changed the landscape of PHP. Gone are the days of massive kitchen-sink frameworks. We're now in the era of packages. And we can all contribute! This talk will walk you through each step of the PHP Package Checklist (phppackagechecklist.com). You'll learn how to properly package your PHP projects, ensuring they are taken seriously by the rest of the PHP community!

Jonathan Reinink

April 08, 2016

More Decks by Jonathan Reinink

Other Decks in Technology


  1. None
  2. Jonathan Reinink Software developer from Canada. Been writing PHP for

    over 16 years. Marketing agency for over a decade. Started contract development this year. I <3 open source.
  3. None
  4. What is a package?

  5. Packages are important because they provide code we don’t have

    to write.
  6. Today there are 92,000 PHP package available on Packagist.

  7. Packages are a BIG part of what makes a language

  8. Please consider contributing a PHP packages to the community, or

    even simply helping on an existing one.
  9. Share your unique way of solving a problem.

  10. I promise it will be of benefit to you.

  11. Contributing to an open source package will push you as

    a developer. GIT GitHub Issues Pull Requests Rebasing Testing TDD Semantic Versioning Code Coverage Composer Packagist Coding Standards PHP-FIG PSR DocBlocks Travis Scrutinizer CI Changelogs Licensing Code Sniffer Jekyll Shields.io Code Quality Milestones Releases Dependency Injection Coupling Cohesion
  12. Creating packages can be a little intimidating.

  13. Introducing The PHP Package Checklist. phppackagechecklist.com

  14. None
  15. None
  16. Designed for open sources packages, but applicable to any PHP

  17. Pick a name wisely

  18. Ensure that there is a unique identifier in your package

  19. “Calling a spec for JSON API’s “JSONAPI” is just the

    worst. Searchability: zero.” — Frank de Jonge
  20. Twig Guzzle Monolog Flysystem Swift Mailer Eloquent Blade Aura

  21. Ensure the name isn't already used by another project.

  22. Maintain consistency between this name and your PHP namespace.

  23. // Good: namespace Glide; namespace League\Glide; // Bad: namespace Images;

    namespace ImageManipulations; namespace PHPGlide; namespace YoloImages;
  24. Avoid using last names or personal handles in your PHP

  25. Host source openly

  26. Hosting your code openly encourages: • Contributions • Downloads •

    Code Reviews • Bug Reports
  27. Recommendation: GitHub

  28. Even if you prefer Bitbucket, SourceForge, or Google Code, your

    end users most likely won’t.
  29. GitHub shines as social coding platform.

  30. GitHub has an insane number of integration options.

  31. GitHub is free to use for public projects.

  32. Alternatives: Bitbucket

  33. Autoloader friendly

  34. Use a PSR-4 compatible autoloader namespace.

  35. Place code in the /src folder.

  36. Distribute via Composer

  37. $ composer require league/glide

  38. { "name": "league/glide", "require": { "intervention/image": "^2.1", "league/flysystem": "^1.0", "php":

    "^5.4 | ^7.0", "psr/http-message": "^1.0" }, "autoload": { "psr-4": { "League\\Glide\\": "src/" } } }
  39. List on Packagist, the main Composer repository.

  40. None
  41. Official Website https://getcomposer.org/ Laracasts https://laracasts.com/series/laravel-5-fundamentals/episodes/1 Sitepoint http://www.sitepoint.com/php-dependency-management-with-composer/ Code Mentor https://www.codementor.io/php/tutorial/composer-install-php-dependency-manager

  42. Framework agnostic

  43. Don't limit your project to just one framework.

  44. Offer framework specific support for your package using service providers.

  45. None
  46. Follow a coding style

  47. Highly recommended that you adhere to the PSR-2 coding style

  48. A familiar coding style makes open source code easier to

    contribute to.
  49. Do this quickly with an automated code fixer like PHP

    Coding Standards Fixer.
  50. You can also use services like Nitpick or StyleCI to

    help you with this.
  51. None
  52. Write unit tests

  53. Aim to cover the majority of your code.

  54. PHPUnit is the de facto testing framework in PHP.

  55. Alternatives: phpspec, Behat, atoum, Codeception.

  56. DocBlock your code

  57. /** * Set source file system. * @param Filesystem $source

    Source file system. */ public function setSource(Filesystem $source) { $this->source = $source; }
  58. DocBlock serve as inline documentation.

  59. They can also improve code completion in IDEs, like PhpStorm.

  60. Can be automatically converted into API documentation, see phpDocumentor.

  61. Use semantic versioning

  62. None

  64. Semantic versioning allows developers to upgrade code safely, without worrying

    about breaking changes.
  65. semver.org

  66. Remember to tag releases in a timely manner!

  67. Keep a changelog

  68. Show notable changes that have been made between releases.

  69. Consider following the Keep a CHANGELOG format, see keepachangelog.com.

  70. None
  71. {% for release in site.github.releases %} ## [{{ release.name }}]({{

    release.html_url }}) - {{ release.published_at | date: "%Y-%m-%d" }} {{ release.body | markdownify }} {% endfor %}
  72. Use continuous integration

  73. Use a service to automatically check coding standards and run

  74. None
  75. None
  76. Write extensive documentation

  77. “Tests are hard so we practice to get better. Docs

    are hard… so we don’t write any and complain.” — Steve Klabnik, Senior Technical Writer (maintainer of the official Rust documentation)
  78. Don’t release an open source package unless your committed to

    writing good documentation.
  79. The formula to awesome docs.

  80. Consider hosting documentation on GitHub Pages.

  81. Alternatives: Read the Docs.

  82. Include a license

  83. See choosealicense.com. Most PHP projects use the MIT License.

  84. The MIT License Copyright (c) <year> <copyright holders> Permission is

    hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  85. At a minimum, include a LICENSE file with your library.

  86. Welcome contributions

  87. Have a CONTRIBUTING file, welcoming contributions to the project.

  88. None
  89. Thanks! Follow me on Twitter at @reinink. Please rate this

    talk at joind.in/talk/f499d.