Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (79)
Showing
with 638 additions and 89 deletions
stages:
- lint
- test
cache:
paths:
- vendor/
before_script:
- apt-get update; apt-get install -y unzip
- composer install --optimize-autoloader --no-interaction --no-ansi --prefer-dist
lint:coding-guideline: &PHP-LINTING
image: tetraweb/php:7.0
stage: test
script:
- mkdir result
- ./vendor/bin/phpcs -s -n --report-full=result/phpcs-full.txt --report-diff=result/phpcs-diff.txt --report-summary=result/phpcs-summary.txt
.lint: &lint
image: composer
stage: lint
before_script:
- apk --no-cache add parallel
- php -v
- composer --no-ansi self-update
- composer --no-ansi --version
- composer install --optimize-autoloader --classmap-authoritative --no-interaction --prefer-dist --no-ansi
artifacts:
when: on_failure
paths:
- result
lint:
<<: *lint
script:
- find . -name \*.php ! -path "./vendor/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;
lint:coding-guideline:
<<: *lint
script:
- mkdir result
- ./vendor/bin/phpcs -s -n --report=full --report-full=result/phpcs-full.txt --report-diff=result/phpcs-diff.txt --report-summary=result/phpcs-summary.txt
lint:php-mass-detection:
<<: *PHP-LINTING
<<: *lint
script:
- mkdir result
- ./vendor/bin/phpmd src text phpmd.xml | tee result/phpmd.txt
test:5.3: &PHP-UNITTESTING
image: tetraweb/php:5.3
.test: &test
stage: test
tags:
- docker
variables:
TIMEZONE: "Europe/Berlin"
WITH_XDEBUG: "true"
before_script:
- apt-get update; apt-get install -y unzip
- composer install --optimize-autoloader --no-interaction --no-ansi --prefer-dist
script:
- ./vendor/bin/phpunit --coverage-text --colors=never
test:5.4:
<<: *PHP-UNITTESTING
<<: *test
image: tetraweb/php:5.4
test:5.5:
<<: *PHP-UNITTESTING
<<: *test
image: tetraweb/php:5.5
test:5.6:
<<: *PHP-UNITTESTING
<<: *test
image: tetraweb/php:5.6
test:7.0:
<<: *PHP-UNITTESTING
<<: *test
image: tetraweb/php:7.0
test:7.1:
<<: *PHP-UNITTESTING
<<: *test
image: tetraweb/php:7.1
test:latest:
<<: *PHP-UNITTESTING
<<: *test
image: tetraweb/php:latest
......@@ -8,7 +8,7 @@ Composer plugin installs [PHP_CodeSniffer](https://github.com/squizlabs/PHP_Code
Requirements
------------
- `PHP >= 5.3.3`
- `PHP >= 5.4`
- Composer package providing the PHP CodeSniffer Rulesets & Sniffs
Installation
......
......@@ -17,6 +17,10 @@
"role": "Developer"
}
],
"support": {
"issues": "https://git.higidi.com/higidi/composer-phpcodesniffer-standards-plugin/issues",
"source": "https://git.higidi.com/higidi/composer-phpcodesniffer-standards-plugin"
},
"autoload": {
"psr-4": {
"Higidi\\ComposerPhpCSStandardsPlugin\\": "src/"
......@@ -24,10 +28,11 @@
},
"autoload-dev": {
"psr-4": {
"Higidi\\ComposerPhpCSStandardsPlugin\\Tests\\": "tests/src/"
"Higidi\\ComposerPhpCSStandardsPlugin\\Tests\\": "tests/"
}
},
"require": {
"php": "^5.4 || ^7.0",
"composer-plugin-api": "^1.1",
"squizlabs/php_codesniffer": "^2.0",
"symfony/finder": "^2.1 || ^3.0",
......@@ -35,7 +40,7 @@
},
"require-dev": {
"composer/composer": "^1.4",
"phpunit/phpunit": "^4.5 || ^5.0.5",
"phpunit/phpunit": "^4.8.36 || ^5.0.5",
"phpmd/phpmd": "^2.6"
},
"extra": {
......
......@@ -11,8 +11,11 @@
bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Project Test Suite">
<directory>./tests/src/</directory>
<testsuite name="Unit Tests">
<directory>./tests/Unit/</directory>
</testsuite>
<testsuite name="Integration Tests">
<directory>./tests/Integration/</directory>
</testsuite>
</testsuites>
......
......@@ -22,21 +22,26 @@ namespace Higidi\ComposerPhpCSStandardsPlugin;
*/
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Installer\BinaryInstaller;
use Composer\Installer\LibraryInstaller;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Util\Filesystem;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standard;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Finder;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Standard;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standards;
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
use Symfony\Component\Finder\Finder;
class Installer extends LibraryInstaller
{
const TYPE = 'phpcodesniffer-standard';
/**
* @var Finder
*/
protected $finder;
/**
* Initializes library installer.
*
......@@ -53,9 +58,11 @@ class Installer extends LibraryInstaller
Composer $composer,
$type = self::TYPE,
Filesystem $filesystem = null,
BinaryInstaller $binaryInstaller = null
BinaryInstaller $binaryInstaller = null,
Finder $finder = null
) {
parent::__construct($io, $composer, $type, $filesystem, $binaryInstaller);
$this->finder = $finder ?: new Finder();
}
/**
......@@ -63,15 +70,15 @@ class Installer extends LibraryInstaller
*/
public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
{
if (!parent::isInstalled($repo, $package)) {
if (! parent::isInstalled($repo, $package)) {
return false;
}
$sourceStandards = $this->getSourceStandards($package);
$destinationStandards = $this->getDestinationStandards($repo);
$srcStandards = $this->getSourceStandards($package);
$dstStandards = $this->getDestinationStandards($repo);
foreach ($sourceStandards as $sourceStandard) {
if (!$destinationStandards->hasStandard($sourceStandard)
|| !$this->compareStandards($sourceStandard, $destinationStandards->getStandard($sourceStandard))
foreach ($srcStandards as $srcStandard) {
if (! $dstStandards->hasStandard($srcStandard)
|| ! $this->compareStandards($srcStandard, $dstStandards->getStandard($srcStandard))
) {
return false;
}
......@@ -103,7 +110,7 @@ class Installer extends LibraryInstaller
*/
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
if (!$repo->hasPackage($package)) {
if (! $repo->hasPackage($package)) {
throw new \InvalidArgumentException('Package is not installed: ' . $package);
}
$this->removeStandards($repo, $package);
......@@ -114,7 +121,10 @@ class Installer extends LibraryInstaller
* @param InstalledRepositoryInterface $repo
* @param PackageInterface $package
* @param bool $override
*
* @return void
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
protected function installStandards(
InstalledRepositoryInterface $repo,
......@@ -122,35 +132,36 @@ class Installer extends LibraryInstaller
$override = false
) {
$filesystem = new SymfonyFilesystem();
$sourceStandards = $this->getSourceStandards($package);
$destStandardsBasePath = $this->getPHPCodeSnifferStandardsBasePath($repo);
$srcStandards = $this->getSourceStandards($package);
$dstStdBasePath = $this->getPHPCodeSnifferStandardsBasePath($repo);
$this->io->writeError(' Installing PHP-CodeSniffer Standards:', false);
foreach ($sourceStandards as $sourceStandard) {
$this->io->writeError(sprintf(' <info>%s</info>', $sourceStandard->getName()));
$sourcePath = $sourceStandard->getPath();
$destPath = $destStandardsBasePath . DIRECTORY_SEPARATOR . $sourceStandard->getName();
$filesystem->mirror($sourcePath, $destPath, null, array('override' => $override));
foreach ($srcStandards as $srcStandard) {
$this->io->writeError(sprintf(' <info>%s</info>', $srcStandard->getName()));
$srcPath = $srcStandard->getPath();
$dstPath = $dstStdBasePath . DIRECTORY_SEPARATOR . $srcStandard->getName();
$filesystem->mirror($srcPath, $dstPath, null, ['override' => $override]);
}
}
/**
* @param InstalledRepositoryInterface $repo
* @param PackageInterface $package
*
* @return void
*/
protected function removeStandards(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$sourceStandards = $this->getSourceStandards($package);
$destinationStandards = $this->getDestinationStandards($repo);
$srcStandards = $this->getSourceStandards($package);
$dstStandards = $this->getDestinationStandards($repo);
$this->io->writeError(' Removing PHP-CodeSniffer Standards:', false);
foreach ($sourceStandards as $sourceStandard) {
if (!$destinationStandards->hasStandard($sourceStandard)) {
foreach ($srcStandards as $srcStandard) {
if (! $dstStandards->hasStandard($srcStandard)) {
continue;
}
$this->io->writeError(sprintf(' <info>%s</info>', $sourceStandard->getName()));
$destinationStandard = $destinationStandards->getStandard($sourceStandard);
$this->io->writeError(sprintf(' <info>%s</info>', $srcStandard->getName()));
$dstStandard = $dstStandards->getStandard($srcStandard);
$this->filesystem->removeDirectory($destinationStandard->getPath());
$this->filesystem->removeDirectory($dstStandard->getPath());
}
}
......@@ -158,6 +169,7 @@ class Installer extends LibraryInstaller
* Get source (provided by the composer package) standards for package.
*
* @param PackageInterface $package
*
* @return Standards
*/
protected function getSourceStandards(PackageInterface $package)
......@@ -171,6 +183,7 @@ class Installer extends LibraryInstaller
* Get destination (provided by PHPCodeSniffer) standards.
*
* @param InstalledRepositoryInterface $repo
*
* @return Standards
*/
protected function getDestinationStandards(InstalledRepositoryInterface $repo)
......@@ -183,6 +196,7 @@ class Installer extends LibraryInstaller
/**
* @param Standard $source
* @param Standard $destination
*
* @return bool
*/
protected function compareStandards(Standard $source, Standard $destination)
......@@ -193,25 +207,17 @@ class Installer extends LibraryInstaller
/**
* @param string $basePath
*
* @return Standards
*/
protected function findStandards($basePath)
{
$standards = new Standards();
$finder = new Finder();
$finder
->in($basePath . '/**/Standards/*/')
->files()->name('ruleset.xml');
foreach ($finder as $ruleSetFile) {
$standard = new Standard($ruleSetFile->getPath());
$standards->addStandard($standard);
}
return $standards;
return $this->finder->in($basePath);
}
/**
* @param InstalledRepositoryInterface $repo
*
* @return string
*/
protected function getPHPCodeSnifferStandardsBasePath(InstalledRepositoryInterface $repo)
......@@ -224,13 +230,14 @@ class Installer extends LibraryInstaller
/**
* @param InstalledRepositoryInterface $repo
*
* @return PackageInterface
*/
protected function getPHPCodeSnifferPackage(InstalledRepositoryInterface $repo)
{
$packageKey = 'squizlabs/php_codesniffer';
$package = $repo->findPackage($packageKey, '*');
if (!$package) {
if (! $package) {
throw new \RuntimeException(sprintf('Package "%s" not installed.', $packageKey));
}
......@@ -239,6 +246,7 @@ class Installer extends LibraryInstaller
/**
* @param InstalledRepositoryInterface $repo
*
* @return string
*/
protected function getPHPCodeSnifferInstallPath(InstalledRepositoryInterface $repo)
......@@ -251,8 +259,8 @@ class Installer extends LibraryInstaller
*/
public function supports($packageType)
{
$secondaryTypes = array('phpcodesniffer-standards');
$deprecatedTypes = array('php-codesniffer-standards');
$secondaryTypes = ['phpcodesniffer-standards'];
$deprecatedTypes = ['php-codesniffer-standards'];
return parent::supports($packageType)
|| in_array($packageType, array_merge($secondaryTypes, $deprecatedTypes));
......
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Factory;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standards;
use Higidi\ComposerPhpCSStandardsPlugin\Symfony\Finder\Factory as FinderFactory;
use Symfony\Component\Finder\Finder as SymfonyFinder;
/**
* Standards finder class.
*/
class Finder
{
/**
* @var FinderFactory
*/
protected $finderFactory;
/**
* @var Factory
*/
protected $factory;
/**
* @param FinderFactory|null $finderFactory
* @param Factory|null $factory
*/
public function __construct(FinderFactory $finderFactory = null, Factory $factory = null)
{
$this->finderFactory = $finderFactory ?: new FinderFactory();
$this->factory = $factory ?: new Factory();
}
/**
* Find and return PHPCodeSniffer standards.
*
* @param string $path
*
* @return Standards
*
* @SuppressWarnings(PHPMD.ShortMethodName)
*/
public function in($path)
{
$finder = $this->getSymfonyFinder()
->in($path)
->files()
->name('ruleset.xml')
->sortByName();
$paths = iterator_to_array($finder, false);
$paths = array_map(
function (\SplFileInfo $file) {
return $file->getPath();
},
$paths
);
return $this->createStandardsFromPaths($paths);
}
/**
* Creates new symfony finder instance.
*
* @return SymfonyFinder
*/
protected function getSymfonyFinder()
{
return $this->finderFactory->create();
}
/**
* Creates PHPCodeSniffer standards from paths.
*
* @param array $path
*
* @return Standards
*/
protected function createStandardsFromPaths(array $paths)
{
return $this->factory->create($paths);
}
}
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer;
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
......@@ -21,58 +21,40 @@ namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer;
* 02110-1301, USA.
*/
class Standard
{
const RULESET_FILENAME = 'ruleset.xml';
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $path;
/**
* @var string
*/
protected $ruleSetXmlPath;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Factory as StandardFactory;
/**
* Standards class factory.
*/
class Factory
{
/**
* @param $path
* @var StandardFactory
*/
public function __construct($path)
{
$path = rtrim($path, DIRECTORY_SEPARATOR);
$pathParts = explode(DIRECTORY_SEPARATOR, $path);
$this->name = array_pop($pathParts);
$this->path = $path;
$this->ruleSetXmlPath = $path . DIRECTORY_SEPARATOR . 'ruleset.xml';
}
protected $standardFactory;
/**
* @return string
* @param StandardFactory|null $standardFactory
*/
public function getName()
public function __construct(StandardFactory $standardFactory = null)
{
return $this->name;
$this->standardFactory = $standardFactory ?: new StandardFactory();
}
/**
* @return string
* Creates PHPCodeSniffer standards from paths.
*
* @param array $paths Paths with PHPCodeSniffer standard paths.
*
* @return Standards PHPCodeSniffer standards object.
*/
public function getPath()
public function create(array $paths)
{
return $this->path;
}
$standards = new Standards();
foreach ($paths as $path) {
$standards->addStandard($this->standardFactory->create($path));
}
/**
* @return string
*/
public function getRuleSetXmlPath()
{
return $this->ruleSetXmlPath;
return $standards;
}
}
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Exception;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* Invalid standard exception.
*/
class InvalidStandardException extends \InvalidArgumentException
{
}
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Exception;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* Standard path access denied exception.
*/
class StandardPathAccessDeniedException extends \UnexpectedValueException
{
}
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* Standards class factory.
*/
class Factory
{
/**
* Creates PHPCodeSniffer standard from path.
*
* @param string $path Path to the PHPCodeSniffer standard.
*
* @return Standard PHPCodeSniffer standard object.
*/
public function create($path)
{
return new Standard($path);
}
}
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Exception\InvalidStandardException;
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\Exception\StandardPathAccessDeniedException;
/**
* Class for PHPCodeSniffer standards.
*/
class Standard implements StandardInterface
{
const RULESET_FILENAME = 'ruleset.xml';
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $path;
/**
* @var string
*/
protected $ruleSetXmlPath;
/**
* @param string $path
*/
public function __construct($path)
{
if (! is_readable($path)) {
throw new StandardPathAccessDeniedException(
sprintf('Standard path "%s" is not accessable.', $path)
);
}
$this->path = realpath($path);
$this->ruleSetXmlPath = $path . DIRECTORY_SEPARATOR . static::RULESET_FILENAME;
$this->name = $this->getNameFromRuleSet($this->ruleSetXmlPath);
if (! is_readable($this->ruleSetXmlPath)) {
throw new InvalidStandardException(
sprintf('Standard "%s" doesn\'t contain a "ruleset.xml" file.', $this->name)
);
}
}
/**
* Fetch PHPCodeSniffer standard name from ruleset.xml.
*
* @param string $ruleSetXmlPath The absolute path to ruleset.xml.
*
* @return string The name of the PHPCodeSniffer standard.
*/
protected function getNameFromRuleSet($ruleSetXmlPath)
{
try {
$ruleSet = new \SimpleXMLElement(file_get_contents($ruleSetXmlPath));
$name = trim($ruleSet->attributes()['name']);
if ($name !== '') {
return $name;
}
} catch (\Exception $e) {
// Nothing todo, use folder name.
}
return basename(dirname($ruleSetXmlPath));
}
/**
* Get the name of the PHPCodeSniffer standard.
*
* @return string The name of the PHPCodeSniffer standard.
*/
public function getName()
{
return $this->name;
}
/**
* Get the path to PHPCodeSniffer standard.
*
* @return string The path to the PHPCodeSniffer standard.
*/
public function getPath()
{
return $this->path;
}
/**
* Get the path to the PHPCodeSniffer ruleset.xml file.
*
* @return string The path to the PHPCodeSniffer ruleset.xml file.
*/
public function getRuleSetXmlPath()
{
return $this->ruleSetXmlPath;
}
}
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* Interface for PHPCodeSniffer standards.
*/
interface StandardInterface
{
/**
* Get the name of the PHPCodeSniffer standard.
*
* @return string The name of the PHPCodeSniffer standard.
*/
public function getName();
/**
* Get the path to PHPCodeSniffer standard.
*
* @return string The path to the PHPCodeSniffer standard.
*/
public function getPath();
/**
* Get the path to the PHPCodeSniffer ruleset.xml file.
*
* @return string The path to the PHPCodeSniffer ruleset.xml file.
*/
public function getRuleSetXmlPath();
}
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer;
namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
......@@ -21,29 +21,34 @@ namespace Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer;
* 02110-1301, USA.
*/
use Higidi\ComposerPhpCSStandardsPlugin\PHPCodeSniffer\Standards\Standard\StandardInterface;
/**
* Class holds a set of PHPCodeSniffer standards.
*/
class Standards implements \Iterator
{
/**
* @var array|Standard[]
* @var StandardInterface[]
*/
protected $standards;
/**
* @param array $standards
* @param StandardInterface[] $standards
*/
public function __construct(array $standards = array())
public function __construct(array $standards = [])
{
foreach ($standards as $standard) {
$this->addStandard($standard);
}
$this->setStandards($standards);
}
/**
* @param Standard $standard
* @return $this
* Add a single standard to set.
*
* @param StandardInterface $standard The standard to add
*
* @return $this Fluent interface
*/
public function addStandard(Standard $standard)
public function addStandard(StandardInterface $standard)
{
$this->standards[$standard->getName()] = $standard;
......@@ -51,8 +56,11 @@ class Standards implements \Iterator
}
/**
* @param string|Standard $standard
* @return bool
* Check whether set holds the given standard.
*
* @param string|StandardInterface $standard The standard to check
*
* @return bool True if sets hold the standard, otherwise false
*/
public function hasStandard($standard)
{
......@@ -60,8 +68,11 @@ class Standards implements \Iterator
}
/**
* @param string|Standard $standard
* @return $this
* Remove a single standard from the set.
*
* @param string|StandardInterface $standard The standard to remove
*
* @return $this Fluent interface
*/
public function removeStandard($standard)
{
......@@ -73,12 +84,15 @@ class Standards implements \Iterator
}
/**
* @param string|Standard $standard
* @return Standard|null
* Get a single standard.
*
* @param string|StandardInterface $standard The standard to get
*
* @return StandardInterface|null Return the standard or null if not exist
*/
public function getStandard($standard)
{
if (!$this->hasStandard($standard)) {
if (! $this->hasStandard($standard)) {
return null;
}
......@@ -86,20 +100,42 @@ class Standards implements \Iterator
}
/**
* @return array|Standard[]
* Get all standards hold by this set.
*
* @return array|StandardInterface[] Array of standards
*/
public function getStandards()
{
return $this->standards;
return array_values($this->standards);
}
/**
* @param string|Standard $standard
* @return string
* Set standards hold by this set.
*
* @param StandardInterface[] $standards Array with standards to set
*
* @return $this Fluent interface
*/
public function setStandards(array $standards)
{
$this->standards = [];
foreach ($standards as $standard) {
$this->addStandard($standard);
}
return $this;
}
/**
* Extract the name of the given standard.
*
* @param string|StandardInterface $standard The standard get name from
*
* @return string The standard name
*/
protected function getStandardName($standard)
{
if ($standard instanceof Standard) {
if ($standard instanceof StandardInterface) {
return $standard->getName();
}
......@@ -108,8 +144,9 @@ class Standards implements \Iterator
/**
* Return the current element
*
* @link http://php.net/manual/en/iterator.current.php
* @return Standard Can return any type.
* @return StandardInterface Can return any type.
* @since 5.0.0
*/
public function current()
......@@ -119,6 +156,7 @@ class Standards implements \Iterator
/**
* Move forward to next element
*
* @link http://php.net/manual/en/iterator.next.php
* @return void Any returned value is ignored.
* @since 5.0.0
......@@ -130,17 +168,21 @@ class Standards implements \Iterator
/**
* Return the key of the current element
*
* @link http://php.net/manual/en/iterator.key.php
* @return mixed scalar on success, or null on failure.
* @since 5.0.0
*/
public function key()
{
return key($this->standards);
$key = key($this->standards);
return array_search($key, array_keys($this->standards));
}
/**
* Checks if current position is valid
*
* @link http://php.net/manual/en/iterator.valid.php
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
......@@ -153,6 +195,7 @@ class Standards implements \Iterator
/**
* Rewind the Iterator to the first element
*
* @link http://php.net/manual/en/iterator.rewind.php
* @return void Any returned value is ignored.
* @since 5.0.0
......
......@@ -25,6 +25,9 @@ use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
/**
* Plugin class register our plugin with composer.
*/
class Plugin implements PluginInterface
{
/**
......
<?php
namespace Higidi\ComposerPhpCSStandardsPlugin\Symfony\Finder;
/*
* Copyright (C) 2017 Daniel Hürtgen <daniel@higidi.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Symfony\Component\Finder\Finder;
/**
* Symfony finder factory class.
*/
class Factory
{
/**
* Creates new symfony finder instance.
*
* @return Finder
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function create()
{
return Finder::create();
}
}
<?xml version="1.0"?>
<ruleset name="CustomStandard">
</ruleset>