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 9de83f9 commit fbaf7e4
Show file tree
Hide file tree
Showing 34 changed files with 419 additions and 277 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
17 changes: 9 additions & 8 deletions Asset/AbstractAssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\VersionParser;
use Composer\Util\Filesystem;
use Composer\Util\ProcessExecutor;
use Composer\Util\Platform;
use Composer\Util\ProcessExecutor;
use Foxy\Config\Config;
use Foxy\Exception\RuntimeException;
use Foxy\Fallback\FallbackInterface;
Expand Down Expand Up @@ -53,7 +53,7 @@ abstract class AbstractAssetManager implements AssetManagerInterface
protected $fs;

/**
* @var FallbackInterface|null
* @var null|FallbackInterface
*/
protected $fallback;

Expand All @@ -71,12 +71,13 @@ abstract class AbstractAssetManager implements AssetManagerInterface
* @param Filesystem $fs The filesystem
* @param FallbackInterface $fallback The asset fallback
*/
public function __construct(IOInterface $io,
Config $config,
ProcessExecutor $executor,
Filesystem $fs,
FallbackInterface $fallback = null)
{
public function __construct(
IOInterface $io,
Config $config,
ProcessExecutor $executor,
Filesystem $fs,
FallbackInterface $fallback = null
) {
$this->io = $io;
$this->config = $config;
$this->executor = $executor;
Expand Down
24 changes: 12 additions & 12 deletions Asset/YarnManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,42 @@ public function getLockPackageName()
/**
* {@inheritdoc}
*/
protected function getVersionCommand()
public function isInstalled()
{
return $this->buildCommand('yarn', 'version', '--version');
return parent::isInstalled() && file_exists($this->getLockPackageName());
}

/**
* {@inheritdoc}
*/
protected function getInstallCommand()
public function isValidForUpdate()
{
return $this->buildCommand('yarn', 'install', 'install --non-interactive');
$cmd = $this->buildCommand('yarn', 'check', 'check --non-interactive');

return 0 === $this->executor->execute($cmd);
}

/**
* {@inheritdoc}
*/
protected function getUpdateCommand()
protected function getVersionCommand()
{
return $this->buildCommand('yarn', 'update', 'upgrade --non-interactive');
return $this->buildCommand('yarn', 'version', '--version');
}

/**
* {@inheritdoc}
*/
public function isInstalled()
protected function getInstallCommand()
{
return parent::isInstalled() && file_exists($this->getLockPackageName());
return $this->buildCommand('yarn', 'install', 'install --non-interactive');
}

/**
* {@inheritdoc}
*/
public function isValidForUpdate()
protected function getUpdateCommand()
{
$cmd = $this->buildCommand('yarn', 'check', 'check --non-interactive');

return 0 === $this->executor->execute($cmd);
return $this->buildCommand('yarn', 'update', 'upgrade --non-interactive');
}
}
14 changes: 7 additions & 7 deletions Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ 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)
{
Expand Down Expand Up @@ -108,7 +108,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 @@ -210,9 +210,9 @@ private function convertJson($value, $environmentVariable)
* Get the configured default value or custom default 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
*/
private function getDefaultValue($key, $default = null)
{
Expand All @@ -228,9 +228,9 @@ private function getDefaultValue($key, $default = null)
*
* @param string $key The config key
* @param array|mixed $value The value
* @param mixed|null $default The default value
* @param null|mixed $default The default value
*
* @return mixed|null
* @return null|mixed
*/
private function getByManager($key, $value, $default = null)
{
Expand Down
6 changes: 3 additions & 3 deletions Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class ConfigBuilder
*
* @param Composer $composer The composer
* @param array $defaults The default values
* @param IOInterface|null $io The composer input/output
* @param null|IOInterface $io The composer input/output
*
* @return Config
*/
Expand All @@ -42,7 +42,7 @@ public static function build(Composer $composer, array $defaults = array(), $io
* 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 @@ -63,7 +63,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 Down
2 changes: 1 addition & 1 deletion Fallback/AssetFallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AssetFallback implements FallbackInterface
protected $fs;

/**
* @var string|null
* @var null|string
*/
protected $originalContent;

Expand Down
25 changes: 13 additions & 12 deletions Fallback/ComposerFallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ComposerFallback implements FallbackInterface
protected $fs;

/**
* @var Installer|null
* @var null|Installer
*/
protected $installer;

Expand All @@ -72,16 +72,17 @@ class ComposerFallback implements FallbackInterface
* @param IOInterface $io The IO
* @param Config $config The config
* @param InputInterface $input The input
* @param Filesystem|null $fs The composer filesystem
* @param Installer|null $installer The installer
* @param null|Filesystem $fs The composer filesystem
* @param null|Installer $installer The installer
*/
public function __construct(Composer $composer,
IOInterface $io,
Config $config,
InputInterface $input,
Filesystem $fs = null,
Installer $installer = null)
{
public function __construct(
Composer $composer,
IOInterface $io,
Config $config,
InputInterface $input,
Filesystem $fs = null,
Installer $installer = null
) {
$this->composer = $composer;
$this->io = $io;
$this->config = $config;
Expand Down Expand Up @@ -184,9 +185,9 @@ protected function restorePreviousLockFile()
* Get the lock value.
*
* @param string $key The key
* @param mixed|null $default The default value
* @param null|mixed $default The default value
*
* @return mixed|null
* @return null|mixed
*/
private function getLockValue($key, $default = null)
{
Expand Down
14 changes: 7 additions & 7 deletions Foxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Foxy implements PluginInterface, EventSubscriberInterface
{
const REQUIRED_COMPOSER_VERSION = '1.5.0';

/**
* @var SolverInterface
*/
protected $solver;

/**
* The list of the classes of asset managers.
*/
Expand Down Expand Up @@ -69,11 +74,6 @@ class Foxy implements PluginInterface, EventSubscriberInterface
'enable-packages' => array(),
);

/**
* @var SolverInterface
*/
protected $solver;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -142,9 +142,9 @@ public function solveAssets(Event $event)
* @param ProcessExecutor $executor The process executor
* @param Filesystem $fs The composer filesystem
*
* @return AssetManagerInterface
*
* @throws RuntimeException When the asset manager is not found
*
* @return AssetManagerInterface
*/
protected function getAssetManager(IOInterface $io, Config $config, ProcessExecutor $executor, Filesystem $fs)
{
Expand Down
20 changes: 10 additions & 10 deletions Json/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ public function write(array $hash, $options = 448)
self::$encodeIndent = JsonFormatter::DEFAULT_INDENT;
}

/**
* Parse the original content.
*/
private function parseOriginalContent()
{
$content = $this->exists() ? file_get_contents($this->getPath()) : '';
$this->arrayKeys = JsonFormatter::getArrayKeys($content);
$this->indent = JsonFormatter::getIndent($content);
}

/**
* {@inheritdoc}
*/
Expand All @@ -111,4 +101,14 @@ public static function encode($data, $options = 448)

return JsonFormatter::format($result, self::$encodeArrayKeys, self::$encodeIndent, false);
}

/**
* Parse the original content.
*/
private function parseOriginalContent()
{
$content = $this->exists() ? file_get_contents($this->getPath()) : '';
$this->arrayKeys = JsonFormatter::getArrayKeys($content);
$this->indent = JsonFormatter::getIndent($content);
}
}
5 changes: 2 additions & 3 deletions Json/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class JsonFormatter
public static function getArrayKeys($content)
{
preg_match_all(self::ARRAY_KEYS_REGEX, trim($content), $matches);
$keys = !empty($matches) ? $matches[1] : array();

return $keys;
return !empty($matches) ? $matches[1] : array();
}

/**
Expand Down Expand Up @@ -94,7 +93,7 @@ private static function replaceArrayByMap($json, array $arrayKeys)
preg_match_all(self::ARRAY_KEYS_REGEX, $json, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
if (!\in_array($match[1], $arrayKeys)) {
if (!\in_array($match[1], $arrayKeys, true)) {
$replace = str_replace('[]', '{}', $match[0]);
$json = str_replace($match[0], $replace, $json);
}
Expand Down
15 changes: 8 additions & 7 deletions Solver/Solver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Solver implements SolverInterface
protected $assetManager;

/**
* @var FallbackInterface|null
* @var null|FallbackInterface
*/
protected $composerFallback;

Expand All @@ -58,13 +58,14 @@ class Solver implements SolverInterface
* @param AssetManagerInterface $assetManager The asset manager
* @param Config $config The config
* @param Filesystem $filesystem The composer filesystem
* @param FallbackInterface|null $composerFallback The composer fallback
* @param null|FallbackInterface $composerFallback The composer fallback
*/
public function __construct(AssetManagerInterface $assetManager,
Config $config,
Filesystem $filesystem,
FallbackInterface $composerFallback = null)
{
public function __construct(
AssetManagerInterface $assetManager,
Config $config,
Filesystem $filesystem,
FallbackInterface $composerFallback = null
) {
$this->config = $config;
$this->fs = $filesystem;
$this->assetManager = $assetManager;
Expand Down
Loading

0 comments on commit fbaf7e4

Please sign in to comment.