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

Commit

Permalink
Merge pull request #51 from Koopzington/new-coding-standard
Browse files Browse the repository at this point in the history
New coding standard
  • Loading branch information
Xerkus committed Mar 12, 2017
2 parents 2ab9a42 + b566f44 commit 8248e2e
Show file tree
Hide file tree
Showing 42 changed files with 178 additions and 161 deletions.
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 @@ -28,14 +28,14 @@ matrix:
include:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- CS_CHECK=true
- php: 5.5
env:
- EVENT_MANAGER_VERSION="^2.6.2"
- SERVICE_MANAGER_VERSION="^2.7.5"
- 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: 5.6
Expand All @@ -60,23 +60,22 @@ 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
- composer require --no-update "zendframework/zend-eventmanager:$EVENT_MANAGER_VERSION"
- composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION"

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 travis_retry curl -sSL https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh | bash ; 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 @@ -24,8 +24,8 @@
"zendframework/zend-loader": "^2.5",
"zendframework/zend-mvc": "^2.7",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
"phpunit/PHPUnit": "~4.0",
"zendframework/zend-coding-standard": "~1.0.0"
},
"suggest": {
"zendframework/zend-config": "Zend\\Config component",
Expand All @@ -46,5 +46,16 @@
"psr-4": {
"ZendTest\\ModuleManager\\": "test/"
}
},
"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"
}
}
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>
4 changes: 2 additions & 2 deletions src/Feature/ConsoleBannerProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ interface ConsoleBannerProviderInterface
* The banner is shown in the console window, when the user supplies invalid command-line parameters or invokes
* the application with no parameters.
*
* The method is called with active Zend\Console\Adapter\AdapterInterface that can be used to directly access Console and send
* output.
* The method is called with active Zend\Console\Adapter\AdapterInterface that can be used to directly access
* Console and send output.
*
* @param AdapterInterface $console
* @return string|null
Expand Down
4 changes: 2 additions & 2 deletions src/Listener/AutoloaderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class AutoloaderListener extends AbstractListener
public function __invoke(ModuleEvent $e)
{
$module = $e->getModule();
if (!$module instanceof AutoloaderProviderInterface
&& !method_exists($module, 'getAutoloaderConfig')
if (! $module instanceof AutoloaderProviderInterface
&& ! method_exists($module, 'getAutoloaderConfig')
) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Listener/ConfigListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public function onLoadModule(ModuleEvent $e)
{
$module = $e->getModule();

if (!$module instanceof ConfigProviderInterface
&& !is_callable([$module, 'getConfig'])
if (! $module instanceof ConfigProviderInterface
&& ! is_callable([$module, 'getConfig'])
) {
return $this;
}
Expand Down Expand Up @@ -274,7 +274,7 @@ protected function addConfigPaths($paths, $type)
$paths = ArrayUtils::iteratorToArray($paths);
}

if (!is_array($paths)) {
if (! is_array($paths)) {
throw new Exception\InvalidArgumentException(
sprintf(
'Argument passed to %::%s() must be an array, '
Expand Down Expand Up @@ -302,7 +302,7 @@ protected function addConfigPaths($paths, $type)
*/
protected function addConfigPath($path, $type)
{
if (!is_string($path)) {
if (! is_string($path)) {
throw new Exception\InvalidArgumentException(
sprintf(
'Parameter to %s::%s() must be a string; %s given.',
Expand All @@ -328,7 +328,7 @@ protected function addConfig($key, $config)
$config = ArrayUtils::iteratorToArray($config);
}

if (!is_array($config)) {
if (! is_array($config)) {
throw new Exception\InvalidArgumentException(
sprintf(
'Config being merged must be an array, '
Expand Down
8 changes: 6 additions & 2 deletions src/Listener/DefaultListenerAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public function attach(EventManagerInterface $events, $priority = 1)
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, new AutoloaderListener($options), 9000);

if ($options->getCheckDependencies()) {
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, new ModuleDependencyCheckerListener, 8000);
$this->listeners[] = $events->attach(
ModuleEvent::EVENT_LOAD_MODULE,
new ModuleDependencyCheckerListener,
8000
);
}

$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, new InitTrigger($options));
Expand Down Expand Up @@ -94,7 +98,7 @@ public function detach(EventManagerInterface $events)
*/
public function getConfigListener()
{
if (!$this->configListener instanceof ConfigMergerInterface) {
if (! $this->configListener instanceof ConfigMergerInterface) {
$this->setConfigListener(new ConfigListener($this->getOptions()));
}
return $this->configListener;
Expand Down
4 changes: 2 additions & 2 deletions src/Listener/InitTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class InitTrigger extends AbstractListener
public function __invoke(ModuleEvent $e)
{
$module = $e->getModule();
if (!$module instanceof InitProviderInterface
&& !method_exists($module, 'init')
if (! $module instanceof InitProviderInterface
&& ! method_exists($module, 'init')
) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Listener/ListenerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getModulePaths()
*/
public function setModulePaths($modulePaths)
{
if (!is_array($modulePaths) && !$modulePaths instanceof Traversable) {
if (! is_array($modulePaths) && ! $modulePaths instanceof Traversable) {
throw new Exception\InvalidArgumentException(
sprintf(
'Argument passed to %s::%s() must be an array, '
Expand Down Expand Up @@ -132,7 +132,7 @@ public function getConfigStaticPaths()
*/
public function setConfigGlobPaths($configGlobPaths)
{
if (!is_array($configGlobPaths) && !$configGlobPaths instanceof Traversable) {
if (! is_array($configGlobPaths) && ! $configGlobPaths instanceof Traversable) {
throw new Exception\InvalidArgumentException(
sprintf(
'Argument passed to %s::%s() must be an array, '
Expand All @@ -158,7 +158,7 @@ public function setConfigGlobPaths($configGlobPaths)
*/
public function setConfigStaticPaths($configStaticPaths)
{
if (!is_array($configStaticPaths) && !$configStaticPaths instanceof Traversable) {
if (! is_array($configStaticPaths) && ! $configStaticPaths instanceof Traversable) {
throw new Exception\InvalidArgumentException(
sprintf(
'Argument passed to %s::%s() must be an array, '
Expand Down Expand Up @@ -195,7 +195,7 @@ public function getExtraConfig()
*/
public function setExtraConfig($extraConfig)
{
if (!is_array($extraConfig) && !$extraConfig instanceof Traversable) {
if (! is_array($extraConfig) && ! $extraConfig instanceof Traversable) {
throw new Exception\InvalidArgumentException(
sprintf(
'Argument passed to %s::%s() must be an array, '
Expand Down
25 changes: 15 additions & 10 deletions src/Listener/LocatorRegistrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,21 @@ public function onLoadModules(ModuleEvent $e)
}

// Shared instance for module manager
$events->attach('Zend\Mvc\Application', ModuleManager::EVENT_BOOTSTRAP, function (MvcEvent $e) use ($moduleManager) {
$moduleClassName = get_class($moduleManager);
$moduleClassNameArray = explode('\\', $moduleClassName);
$moduleClassNameAlias = end($moduleClassNameArray);
$application = $e->getApplication();
$services = $application->getServiceManager();
if (! $services->has($moduleClassName)) {
$services->setAlias($moduleClassName, $moduleClassNameAlias);
}
}, 1000);
$events->attach(
'Zend\Mvc\Application',
ModuleManager::EVENT_BOOTSTRAP,
function (MvcEvent $e) use ($moduleManager) {
$moduleClassName = get_class($moduleManager);
$moduleClassNameArray = explode('\\', $moduleClassName);
$moduleClassNameAlias = end($moduleClassNameArray);
$application = $e->getApplication();
$services = $application->getServiceManager();
if (! $services->has($moduleClassName)) {
$services->setAlias($moduleClassName, $moduleClassNameAlias);
}
},
1000
);

if (0 === count($this->modules)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/ModuleDependencyCheckerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __invoke(ModuleEvent $e)
$dependencies = $module->getModuleDependencies();

foreach ($dependencies as $dependencyModule) {
if (!isset($this->loaded[$dependencyModule])) {
if (! isset($this->loaded[$dependencyModule])) {
throw new Exception\MissingDependencyModuleException(
sprintf(
'Module "%s" depends on module "%s", which was not initialized before it',
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/ModuleResolverListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __invoke(ModuleEvent $e)
$moduleName = $e->getModuleName();
$class = $moduleName . '\Module';

if (!class_exists($class)) {
if (! class_exists($class)) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Listener/OnBootstrapListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class OnBootstrapListener extends AbstractListener
public function __invoke(ModuleEvent $e)
{
$module = $e->getModule();
if (!$module instanceof BootstrapListenerInterface
&& !method_exists($module, 'onBootstrap')
if (! $module instanceof BootstrapListenerInterface
&& ! method_exists($module, 'onBootstrap')
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/ServiceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private function mergeServiceConfiguration($key, array $metadata, array $config)
{
if (isset($config[$metadata['config_key']])
&& is_array($config[$metadata['config_key']])
&& !empty($config[$metadata['config_key']])
&& ! empty($config[$metadata['config_key']])
) {
$this->serviceManagers[$key]['configuration']['merged_config'] = $config[$metadata['config_key']];
}
Expand Down
4 changes: 2 additions & 2 deletions src/ModuleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getModuleName()
*/
public function setModuleName($moduleName)
{
if (!is_string($moduleName)) {
if (! is_string($moduleName)) {
throw new Exception\InvalidArgumentException(
sprintf(
'%s expects a string as an argument; %s provided',
Expand Down Expand Up @@ -96,7 +96,7 @@ public function getModule()
*/
public function setModule($module)
{
if (!is_object($module)) {
if (! is_object($module)) {
throw new Exception\InvalidArgumentException(
sprintf(
'%s expects a module object as an argument; %s provided',
Expand Down
Loading

0 comments on commit 8248e2e

Please sign in to comment.