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
Tweet

More Decks by Jonathan Reinink

Other Decks in Technology

Transcript

  1. View Slide

  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.

    View Slide

  3. View Slide

  4. What is a package?

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  8. Please consider contributing
    a PHP packages to the
    community, or even simply
    helping on an existing one.

    View Slide

  9. Share your unique
    way of solving a
    problem.

    View Slide

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

    View Slide

  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

    View Slide

  12. Creating
    packages can be a
    little intimidating.

    View Slide

  13. Introducing The PHP
    Package Checklist.
    phppackagechecklist.com

    View Slide

  14. View Slide

  15. View Slide

  16. Designed for open
    sources packages,
    but applicable to any
    PHP package.

    View Slide

  17. Pick a name wisely

    View Slide

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

    View Slide

  19. “Calling a spec for
    JSON API’s “JSONAPI”
    is just the worst.
    Searchability: zero.”
    — Frank de Jonge

    View Slide

  20. Twig
    Guzzle
    Monolog
    Flysystem
    Swift Mailer
    Eloquent
    Blade
    Aura

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  24. Avoid using last names
    or personal handles in
    your PHP namespaces.

    View Slide

  25. Host source openly

    View Slide

  26. Hosting your code
    openly encourages:
    • Contributions
    • Downloads
    • Code Reviews
    • Bug Reports

    View Slide

  27. Recommendation: GitHub

    View Slide

  28. Even if you prefer
    Bitbucket, SourceForge,
    or Google Code, your end
    users most likely won’t.

    View Slide

  29. GitHub shines
    as social coding
    platform.

    View Slide

  30. GitHub has an
    insane number of
    integration options.

    View Slide

  31. GitHub is free to use
    for public projects.

    View Slide

  32. Alternatives: Bitbucket

    View Slide

  33. Autoloader friendly

    View Slide

  34. Use a PSR-4 compatible
    autoloader namespace.

    View Slide

  35. Place code in
    the /src folder.

    View Slide

  36. Distribute via Composer

    View Slide

  37. $ composer require league/glide

    View Slide

  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/"
    }
    }
    }

    View Slide

  39. List on Packagist,
    the main Composer
    repository.

    View Slide

  40. View Slide

  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

    View Slide

  42. Framework agnostic

    View Slide

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

    View Slide

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

    View Slide

  45. View Slide

  46. Follow a coding style

    View Slide

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

    View Slide

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

    View Slide

  49. Do this quickly with
    an automated code
    fixer like PHP Coding
    Standards Fixer.

    View Slide

  50. You can also use services
    like Nitpick or StyleCI
    to help you with this.

    View Slide

  51. View Slide

  52. Write unit tests

    View Slide

  53. Aim to cover
    the majority of
    your code.

    View Slide

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

    View Slide

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

    View Slide

  56. DocBlock your code

    View Slide

  57. /**
    * Set source file system.
    * @param Filesystem $source Source file system.
    */
    public function setSource(Filesystem $source)
    {
    $this->source = $source;
    }

    View Slide

  58. DocBlock serve as
    inline documentation.

    View Slide

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

    View Slide

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

    View Slide

  61. Use semantic versioning

    View Slide

  62. View Slide

  63. Follow the pattern:
    MAJOR.MINOR.PATCH
    BREAKING.NEW-FEATURES.BUG-FIXES

    View Slide

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

    View Slide

  65. semver.org

    View Slide

  66. Remember to tag
    releases in a timely
    manner!

    View Slide

  67. Keep a changelog

    View Slide

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

    View Slide

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

    View Slide

  70. View Slide

  71. {% for release in site.github.releases %}
    ## [{{ release.name }}]({{ release.html_url }})
    - {{ release.published_at | date: "%Y-%m-%d" }}
    {{ release.body | markdownify }}
    {% endfor %}

    View Slide

  72. Use continuous integration

    View Slide

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

    View Slide

  74. View Slide

  75. View Slide

  76. Write extensive documentation

    View Slide

  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)

    View Slide

  78. Don’t release an open
    source package unless
    your committed to writing
    good documentation.

    View Slide

  79. The formula to
    awesome docs.

    View Slide

  80. Consider hosting
    documentation on
    GitHub Pages.

    View Slide

  81. Alternatives: Read the Docs.

    View Slide

  82. Include a license

    View Slide

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

    View Slide

  84. The MIT License
    Copyright (c)
    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.

    View Slide

  85. At a minimum,
    include a LICENSE
    file with your library.

    View Slide

  86. Welcome contributions

    View Slide

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

    View Slide

  88. View Slide

  89. Thanks!
    Follow me on Twitter at @reinink.
    Please rate this talk at joind.in/talk/f499d.

    View Slide