Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

New coding standard #11

Merged
merged 10 commits into from
Apr 30, 2018
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
45 changes: 0 additions & 45 deletions .php_cs

This file was deleted.

15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ matrix:
include:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- CS_CHECK=true
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- TEST_COVERAGE=true
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
- PATH="$HOME/.local/bin:$PATH"
- php: 7
Expand All @@ -43,21 +43,20 @@ notifications:
email: false

before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs

script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi

after_success:
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi

after_script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ To do so:

## Running Coding Standards Checks

This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding
This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding
standards checks, and provides configuration for our selected checks.
`php-cs-fixer` is installed by default via Composer.
`phpcs` is installed by default via Composer.

To run checks only:

```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs
$ composer cs-check
```

To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run`
flag:
`phpcs` also includes a tool for fixing most CS violations, `phpcbf`:


```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs
$ composer cs-fix
```

If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure
If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.

## Recommended Workflow for Contributions
Expand Down
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "^4.8"
"phpunit/PHPUnit": "^4.8",
"zendframework/zend-coding-standard": "~1.0.0"
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"upload-coverage": "coveralls -v"
}
}
19 changes: 19 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>

<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>/src/Exception/*</exclude-pattern>
<exclude-pattern>/src/SplAutoloader.php</exclude-pattern>
<exclude-pattern>/src/AutoloaderFactory.php</exclude-pattern>
<exclude-pattern>/src/ClassMapAutoloader.php</exclude-pattern>
<exclude-pattern>/src/ModuleAutoloader.php</exclude-pattern>
<exclude-pattern>/src/StandardAutoloader.php</exclude-pattern>
</rule>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
<exclude-pattern>*/TestAsset/*</exclude-pattern>
<exclude-pattern>*/_files/*</exclude-pattern>
</ruleset>
16 changes: 8 additions & 8 deletions src/AutoloaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class AutoloaderFactory
public static function factory($options = null)
{
if (null === $options) {
if (!isset(static::$loaders[static::STANDARD_AUTOLOADER])) {
if (! isset(static::$loaders[static::STANDARD_AUTOLOADER])) {
$autoloader = static::getStandardAutoloader();
$autoloader->register();
static::$loaders[static::STANDARD_AUTOLOADER] = $autoloader;
Expand All @@ -69,24 +69,24 @@ public static function factory($options = null)
return;
}

if (!is_array($options) && !($options instanceof Traversable)) {
if (! is_array($options) && ! ($options instanceof Traversable)) {
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(
'Options provided must be an array or Traversable'
);
}

foreach ($options as $class => $autoloaderOptions) {
if (!isset(static::$loaders[$class])) {
if (! isset(static::$loaders[$class])) {
$autoloader = static::getStandardAutoloader();
if (!class_exists($class) && !$autoloader->autoload($class)) {
if (! class_exists($class) && ! $autoloader->autoload($class)) {
require_once 'Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(
sprintf('Autoloader class "%s" not loaded', $class)
);
}

if (!is_subclass_of($class, 'Zend\Loader\SplAutoloader')) {
if (! is_subclass_of($class, 'Zend\Loader\SplAutoloader')) {
require_once 'Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(
sprintf('Autoloader class %s must implement Zend\\Loader\\SplAutoloader', $class)
Expand Down Expand Up @@ -127,7 +127,7 @@ public static function getRegisteredAutoloaders()
*/
public static function getRegisteredAutoloader($class)
{
if (!isset(static::$loaders[$class])) {
if (! isset(static::$loaders[$class])) {
require_once 'Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(sprintf('Autoloader class "%s" not loaded', $class));
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public static function unregisterAutoloaders()
*/
public static function unregisterAutoloader($autoloaderClass)
{
if (!isset(static::$loaders[$autoloaderClass])) {
if (! isset(static::$loaders[$autoloaderClass])) {
return false;
}

Expand All @@ -182,7 +182,7 @@ protected static function getStandardAutoloader()
}


if (!class_exists(static::STANDARD_AUTOLOADER)) {
if (! class_exists(static::STANDARD_AUTOLOADER)) {
// Extract the filename from the classname
$stdAutoloader = substr(strrchr(static::STANDARD_AUTOLOADER, '\\'), 1);
require_once __DIR__ . "/$stdAutoloader.php";
Expand Down
12 changes: 6 additions & 6 deletions src/ClassMapAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function registerAutoloadMap($map)
}
}

if (!is_array($map)) {
if (! is_array($map)) {
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(sprintf(
'Map file provided does not return a map. Map file: "%s"',
Expand All @@ -109,7 +109,7 @@ public function registerAutoloadMap($map)
*/
public function registerAutoloadMaps($locations)
{
if (!is_array($locations) && !($locations instanceof Traversable)) {
if (! is_array($locations) && ! ($locations instanceof Traversable)) {
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException('Map list must be an array or implement Traversable');
}
Expand Down Expand Up @@ -166,15 +166,15 @@ public function register()
*/
protected function loadMapFromFile($location)
{
if (!file_exists($location)) {
if (! file_exists($location)) {
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(sprintf(
'Map file provided does not exist. Map file: "%s"',
(is_string($location) ? $location : 'unexpected type: ' . gettype($location))
));
}

if (!$path = static::realPharPath($location)) {
if (! $path = static::realPharPath($location)) {
$path = realpath($location);
}

Expand All @@ -197,7 +197,7 @@ protected function loadMapFromFile($location)
*/
public static function realPharPath($path)
{
if (!preg_match('|^phar:(/{2,3})|', $path, $match)) {
if (! preg_match('|^phar:(/{2,3})|', $path, $match)) {
return;
}

Expand All @@ -209,7 +209,7 @@ public static function realPharPath($path)

array_walk($parts, function ($value, $key) use (&$parts) {
if ($value === '..') {
unset($parts[$key], $parts[$key-1]);
unset($parts[$key], $parts[$key - 1]);
$parts = array_values($parts);
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/ModuleAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function autoload($class)
$path = $path . $moduleClassPath;

if ($path == '.' || substr($path, 0, 2) == './' || substr($path, 0, 2) == '.\\') {
if (!$basePath = $this->pharBasePath) {
if (! $basePath = $this->pharBasePath) {
$basePath = realpath('.');
}

Expand All @@ -216,7 +216,7 @@ public function autoload($class)
continue;
}

if (!preg_match('#.+\.' . $pharSuffixPattern . '$#', $entry->getPathname())) {
if (! preg_match('#.+\.' . $pharSuffixPattern . '$#', $entry->getPathname())) {
continue;
}

Expand Down Expand Up @@ -274,7 +274,7 @@ protected function loadModuleFromPhar($pharPath, $class)
{
$pharPath = static::normalizePath($pharPath, false);
$file = new SplFileInfo($pharPath);
if (!$file->isReadable() || !$file->isFile()) {
if (! $file->isReadable() || ! $file->isFile()) {
return false;
}

Expand Down Expand Up @@ -347,7 +347,7 @@ public function unregister()
*/
public function registerPaths($paths)
{
if (!is_array($paths) && !$paths instanceof Traversable) {
if (! is_array($paths) && ! $paths instanceof Traversable) {
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(
'Parameter to \\Zend\\Loader\\ModuleAutoloader\'s '
Expand Down Expand Up @@ -377,7 +377,7 @@ public function registerPaths($paths)
*/
public function registerPath($path, $moduleName = false)
{
if (!is_string($path)) {
if (! is_string($path)) {
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(sprintf(
'Invalid path provided; must be a string, received %s',
Expand Down
12 changes: 6 additions & 6 deletions src/PluginClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PluginClassLoader implements PluginClassLocator
public function __construct($map = null)
{
// Merge in static overrides
if (!empty(static::$staticMap)) {
if (! empty(static::$staticMap)) {
$this->registerPlugins(static::$staticMap);
}

Expand All @@ -64,7 +64,7 @@ public static function addStaticMap($map)
return;
}

if (!is_array($map) && !$map instanceof Traversable) {
if (! is_array($map) && ! $map instanceof Traversable) {
throw new Exception\InvalidArgumentException('Expects an array or Traversable object');
}
foreach ($map as $key => $value) {
Expand Down Expand Up @@ -105,15 +105,15 @@ public function registerPlugin($shortName, $className)
public function registerPlugins($map)
{
if (is_string($map)) {
if (!class_exists($map)) {
if (! class_exists($map)) {
throw new Exception\InvalidArgumentException('Map class provided is invalid');
}
$map = new $map;
}
if (is_array($map)) {
$map = new ArrayIterator($map);
}
if (!$map instanceof Traversable) {
if (! $map instanceof Traversable) {
throw new Exception\InvalidArgumentException('Map provided is invalid; must be traversable');
}

Expand All @@ -124,7 +124,7 @@ public function registerPlugins($map)

foreach ($map as $name => $class) {
if (is_int($name) || is_numeric($name)) {
if (!is_object($class) && class_exists($class)) {
if (! is_object($class) && class_exists($class)) {
$class = new $class();
}

Expand Down Expand Up @@ -196,7 +196,7 @@ public function getClassName($name)
*/
public function load($name)
{
if (!$this->isLoaded($name)) {
if (! $this->isLoaded($name)) {
return false;
}
return $this->plugins[strtolower($name)];
Expand Down
Loading