Skip to content

Commit

Permalink
qa: apply CS rules
Browse files Browse the repository at this point in the history
Applies CS rules, and ensures psalm tests pass following changes.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
  • Loading branch information
weierophinney committed Jun 7, 2021
1 parent 3a0f6f8 commit a9da9c5
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 276 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.phpcs-cache
/.phpunit.result.cache
/clover.xml
/coveralls-upload.json
Expand Down
12 changes: 5 additions & 7 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration;
Expand All @@ -19,13 +17,13 @@
// manipulated by the ConfigWriter should use ::class notation
// 'class_name_scalars' => true,
],
'service_manager' => [
'service_manager' => [
// Legacy Zend Framework aliases
'aliases' => [
\ZF\Configuration\ConfigResource::class => ConfigResource::class,
'aliases' => [
\ZF\Configuration\ConfigResource::class => ConfigResource::class,
\ZF\Configuration\ConfigResourceFactory::class => ConfigResourceFactory::class,
\ZF\Configuration\ConfigWriter::class => ConfigWriter::class,
\ZF\Configuration\ModuleUtils::class => ModuleUtils::class,
\ZF\Configuration\ConfigWriter::class => ConfigWriter::class,
\ZF\Configuration\ModuleUtils::class => ModuleUtils::class,
],
'factories' => [
ConfigResource::class => Factory\ConfigResourceFactory::class,
Expand Down
40 changes: 22 additions & 18 deletions src/ConfigResource.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration;

use Laminas\Config\Writer\WriterInterface as ConfigWriter;
use Laminas\Stdlib\ArrayUtils;
use stdClass;
use Traversable;

use function array_key_exists;
use function array_merge;
use function array_shift;
use function explode;
use function file_exists;
use function function_exists;
use function get_class;
use function gettype;
use function ini_get;
use function is_array;
use function is_object;
use function opcache_invalidate;
use function sprintf;

class ConfigResource
{
/**
* @var array
*/
/** @var array */
protected $config;

/**
Expand All @@ -34,15 +40,12 @@ class ConfigResource
*/
protected $opcacheEnabled = false;

/**
* @var ConfigWriter
*/
/** @var ConfigWriter */
protected $writer;

/**
* @param array $config
* @param string $fileName
* @param ConfigWriter $writer
*/
public function __construct(array $config, $fileName, ConfigWriter $writer)
{
Expand Down Expand Up @@ -202,7 +205,8 @@ public function replaceKey($keys, $value, array $config)

// If key does not exist, or the current value is not an associative
// array, create nested set and return
if (! isset($config[$key])
if (
! isset($config[$key])
|| ! ArrayUtils::isHashTable($config[$key])
) {
$config[$key] = $this->replaceKey($keys, $value, []);
Expand Down Expand Up @@ -262,9 +266,9 @@ public function traverseArray(array $array, $currentKey = '')
{
$flattened = [];
foreach ($array as $key => $value) {
$targetKey = ('' === $currentKey) ? $key : $currentKey . '.' . $key;
$targetKey = '' === $currentKey ? $key : $currentKey . '.' . $key;
if (is_array($value)) {
$value = $this->traverseArray($value, $targetKey);
$value = $this->traverseArray($value, $targetKey);
$flattened = array_merge($flattened, $value);
continue;
}
Expand All @@ -291,7 +295,7 @@ public function createNestedKeyValuePair(&$patchValues, $key, $value)
throw new Exception\InvalidArgumentException(sprintf(
'%s expects the $patchValues argument to be an array; received %s',
__METHOD__,
(is_object($patchValues) ? get_class($patchValues) : gettype($patchValues))
is_object($patchValues) ? get_class($patchValues) : gettype($patchValues)
));
}

Expand All @@ -312,7 +316,7 @@ protected function extractAndSet(array $keys, $value, &$array): void
if (! isset($array[$key]) || ! is_array($array[$key])) {
$array[$key] = [];
}
$reference = &$array[$key];
$reference = &$array[$key];
$this->extractAndSet($keys, $value, $reference);
return;
}
Expand Down
6 changes: 0 additions & 6 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration\Exception;

interface ExceptionInterface
Expand Down
6 changes: 0 additions & 6 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
Expand Down
6 changes: 0 additions & 6 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration\Exception;

class RuntimeException extends \RuntimeException implements ExceptionInterface
Expand Down
11 changes: 2 additions & 9 deletions src/Factory/ConfigResourceFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration\Factory;

use Interop\Container\ContainerInterface;
Expand All @@ -16,14 +10,14 @@ class ConfigResourceFactory
{
/**
* Default configuration file to use.
* @param string
*
* @var string
*/
private $defaultConfigFile = 'config/autoload/development.php';

/**
* Create and return a ConfigResource.
*
* @param ContainerInterface $container
* @return ConfigResource
*/
public function __invoke(ContainerInterface $container)
Expand All @@ -40,7 +34,6 @@ public function __invoke(ContainerInterface $container)
/**
* Fetch configuration from the container, if possible.
*
* @param ContainerInterface $container
* @return array
*/
private function fetchConfig(ContainerInterface $container)
Expand Down
8 changes: 0 additions & 8 deletions src/Factory/ConfigWriterFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration\Factory;

use Interop\Container\ContainerInterface;
Expand All @@ -16,7 +10,6 @@ class ConfigWriterFactory
/**
* Create and return a PhpArray config writer.
*
* @param ContainerInterface $container
* @return PhpArray
*/
public function __invoke(ContainerInterface $container)
Expand All @@ -37,7 +30,6 @@ public function __invoke(ContainerInterface $container)
/**
* Discover the $key flag from configuration, if present.
*
* @param ContainerInterface $container
* @param string $key
* @return bool
*/
Expand Down
7 changes: 0 additions & 7 deletions src/Factory/ModuleUtilsFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration\Factory;

use Interop\Container\ContainerInterface;
Expand All @@ -14,7 +8,6 @@
class ModuleUtilsFactory
{
/**
* @param ContainerInterface $container
* @return ModuleUtils
*/
public function __invoke(ContainerInterface $container)
Expand Down
7 changes: 0 additions & 7 deletions src/Factory/ResourceFactoryFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration\Factory;

use Interop\Container\ContainerInterface;
Expand All @@ -16,7 +10,6 @@
class ResourceFactoryFactory
{
/**
* @param ContainerInterface $container
* @return ResourceFactory
*/
public function __invoke(ContainerInterface $container)
Expand Down
6 changes: 0 additions & 6 deletions src/Module.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration;

/**
Expand Down
49 changes: 25 additions & 24 deletions src/ModuleUtils.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?php

/**
* @see https://github.com/laminas-api-tools/api-tools-configuration for the canonical source repository
* @copyright https://github.com/laminas-api-tools/api-tools-configuration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas-api-tools/api-tools-configuration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\ApiTools\Configuration;

use Laminas\ModuleManager\ModuleManager;
use ReflectionObject;

use function array_key_exists;
use function dirname;
use function file_exists;
use function in_array;
use function is_dir;
use function preg_match;
use function sprintf;
use function str_replace;
use function strtoupper;
use function substr;

use const PHP_OS;

class ModuleUtils
{
/**
* @var array
*/
/** @var array */
protected $modules = [];

/**
* @var array
*/
/** @var array */
protected $moduleData = [];

/**
* @param ModuleManager $modules
*/
public function __construct(ModuleManager $modules)
{
$this->modules = $modules->getLoadedModules();
Expand All @@ -36,8 +36,8 @@ public function __construct(ModuleManager $modules)
*
* @param string $moduleName
* @return string
* @throws Exception\InvalidArgumentException if module does not exist
* @throws Exception\RuntimeException if unable to locate module path
* @throws Exception\InvalidArgumentException If module does not exist.
* @throws Exception\RuntimeException If unable to locate module path.
*/
public function getModulePath($moduleName)
{
Expand All @@ -57,8 +57,8 @@ public function getModulePath($moduleName)
*
* @param string $moduleName
* @return string
* @throws Exception\InvalidArgumentException if module does not exist
* @throws Exception\RuntimeException if unable to locate config path
* @throws Exception\InvalidArgumentException If module does not exist.
* @throws Exception\RuntimeException If unable to locate config path.
*/
public function getModuleConfigPath($moduleName)
{
Expand All @@ -76,7 +76,7 @@ public function getModuleConfigPath($moduleName)
/**
* Validate that the module actually exists
*
* @throws Exception\InvalidArgumentException if the module does not exist
* @throws Exception\InvalidArgumentException If the module does not exist.
*/
protected function validateModule(string $moduleName): void
{
Expand All @@ -93,8 +93,8 @@ protected function validateModule(string $moduleName): void
*/
protected function deriveModuleData(string $moduleName): void
{
$configPath = $this->deriveModuleConfig($moduleName);
$modulePath = dirname(dirname($configPath));
$configPath = $this->deriveModuleConfig($moduleName);
$modulePath = dirname(dirname($configPath));
$this->moduleData[$moduleName] = [
'config' => $configPath,
'path' => $modulePath,
Expand All @@ -104,7 +104,7 @@ protected function deriveModuleData(string $moduleName): void
/**
* Determines the location of the module configuration file
*
* @throws Exception\RuntimeException if unable to find the configuration file
* @throws Exception\RuntimeException If unable to find the configuration file.
*/
protected function deriveModuleConfig(string $moduleName): string
{
Expand Down Expand Up @@ -147,7 +147,8 @@ protected function recurseTree(string $path)
return $path . '/config/module.config.php';
}

if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN'
if (
strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN'
&& (in_array($path, ['.', '/', '\\\\', '\\'])
|| preg_match('#[a-z]:(\\\\|/{1,2})$#i', $path))
) {
Expand Down
Loading

0 comments on commit a9da9c5

Please sign in to comment.