Skip to content

Commit

Permalink
Update php code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed May 1, 2019
1 parent 2206d2e commit 6d5cfd0
Show file tree
Hide file tree
Showing 78 changed files with 1,443 additions and 1,044 deletions.
14 changes: 12 additions & 2 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PHPUnit60Migration:risky' => true,
'array_syntax' => array('syntax' => 'long'),
'class_definition' => array('singleLine' => false),
'declare_strict_types' => false,
'ordered_imports' => true,
'php_unit_expectation' => false,
'php_unit_no_expectation_annotation' => false,
'php_unit_strict' => false,
'php_unit_test_class_requires_covers' => false,
'self_accessor' => false,
'single_line_comment_style' => false,
))
->setRiskyAllowed(true)
->setFinder(
Expand Down
4 changes: 2 additions & 2 deletions Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class Assets
*
* @param string $type
*
* @return AssetTypeInterface
*
* @throws InvalidArgumentException When the asset type does not exist
*
* @return AssetTypeInterface
*/
public static function createType($type)
{
Expand Down
4 changes: 2 additions & 2 deletions Composer/ScriptHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected static function getIgnoreConfigSection()
*
* @param OperationInterface $operation The operation
*
* @return PackageInterface|null Return NULL if the package is an asset
* @return null|PackageInterface Return NULL if the package is an asset
*/
protected static function getLibraryPackage(OperationInterface $operation)
{
Expand All @@ -97,7 +97,7 @@ protected static function getLibraryPackage(OperationInterface $operation)
*
* @param OperationInterface $operation The operation
*
* @return PackageInterface|null Return NULL if the operation is not INSTALL or UPDATE
* @return null|PackageInterface Return NULL if the operation is not INSTALL or UPDATE
*/
protected static function getOperationPackage(OperationInterface $operation)
{
Expand Down
25 changes: 12 additions & 13 deletions Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,23 @@ public function getArray($key, array $default = array())
* Get the config value.
*
* @param string $key The config key
* @param mixed|null $default The default value
* @param null|mixed $default The default value
*
* @return mixed|null
* @return null|mixed
*/
public function get($key, $default = null)
{
if (array_key_exists($key, $this->cacheEnv)) {
if (\array_key_exists($key, $this->cacheEnv)) {
return $this->cacheEnv[$key];
} else {
$envKey = $this->convertEnvKey($key);
$envValue = getenv($envKey);
}
$envKey = $this->convertEnvKey($key);
$envValue = getenv($envKey);

if (false !== $envValue) {
return $this->cacheEnv[$key] = $this->convertEnvValue($envValue, $envKey);
}
if (false !== $envValue) {
return $this->cacheEnv[$key] = $this->convertEnvValue($envValue, $envKey);
}

return array_key_exists($key, $this->config)
return \array_key_exists($key, $this->config)
? $this->config[$key]
: $default;
}
Expand All @@ -97,7 +96,7 @@ private function convertEnvKey($key)
* @param string $value The value of environment variable
* @param string $environmentVariable The environment variable name
*
* @return string|bool|int|array
* @return array|bool|int|string
*/
private function convertEnvValue($value, $environmentVariable)
{
Expand Down Expand Up @@ -125,7 +124,7 @@ private function isBoolean($value)
{
$value = strtolower($value);

return in_array($value, array('true', 'false', '1', '0', 'yes', 'no', 'y', 'n'), true);
return \in_array($value, array('true', 'false', '1', '0', 'yes', 'no', 'y', 'n'), true);
}

/**
Expand All @@ -137,7 +136,7 @@ private function isBoolean($value)
*/
private function convertBoolean($value)
{
return in_array($value, array('true', '1', 'yes', 'y'), true);
return \in_array($value, array('true', '1', 'yes', 'y'), true);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ abstract class ConfigBuilder
*/
public static function validate(IOInterface $io, RootPackageInterface $package, $commandName = null)
{
if (null === $commandName || in_array($commandName, array('install', 'update', 'validate', 'require', 'remove'))) {
if (null === $commandName || \in_array($commandName, array('install', 'update', 'validate', 'require', 'remove'), true)) {
$extra = (array) $package->getExtra();

foreach (self::$deprecatedOptions as $new => $old) {
if (array_key_exists($old, $extra)) {
if (\array_key_exists($old, $extra)) {
$io->write(sprintf('<warning>The "extra.%s" option is deprecated, use the "config.fxp-asset.%s" option</warning>', $old, $new));
}
}
Expand All @@ -65,7 +65,7 @@ public static function validate(IOInterface $io, RootPackageInterface $package,
* Build the config of plugin.
*
* @param Composer $composer The composer
* @param IOInterface|null $io The composer input/output
* @param null|IOInterface $io The composer input/output
*
* @return Config
*/
Expand All @@ -88,7 +88,7 @@ public static function build(Composer $composer, $io = null)
private static function injectDeprecatedConfig(array $config, array $extra)
{
foreach (self::$deprecatedOptions as $key => $deprecatedKey) {
if (array_key_exists($deprecatedKey, $extra) && !array_key_exists($key, $config)) {
if (\array_key_exists($deprecatedKey, $extra) && !\array_key_exists($key, $config)) {
$config[$key] = $extra[$deprecatedKey];
}
}
Expand All @@ -100,7 +100,7 @@ private static function injectDeprecatedConfig(array $config, array $extra)
* Get the base of data.
*
* @param Composer $composer The composer
* @param IOInterface|null $io The composer input/output
* @param null|IOInterface $io The composer input/output
*
* @return array
*/
Expand All @@ -109,7 +109,7 @@ private static function getConfigBase(Composer $composer, $io = null)
$globalPackageConfig = self::getGlobalConfig($composer, 'composer', $io);
$globalConfig = self::getGlobalConfig($composer, 'config', $io);
$packageConfig = $composer->getPackage()->getConfig();
$packageConfig = isset($packageConfig['fxp-asset']) && is_array($packageConfig['fxp-asset'])
$packageConfig = isset($packageConfig['fxp-asset']) && \is_array($packageConfig['fxp-asset'])
? $packageConfig['fxp-asset']
: array();

Expand All @@ -121,7 +121,7 @@ private static function getConfigBase(Composer $composer, $io = null)
*
* @param Composer $composer The composer
* @param string $filename The filename
* @param IOInterface|null $io The composer input/output
* @param null|IOInterface $io The composer input/output
*
* @return array
*/
Expand All @@ -134,7 +134,7 @@ private static function getGlobalConfig(Composer $composer, $filename, $io = nul
if ($file->exists()) {
$data = $file->read();

if (isset($data['config']['fxp-asset']) && is_array($data['config']['fxp-asset'])) {
if (isset($data['config']['fxp-asset']) && \is_array($data['config']['fxp-asset'])) {
$config = $data['config']['fxp-asset'];

if ($io instanceof IOInterface && $io->isDebug()) {
Expand Down
10 changes: 5 additions & 5 deletions Converter/AbstractPackageConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ protected function convertData(array $asset, array $keys, array $dependencies, a
* @param array $asset The asset data
* @param string $assetKey The asset key
* @param array $composer The composer data
* @param string|array $composerKey The composer key or array with composer key name and closure
* @param array|string $composerKey The composer key or array with composer key name and closure
*
* @throws InvalidArgumentException When the 'composerKey' argument of asset packager converter is not an string or an array with the composer key and closure
*/
protected function convertKey(array $asset, $assetKey, array &$composer, $composerKey)
{
if (is_array($composerKey)) {
if (\is_array($composerKey)) {
PackageUtil::convertArrayKey($asset, $assetKey, $composer, $composerKey);
} else {
PackageUtil::convertStringKey($asset, $assetKey, $composer, $composerKey);
Expand All @@ -103,7 +103,7 @@ protected function convertKey(array $asset, $assetKey, array &$composer, $compos
* @param array $asset The asset data
* @param string $assetKey The asset extra key
* @param array $composer The composer data
* @param string|array $composerKey The composer extra key or array with composer extra key name and closure
* @param array|string $composerKey The composer extra key or array with composer extra key name and closure
* @param string $extraKey The extra key name
*/
protected function convertExtraKey(array $asset, $assetKey, array &$composer, $composerKey, $extraKey = 'extra')
Expand All @@ -112,7 +112,7 @@ protected function convertExtraKey(array $asset, $assetKey, array &$composer, $c

$this->convertKey($asset, $assetKey, $extra, $composerKey);

if (count($extra) > 0) {
if (\count($extra) > 0) {
$composer[$extraKey] = $extra;
}
}
Expand All @@ -128,7 +128,7 @@ protected function convertExtraKey(array $asset, $assetKey, array &$composer, $c
*/
protected function convertDependencies(array $asset, $assetKey, array &$composer, $composerKey, array &$vcsRepos = array())
{
if (isset($asset[$assetKey]) && is_array($asset[$assetKey])) {
if (isset($asset[$assetKey]) && \is_array($asset[$assetKey])) {
$newDependencies = array();

foreach ($asset[$assetKey] as $dependency => $version) {
Expand Down
2 changes: 1 addition & 1 deletion Converter/BowerPackageConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function checkGithubRepositoryVersion($dependency, $version)
{
if (preg_match('/^[A-Za-z0-9\-_]+\/[A-Za-z0-9\-_.]+/', $version)) {
$pos = strpos($version, '#');
$pos = false === $pos ? strlen($version) : $pos;
$pos = false === $pos ? \strlen($version) : $pos;
$realVersion = substr($version, $pos);
$version = 'git://github.com/'.substr($version, 0, $pos).'.git'.$realVersion;
}
Expand Down
26 changes: 13 additions & 13 deletions Converter/NpmPackageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public static function revertName($name)
*/
public static function convertLicenses($licenses)
{
if (!is_array($licenses)) {
if (!\is_array($licenses)) {
return $licenses;
}

$result = array();
foreach ($licenses as $license) {
if (is_array($license)) {
if (\is_array($license)) {
if (!empty($license['type'])) {
$result[] = $license['type'];
} elseif (!empty($license['name'])) {
Expand All @@ -82,7 +82,7 @@ public static function convertLicenses($licenses)
/**
* Convert the author section.
*
* @param string|null $value The current value
* @param null|string $value The current value
*
* @return array
*/
Expand All @@ -98,17 +98,17 @@ public static function convertAuthor($value)
/**
* Convert the contributors section.
*
* @param string|null $value The current value
* @param string|null $prevValue The previous value
* @param null|string $value The current value
* @param null|string $prevValue The previous value
*
* @return array
*/
public static function convertContributors($value, $prevValue)
{
$mergeValue = is_array($prevValue) ? $prevValue : array();
$mergeValue = array_merge($mergeValue, is_array($value) ? $value : array());
$mergeValue = \is_array($prevValue) ? $prevValue : array();
$mergeValue = array_merge($mergeValue, \is_array($value) ? $value : array());

if (count($mergeValue) > 0) {
if (\count($mergeValue) > 0) {
$value = $mergeValue;
}

Expand All @@ -118,18 +118,18 @@ public static function convertContributors($value, $prevValue)
/**
* Convert the dist section.
*
* @param string|null $value The current value
* @param null|string $value The current value
*
* @return array
*/
public static function convertDist($value)
{
if (is_array($value)) {
if (\is_array($value)) {
$data = (array) $value;
$value = array();

foreach ($data as $type => $url) {
if (is_string($url)) {
if (\is_string($url)) {
self::convertDistEntry($value, $type, $url);
}
}
Expand All @@ -150,15 +150,15 @@ private static function convertDistEntry(array &$value, $type, $url)
$httpPrefix = 'http://';

if (0 === strpos($url, $httpPrefix)) {
$url = 'https://'.substr($url, strlen($httpPrefix));
$url = 'https://'.substr($url, \strlen($httpPrefix));
}

if ('shasum' === $type) {
$value[$type] = $url;
} elseif ('tarball' === $type) {
$value['type'] = 'tar';
$value['url'] = $url;
} elseif (in_array($type, self::getDownloaderTypes(), true)) {
} elseif (\in_array($type, self::getDownloaderTypes(), true)) {
$value['type'] = $type;
$value['url'] = $url;
}
Expand Down
10 changes: 5 additions & 5 deletions Converter/PackageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function isUrlArchive($url)
{
if (0 === strpos($url, 'http')) {
foreach (self::$extensions as $extension) {
if (substr($url, -strlen($extension)) === $extension) {
if (substr($url, -\strlen($extension)) === $extension) {
return true;
}
}
Expand Down Expand Up @@ -182,8 +182,8 @@ public static function convertStringKey(array $asset, $assetKey, array &$compose
*/
public static function convertArrayKey(array $asset, $assetKey, array &$composer, $composerKey)
{
if (2 !== count($composerKey)
|| !is_string($composerKey[0]) || !$composerKey[1] instanceof \Closure) {
if (2 !== \count($composerKey)
|| !\is_string($composerKey[0]) || !$composerKey[1] instanceof \Closure) {
throw new InvalidArgumentException('The "composerKey" argument of asset packager converter must be an string or an array with the composer key and closure');
}

Expand Down Expand Up @@ -233,7 +233,7 @@ protected static function splitUrlVersion($version)
protected static function getUrlFileDependencyName(AssetTypeInterface $assetType, array $composer, $dependency)
{
$prefix = isset($composer['name'])
? substr($composer['name'], strlen($assetType->getComposerVendorName()) + 1).'-'
? substr($composer['name'], \strlen($assetType->getComposerVendorName()) + 1).'-'
: '';

return $prefix.$dependency.'-file';
Expand Down Expand Up @@ -273,7 +273,7 @@ protected static function hasUrlDependencySupported($url)
$io = new NullIO();
$config = new Config();

/* @var VcsDriverInterface $driver */
/** @var VcsDriverInterface $driver */
foreach (Assets::getVcsDrivers() as $driver) {
$supported = $driver::supports($io, $config, $url);

Expand Down
Loading

0 comments on commit 6d5cfd0

Please sign in to comment.