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. 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 full-size slide

  2. What is a package?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. Share your unique
    way of solving a
    problem.

    View full-size slide

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

    View full-size slide

  9. 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 full-size slide

  10. Creating
    packages can be a
    little intimidating.

    View full-size slide

  11. Introducing The PHP
    Package Checklist.
    phppackagechecklist.com

    View full-size slide

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

    View full-size slide

  13. Pick a name wisely

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  16. Twig
    Guzzle
    Monolog
    Flysystem
    Swift Mailer
    Eloquent
    Blade
    Aura

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  21. Host source openly

    View full-size slide

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

    View full-size slide

  23. Recommendation: GitHub

    View full-size slide

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

    View full-size slide

  25. GitHub shines
    as social coding
    platform.

    View full-size slide

  26. GitHub has an
    insane number of
    integration options.

    View full-size slide

  27. GitHub is free to use
    for public projects.

    View full-size slide

  28. Alternatives: Bitbucket

    View full-size slide

  29. Autoloader friendly

    View full-size slide

  30. Use a PSR-4 compatible
    autoloader namespace.

    View full-size slide

  31. Place code in
    the /src folder.

    View full-size slide

  32. Distribute via Composer

    View full-size slide

  33. $ composer require league/glide

    View full-size slide

  34. {
    "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 full-size slide

  35. List on Packagist,
    the main Composer
    repository.

    View full-size slide

  36. 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 full-size slide

  37. Framework agnostic

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  40. Follow a coding style

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  45. Write unit tests

    View full-size slide

  46. Aim to cover
    the majority of
    your code.

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  49. DocBlock your code

    View full-size slide

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

    View full-size slide

  51. DocBlock serve as
    inline documentation.

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  54. Use semantic versioning

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  57. Remember to tag
    releases in a timely
    manner!

    View full-size slide

  58. Keep a changelog

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  62. Use continuous integration

    View full-size slide

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

    View full-size slide

  64. Write extensive documentation

    View full-size slide

  65. “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 full-size slide

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

    View full-size slide

  67. The formula to
    awesome docs.

    View full-size slide

  68. Consider hosting
    documentation on
    GitHub Pages.

    View full-size slide

  69. Alternatives: Read the Docs.

    View full-size slide

  70. Include a license

    View full-size slide

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

    View full-size slide

  72. 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 full-size slide

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

    View full-size slide

  74. Welcome contributions

    View full-size slide

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

    View full-size slide

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

    View full-size slide