Skip to content

Commit

Permalink
Add new coding styles and fix code accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
helhum committed May 30, 2017
1 parent 911c80b commit 39580da
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 69 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
composer.lock
/vendor
/composer.lock
/.php_cs.cache
56 changes: 0 additions & 56 deletions .php_cs

This file was deleted.

77 changes: 77 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => true,
'concat_space' => [
'spacing' => 'one',
],
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
'method_separation' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_blank_lines_before_namespace' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => [
'continue',
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'square_brace_block',
'throw',
],
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => [
'break',
'clone',
'continue',
'echo_print',
'return',
'switch_case',
],
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_types' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'single_quote' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'whitespace_after_comma_in_array' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('res')
->exclude('vendor')
);
58 changes: 58 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
preset: psr2

enabled:
- alpha_ordered_imports
- binary_operator_spaces
- concat_with_spaces
- function_typehint_space
- hash_to_slash_comment
- linebreak_after_opening_tag
- lowercase_cast
- method_separation
- native_function_casing
- new_with_braces
- no_alias_functions
- no_blank_lines_after_class_opening
- no_blank_lines_after_phpdoc
- no_blank_lines_before_namespace
- no_empty_comment
- no_empty_phpdoc
- no_empty_statement
- no_extra_block_blank_lines
- no_extra_consecutive_blank_lines
- no_leading_import_slash
- no_leading_namespace_whitespace
- no_multiline_whitespace_around_double_arrow
- no_multiline_whitespace_before_semicolons
- no_short_bool_cast
- no_singleline_whitespace_before_semicolons
- no_trailing_comma_in_list_call
- no_trailing_comma_in_singleline_array
- no_unneeded_control_parentheses
- no_unreachable_default_argument_value
- no_unused_imports
- no_useless_else
- no_useless_return
- no_whitespace_before_comma_in_array
- no_whitespace_in_blank_line
- normalize_index_brace
- phpdoc_add_missing_param_annotation
- phpdoc_no_package
- phpdoc_order
- phpdoc_scalar
- phpdoc_types
- self_accessor
- short_array_syntax
- short_scalar_cast
- single_quote
- standardize_not_equals
- ternary_operator_spaces
- trailing_comma_in_multiline_array
- whitespace_after_comma_in_array

finder:
name:
- "*.php"
exclude:
- "res"
- "vendor"
12 changes: 6 additions & 6 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class Config
/**
* @var array
*/
public static $defaultConfig = array(
public static $defaultConfig = [
'env-dir' => '',
'cache-dir' => null,
'allow-overrides' => true,
);
];

/**
* @var array
Expand Down Expand Up @@ -87,7 +87,7 @@ public function get($key, $flags = 0)
*/
public function all($flags = 0)
{
$all = array();
$all = [];
foreach ($this->config as $key => $_) {
$all['config'][$key] = $this->get($key, $flags);
}
Expand All @@ -100,9 +100,9 @@ public function all($flags = 0)
*/
public function raw()
{
return array(
return [
'config' => $this->config,
);
];
}

/**
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function load(\Composer\IO\IOInterface $io, \Composer\Config $comp
{
static $config;
if ($config === null) {
$baseDir = realpath(substr($composerConfig->get('vendor-dir'), 0, -strlen($composerConfig->get('vendor-dir', Config::RELATIVE_PATHS))));
$baseDir = realpath(substr($composerConfig->get('vendor-dir'), 0, -strlen($composerConfig->get('vendor-dir', self::RELATIVE_PATHS))));
$localConfig = \Composer\Factory::getComposerFile();
$file = new \Composer\Json\JsonFile($localConfig, new \Composer\Util\RemoteFilesystem($io));

Expand Down
8 changes: 4 additions & 4 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function activate(Composer $composer, IOInterface $io)
*/
public static function getSubscribedEvents()
{
return array(
ScriptEvents::PRE_AUTOLOAD_DUMP => array('onPreAutoloadDump')
);
return [
ScriptEvents::PRE_AUTOLOAD_DUMP => ['onPreAutoloadDump'],
];
}

/**
Expand Down Expand Up @@ -98,9 +98,9 @@ public function onPreAutoloadDump()
* Constructs the include file content
*
* @param string $includeFile The path to the file that will be included by composer in autoload.php
* @return string
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @return string
*/
protected function getIncludeFileContent($includeFile)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function tearDown()
$cacheDir = __DIR__ . '/Fixtures/cache';
foreach (glob($cacheDir . '/*.php') as $file) {
unlink($file);
};
}
}

/**
Expand Down

0 comments on commit 39580da

Please sign in to comment.