Skip to content

Commit

Permalink
EZP-28161: Enable php-cs-fixer aligned with v2.7.1 settings (#25)
Browse files Browse the repository at this point in the history
* EZP-28161: [CS] Created php-cs-fixer config aligned with v2.7.1 settings

* EZP-28161: [Composer] Added dev dependency for php-cs-fixer:~2.7.1

* EZP-28161: [Composer] Added composer command fix-cs

Usage:
composer fix-cs

* EZP-28161: [CS] Fixed code according to CS rules

Fixed:
   1) Tests/View/SystemInfoViewBuilderTest.php (no_unused_imports)
   2) Tests/SystemInfo/Collector/DoctrineDatabaseSystemInfoCollectorTest.php (no_unused_imports)
   3) Tests/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php (function_to_constant, trailing_comma_in_multiline_array)
   4) View/SystemInfoViewBuilder.php (no_unused_imports)
   5) SystemInfo/Registry/IdentifierBased.php (single_quote)
   6) SystemInfo/OutputFormat/JsonOutputFormat.php (no_spaces_inside_parenthesis)
   7) SystemInfo/OutputFormatRegistry.php (single_quote)
   8) SystemInfo/OutputFormat.php (phpdoc_summary)
   9) SystemInfo/EzcSystemInfoWrapper.php (phpdoc_scalar, braces)
  10) SystemInfo/Collector/EzcPhpSystemInfoCollector.php (function_to_constant, phpdoc_summary)
  11) SystemInfo/Collector/EzcHardwareSystemInfoCollector.php (phpdoc_summary)
  12) SystemInfo/Collector/DoctrineDatabaseSystemInfoCollector.php (phpdoc_summary)
  13) Command/SystemInfoDumpCommand.php (method_separation, phpdoc_indent, no_unused_imports, blank_line_before_statement, braces)
  14) DependencyInjection/EzSystemsEzSupportToolsExtension.php (concat_space)

* [Travis] Created test matrix: dropped PHP 5.5 testing, added 7.1 testing

* EZP-28161: [Travis] Added CodeStyle testing using php-cs-fixer

* EZP-28161: [Travis] Disabled XDebug when running php-cs-fixer

(for better performance)
  • Loading branch information
alongosz authored and andrerom committed Nov 9, 2017
1 parent 18f8d13 commit 467c170
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
composer.lock
.php_cs.cache
37 changes: 37 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

// PHP-CS-Fixer 2.x syntax
return PhpCsFixer\Config::create()
->setRules(
[
'@Symfony' => true,
'@Symfony:risky' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => false,
'simplified_null_return' => false,
'phpdoc_align' => false,
'phpdoc_separation' => false,
'phpdoc_to_comment' => false,
'cast_spaces' => false,
'blank_line_after_opening_tag' => false,
'single_blank_line_before_namespace' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_no_alias_tag' => false,
'space_after_semicolon' => false,
'yoda_style' => false,
'no_break_comment' => false,
]
)
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(
[
'bin',
'Resources',
'vendor',
]
)
->files()->name('*.php')
);
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: php

php:
- 5.5
- 5.6
- 7.0
matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
env: CHECK_CS=true

# test only master (+ Pull requests)
branches:
Expand All @@ -16,9 +18,12 @@ before_script:
- travis_retry composer selfupdate
# Avoid memory issues on composer install
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
# Install packages
- travis_retry composer install --prefer-dist --no-interaction

script: php bin/phpunit --coverage-text
script:
- php bin/phpunit --coverage-text
- if [ "$CHECK_CS" == "true" ]; then phpenv config-rm xdebug.ini && bin/php-cs-fixer fix -v --dry-run --diff --show-progress=estimating; fi

notifications:
email: false
47 changes: 23 additions & 24 deletions Command/SystemInfoDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
namespace EzSystems\EzSupportToolsBundle\Command;

use EzSystems\EzSupportToolsBundle\SystemInfo\Collector\SystemInfoCollector;
use EzSystems\EzSupportToolsBundle\SystemInfo\SystemInfoCollectorRegistry;
use EzSystems\EzSupportToolsBundle\SystemInfo\OutputFormatRegistry;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
Expand Down Expand Up @@ -82,35 +81,35 @@ protected function configure()
* @param $input InputInterface
* @param $output OutputInterface
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('list-info-collectors')) {
$output->writeln('Available info collectors:', true);
foreach ($this->systemInfoCollectorRegistry->getIdentifiers() as $identifier) {
$output->writeln(" $identifier", true);
}
return;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('list-info-collectors')) {
$output->writeln('Available info collectors:', true);
foreach ($this->systemInfoCollectorRegistry->getIdentifiers() as $identifier) {
$output->writeln(" $identifier", true);
}

return;
}

