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

Package Development Laracon EU

Package Development Laracon EU

Registering your new awesome package to packagist is easy. But what about maintainability? What dependencies should you avoid? Have you considered reducing download size? How will you keep your users up to date with changes in newer versions? How do you best handle releases? How do you manage your package to behave in an optimal way both in other people's production environment as in your local package development environment?

These and many other tips for medium to high quality packages are included in this talk.

https://www.youtube.com/watch?v=lreUaGnOOYs

Hannes Van De Vreken

August 26, 2015
Tweet

More Decks by Hannes Van De Vreken

Other Decks in Technology

Transcript

  1. BEGINNER STEPS - VERSIONS Class Sdk { public function __construct(Illuminate\Config\Repository

    $confi { … } } /** * Register method. */ public function register() { // Register SDK class. $this->app->singleton('twilio', function () { return new Sdk($this->app['config']); }); }
  2. BEGINNER STEPS - VERSIONS Class Sdk { public function __construct(array

    $options) { … } } /** * Register method. */ public function register() { // Register SDK class. $this->app->singleton('twilio', function () { $config = $this->app['config']; return new Sdk($config->get('services.twilio')); }); }
  3. BEGINNER STEPS - CHANGELOG # Change Log All notable changes

    to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] ### Changed - Improve argument against commit logs. ## [0.0.8] - 2015-02-17 ### Changed - Update year to match in every README example. - Reluctantly stop making fun of Brits only, since most of the world writes dates in a strange way. ### Fixed - Fix typos in recent README changes. - Update outdated unreleased diff link.
  4. BEGINNER STEPS - README.MD // open an image file $img

    = Image::make('public/foo.jpg'); // resize image instance $img->resize(320, 240); // insert a watermark $img->insert('public/watermark.png'); // save image in desired format $img->save('public/bar.jpg');
  5. BEGINNER STEPS - HINT 1 $ construct generate --help Arguments:

    name The vendor/project name Options: --test (-t) Testing framework (default: "phpunit") --license (-l) License (default: "MIT") --namespace (-s) Namespace for project (default: "Vendor\\Pro --git (-g) Initialize an empty Git repo --phpcs (-p) Generate a PHP Coding Standards Fixer config --keywords (-k) Comma separated list of Composer keywords --vagrant Generate a Vagrantfile
  6. BEGINNER STEPS - HINT 2 $ studio load --help Usage:

    load <path> Arguments: path The path where the package files are located
  7. INTERMEDIATE TIPS - ENVIRONMENTS - DEV & CI not in

    production: composer require --dev
  8. INTERMEDIATE TIPS - ENVIRONMENTS - CI phpunit --coverage-html=/tmp/coverage/; vs phpunit

    --coverage-clover=/tmp/coverage.xml; ocular code-coverage:upload /tmp/coverage.xml;
  9. INTERMEDIATE TIPS - CLEAN DISTS "autoload": { "psr-4": { "GuzzleHttp\\":

    "src/" } }, "autoload-dev": { "psr-4": { "GuzzleHttp\\Stubs\\": "tests/stubs/" } }
  10. INTERMEDIATE TIPS - CODE STYLE $container = new Container; $container

    = new Container(); $options = [ 'ssl' => true, 'redirects' => false, ];
  11. DECOUPLING - HTTP EXAMPLE /* @var \Psr\Http\Message\RequestInterface $request */ /*

    @var \Psr\Http\Message\ResponseInterface $response */ /* @var \Http\Adapter\HttpAdapter $adapter */ $response = $adapter->send($request);
  12. DECOUPLING - HTTP EXAMPLE /** * @param \Http\Adapter\HttpAdapter $adapter */

    public function __construct(HttpAdapter $adapter) { $this->adapter = $adapter; }
  13. company/sdk requires (1.0.0) php-http/adapter-implementation php-http/adapter provides (1.0.0) requires (1.0.0) guzzlehttp/guzzle

    requires (^6.0) application requires (x.y.z) requires (1.0.0) requires (1.0.0) php-http/guzzle6-adapter
  14. DECOUPLING - RECAP - Single responsibility principle - Try to

    decouple from implementation - Depend on virtual packages