Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Ignore composer deps.
/vendor/
/composer.lock
composer.phar
vendor/

# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
# Ignore the folder we use when testing the installers.
/build/*
/tmp
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: php
sudo: false
php:
- '5.6'
# - '5.5'
# - '5.4'
#matrix:
# fast_finish: true
env:
global:
# Contains a $GITHUB_TOKEN env var for use with composer to avoid API limits.
- secure: "hsmni1Mi9zCjYaGaCpRnXPYzdBywqPyhKQdrcS4cxJpCIPROd1Txtj8KKa2hdHp6f/xObd3zAqQeJgKDIzkj3ht0D1Za7BCuh+fY21F76k1u/SXIATgq7kk+vFg83EfcuojW4WI94FRhCfJ2bUOzZOpTzpsteo8vadyCJHHztXjcEnvmd9WrTI7OyeMTO/C51dq1yUJyJ1X/XdgwC2VrsUJLAIQzlvEenW7jQzmLp6F2T7b9sh7QrheSmqjX6A8SiN2PBe9YHQgpg0s9Rck3phiG+Th7L+Kpudc+M83a8izI4djyITevZc8l84dHYyonkh68jTNgCjOEz7gRmhuUUAXEaGLeZOJSiwbQKJ8juqPWA9eqTu4x8AR3b56ONb5TVATKNqpNSkzsYu43vtxqsaVsH8GLA3ic3KewRRM9awiLZyuZ1Npk5riD1UhgXv0CdR5geAQmgUh50PGwVcYNFm5/wz9hKaTBevbv1a1fXPzjQqB6aiV/qa7KQppSuYI3h1APOhxpFofQbKy+2plFTPjvWwpowJ3HjULuhSx5Nd7Gg4I8plCfo8yhI8VODOW4KYyh2617hBq2nMvEyS9/DgZ5Bix/mOuOoJMJ/fKnmXS49QLUMadcLSBMlKTUBgEuDtXuK3Q6RgYAY8KUMw6i5Dpu2mPAocoGR1T6ZaDr7Qs="
branches:
except:
- gh-pages
install:
- composer self-update --no-interaction
- composer config -g github-oauth.github.com $GITHUB_TOKEN
- composer install --no-interaction
script:
- vendor/bin/phpunit
notifications:
email: false
147 changes: 146 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,147 @@
# composer-plugins
# Loadsys Composer Plugins

[![Build Status](https://travis-ci.org/loadsys/composer-plugins.svg?branch=master)](https://travis-ci.org/loadsys/composer-plugins)

Including this package in your composer.json makes a number of installers and project types available.




## PHP CodeSniffer, `phpcs-coding-standard` type (copying folders approach)

When you develop your own Coding Standard for the [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), you can package it for installation via Composer, but `phpcs` won't know about your standard unless you either manually specify it on the command line every time:

```shell
$ vendor/bin/phpcs --standard=vendor/yourname/your-codesniffer/YourStandard .
```

Or you must use the `--config-set` switch to write your Standard's path into the `phpcs` config file:

```shell
$ vendor/bin/phpcs --config-set installed_paths vendor/yourname/your-codesniffer
```

Neither of these is convenient, and defeats the purpose of using Composer to make your dependencies "automatically" available to your project.

This plugin provide a custom installer that engages for the Composer `type` of `phpcs-coding-standard`.

When you create your coding standard package, use this `type` in your composer.json file, and `require` this package of composer plugins in order to gain access to the Installer for that type:

```json
{
"name": "yourname/your-codesniffer",
"type": "phpcs-coding-standard",
"require": {
"squizlabs/php_codesniffer": "~2.3",
"loadsys/composer-plugins": "dev-master"
}
}
```

You must also make sure your coding standard lives in a subfolder of the package, usually with a proper name. For example: `GIT_ROOT/YourStandard/ruleset.xml`. This allows for multiple standards to be installed from a single package.

It also usually makes sense for your coding standard to include the required version of `squizlabs/php_codesniffer` itself, so that your projects that use this standard don't have to require it themselves, or accidentally require the wrong version.

With this setup, when your standard is included in another project, the installer in this package will search its `vendor/your-name/your-codesniffer/` folder for folders that contain `ruleset.xml` files, indicating that those sub-folders contain Coding Standards. This installer will then copy those folders into the `vendor/squizlabs/CodeSniffer/Standards/` folder for you, making your Coding Standard immediately available to `phpcs --standard YourStandard .` without any additional configuration.




## PHP CodeSniffer, post-install hook (copying folders approach)

Sometimes you want to use somebody else's coding standard package where you can't set the `type` explicitly. In cases like this, this package provides composer hook scripts that can be used to accomplish the same effect.

The script works by scanning each installed package for any immediate sub-folders containing a `ruleset.xml` file (which indicates that folder contains a Coding Standard.) It then copies those folders into the `CodeSniffer/Standards/` directory, making them available to `phpcs`.

To use this hook script, add the following to your root project's `composer.json`:

```json
{
"require": {
"squizlabs/php_codesniffer": "~2.3",
"loadsys/composer-plugins": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Loadsys\\Composer\\PhpCodesniffer\\CodingStandardHook::postInstall"
],
"post-update-cmd": [
"Loadsys\\Composer\\PhpCodesniffer\\CodingStandardHook::postInstall"
],
"pre-package-uninstall": [
"Loadsys\\Composer\\PhpCodesniffer\\CodingStandardHook::prePackageUninstall"
]
}
}
```

The `postInstall` command checks every installed package for Coding Standard folders, and copies those folders into the `CodeSniffer/Standards/` folder directly. This should also be run post-update, in order to copy updates to a Coding Standard into the correct place for use.

The `prePackageUninstall` removes any Coding Standard folders from a package that is being removed from the phpcs `CodeSniffer/Standards/` folder.




## PHP CodeSniffer, post-install hook (config editing approach)

:warning: Speculative! :warning:

@TODO: _This approach is partially coded already, but the plan is to eventually use an `extra` flag in the composer.json file to determine whether to copy standards folders or manage entries in phpcs's config file. This approach could be used both by the `phpcs-coding-standard` type as well as the postInstall hooks._



Sometimes you want to use somebody else's coding standard package where you can't set the `type` explicitly. In cases like this, this package provides composer hook scripts that can be used to accomplish the same effect.

The script works by scanning each installed package for any folders containing a `ruleset.xml` file (which indicates that folder contains a Coding Standard.) It then adds the vendor paths for these folders into the `CodeSniffer.conf` file, making them available to `phpcs` in their natural install location.

To use this hook script, add the following to your root project's `composer.json`:

```json
{
"require": {
"squizlabs/php_codesniffer": "~2.3",
"loadsys/composer-plugins": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Loadsys\\Composer\\PhpCodesniffer\\CodingStandardHook::postInstall"
],
"post-update-cmd": [
"Loadsys\\Composer\\PhpCodesniffer\\CodingStandardHook::postInstall"
],
"pre-package-uninstall": [
"Loadsys\\Composer\\PhpCodesniffer\\CodingStandardHook::prePackageUninstall"
]
}
}
```

The `postInstall` command checks every installed package for Coding Standard folders, and adds the path for any packages containing Standards into `phpcs`'s `installed_paths` config setting. This should also be run `post-update` in case the package's installed_path has changed.

The `postPackageUninstall` removes the path for a package that is being removed from the phpcs config file.




## Contributing

Create an issue or submit a pull request.

### Running Unit Tests

* `composer install`
* `vendor/bin/phpunit`




## License

[MIT](https://github.com/loadsys/puphpet-release/blob/master/LICENSE).




## Copyright

© 2015 [Loadsys Web Strategies](http://loadsys.com)
42 changes: 42 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "loadsys/composer-plugins",
"description": "Provides composer custom installers and hook scripts.",
"keywords": [
"composer",
"plugins",
"loadsys",
"codesniffer",
"puphpet",
"vagrant"
],
"type": "composer-plugin",
"license": "MIT",
"authors": [
{
"name": "Brian Porter",
"email": "beporter@users.sourceforge.net"
}
],
"autoload": {
"psr-4": {
"Loadsys\\Composer\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Loadsys\\Composer\\Test\\": "tests"
}
},
"extra": {
"class": "Loadsys\\Composer\\LoadsysComposerPlugin"
},
"require": {
"composer-plugin-api": "~1.0.0",
"symfony/filesystem": "~2.6"
},
"require-dev": {
"composer/composer": "1.0.*@dev",
"phpunit/phpunit": "~4.8",
"squizlabs/php_codesniffer": "~2.0"
}
}
27 changes: 27 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="all">
<directory>tests/TestCase</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
29 changes: 29 additions & 0 deletions src/LoadsysComposerPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Loadsys\Composer;

// Needed for PluginInterface:
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;

/**
* Plugin entry point.
*
*/
class LoadsysComposerPlugin implements PluginInterface {

/**
* Activate the plugin (called from {@see \Composer\Plugin\PluginManager})
*
* All we need to do is register our custom installer classes.
*
* @param \Composer\Composer $composer The active instance of the composer base class.
* @param \Composer\IO\IOInterface $io The I/O instance.
* @return void
*/
public function activate(Composer $composer, IOInterface $io) {
$phpcsCodingStandardInstaller = new PhpCodesniffer\CodingStandardInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($phpcsCodingStandardInstaller);
}
}
Loading