$outputFormatter = $this->outputFormatRegistry->getItem(
$outputFormatter = $this->outputFormatRegistry->getItem(
$input->getOption('format')
);

if ($input->getArgument('info-collectors')) {
$identifiers = $input->getArgument('info-collectors');
} else {
$identifiers = $this->systemInfoCollectorRegistry->getIdentifiers();
}
if ($input->getArgument('info-collectors')) {
$identifiers = $input->getArgument('info-collectors');
} else {
$identifiers = $this->systemInfoCollectorRegistry->getIdentifiers();
}

// Collect info for the given identifiers.
$collectedInfoArray = [];
foreach ($identifiers as $identifier) {
$collectedInfoArray[$identifier] = $this->systemInfoCollectorRegistry->getItem($identifier)->collect();
}
// Collect info for the given identifiers.
$collectedInfoArray = [];
foreach ($identifiers as $identifier) {
$collectedInfoArray[$identifier] = $this->systemInfoCollectorRegistry->getItem($identifier)->collect();
}

$output->writeln(
$output->writeln(
$outputFormatter->format($collectedInfoArray)
);
}

}
}
2 changes: 1 addition & 1 deletion DependencyInjection/EzSystemsEzSupportToolsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EzSystemsEzSupportToolsExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('default_settings.yml');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(Connection $db)
* - type
* - name
* - host
* - username
* - username.
*
* @return Value\DatabaseSystemInfo
*/
Expand Down
2 changes: 1 addition & 1 deletion SystemInfo/Collector/EzcHardwareSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(EzcSystemInfoWrapper $ezcSystemInfo)
/**
* Collects information about the hardware eZ Platform is installed on.
* - cpu information
* - memory size
* - memory size.
*
* @return Value\HardwareSystemInfo
*/
Expand Down
4 changes: 2 additions & 2 deletions SystemInfo/Collector/EzcPhpSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function __construct(EzcSystemInfoWrapper $ezcSystemInfo)
/**
* Collects information about the PHP installation eZ Platform is using.
* - php version
* - php accelerator info
* - php accelerator info.
*
* @return Value\PhpSystemInfo
*/
public function collect()
{
$properties = [
'version' => phpversion(),
'version' => PHP_VERSION,
'acceleratorEnabled' => false,
];

Expand Down
6 changes: 3 additions & 3 deletions SystemInfo/EzcSystemInfoWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EzcSystemInfoWrapper
/** @var string */
public $fileSystemType;

/** @var integer */
/** @var int */
public $cpuCount;

/** @var string */
Expand All @@ -35,7 +35,7 @@ class EzcSystemInfoWrapper
/** @var float */
public $cpuSpeed;

/** @var integer */
/** @var int */
public $memorySize;

/** @var string */
Expand All @@ -57,7 +57,7 @@ public function __construct()
{
try {
$ezcSystemInfo = ezcSystemInfo::getInstance();
} catch(ezcSystemInfoReaderCantScanOSException $e) {
} catch (ezcSystemInfoReaderCantScanOSException $e) {
// Leave properties as null: https://github.com/zetacomponents/SystemInformation/pull/9
return;
}
Expand Down
2 changes: 1 addition & 1 deletion SystemInfo/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
interface OutputFormat
{
/**
* Format an array of collected information data, and return it as string
* Format an array of collected information data, and return it as string.
*
* @param array $collectedInfo
* @return string
Expand Down
2 changes: 1 addition & 1 deletion SystemInfo/OutputFormat/JsonOutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class JsonOutputFormat implements SystemInfoOutputFormat
{
public function format(array $collectedInfo)
{
return json_encode( $collectedInfo, JSON_PRETTY_PRINT);
return json_encode($collectedInfo, JSON_PRETTY_PRINT);
}
}
2 changes: 1 addition & 1 deletion SystemInfo/OutputFormatRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getItem($identifier)
return $this->registry[$identifier];
}

throw new NotFoundException("A SystemInfo output format could not be found.", $identifier);
throw new NotFoundException('A SystemInfo output format could not be found.', $identifier);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion SystemInfo/Registry/IdentifierBased.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getItem($identifier)
return $this->registry[$identifier];
}

throw new NotFoundException("A SystemInfo collector could not be found.", $identifier);
throw new NotFoundException('A SystemInfo collector could not be found.', $identifier);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
namespace EzSystems\EzSupportToolsBundle\Tests\SystemInfo\Collector;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\DatabaseSystemInfo;
use PHPUnit_Framework_TestCase;
Expand Down
17 changes: 10 additions & 7 deletions Tests/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ public function setUp()
->getMockBuilder('EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper')
->disableOriginalConstructor()
->getMock();
$this->ezcSystemInfoMock->phpVersion = phpversion();
$this->ezcSystemInfoMock->phpVersion = PHP_VERSION;

$this->ezcSystemInfoMock->phpAccelerator = $this
->getMockBuilder('ezcSystemInfoAccelerator')
->setConstructorArgs([
'Zend OPcache',
'http://www.php.net/opcache',
true,
false,
'7.0.4-devFE'])
->setConstructorArgs(
[
'Zend OPcache',
'http://www.php.net/opcache',
true,
false,
'7.0.4-devFE',
]
)
->getMock();

$this->ezcPhpCollector = new EzcPhpSystemInfoCollector($this->ezcSystemInfoMock);
Expand Down
2 changes: 0 additions & 2 deletions Tests/View/SystemInfoViewBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
namespace EzSystems\EzSupportToolsBundle\Tests\View;

use eZ\Publish\Core\Base\Exceptions\NotFoundException;
use EzSystems\EzSupportToolsBundle\SystemInfo\SystemInfoCollectorRegistry;
use EzSystems\EzSupportToolsBundle\View\SystemInfoViewBuilder;

class SystemInfoViewBuilderTest extends \PHPUnit_Framework_TestCase
Expand Down
1 change: 0 additions & 1 deletion View/SystemInfoViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use eZ\Publish\Core\MVC\Symfony\View\Builder\ViewBuilder;
use eZ\Publish\Core\MVC\Symfony\View\Configurator;
use EzSystems\EzSupportToolsBundle\SystemInfo\Collector\SystemInfoCollector;
use EzSystems\EzSupportToolsBundle\SystemInfo\SystemInfoCollectorRegistry;

class SystemInfoViewBuilder implements ViewBuilder
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"bin-dir": "bin"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.7.1",
"phpunit/phpunit": "^4.7"
},
"scripts": {
"fix-cs": "@php ./bin/php-cs-fixer fix -v --show-progress=estimating"
}
}

0 comments on commit 467c170

Please sign in to comment.