Skip to content

Commit

Permalink
Tweak CS (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 28, 2019
1 parent a9301c1 commit 43a0566
Show file tree
Hide file tree
Showing 290 changed files with 1,142 additions and 644 deletions.
47 changes: 35 additions & 12 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ declare(strict_types=1);
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$header = trim(
sprintf(
'This code is licensed under the BSD 3-Clause License.%s',
substr(
file_get_contents('LICENSE'),
\strlen('BSD 3-Clause License')
)
$header = trim(sprintf(
'This code is licensed under the BSD 3-Clause License.%s',
substr(
file_get_contents('LICENSE'),
strlen('BSD 3-Clause License')
)
);
));

$finder = Finder::create()
->in(__DIR__)
Expand Down Expand Up @@ -74,6 +72,7 @@ return Config::create()
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'blank_line_before_statement' => [
'statements' => [
'break',
Expand All @@ -95,32 +94,56 @@ return Config::create()
'yield',
],
],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'final_static_access' => true,
'fully_qualified_strict_types' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
'header_comment' => [
'commentType' => 'PHPDoc',
'header' => $header,
'location' => 'after_open',
'separate' => 'bottom',
],
'native_function_invocation' => [
'include' => ['@compiler_optimized'],
'list_syntax' => [
'syntax' => 'short',
],
'logical_operators' => true,
'native_constant_invocation' => false,
'native_function_invocation' => false,
'no_alternative_syntax' => true,
'no_superfluous_phpdoc_tags' => true,
'no_unset_cast' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'ordered_interfaces' => true,
'phpdoc_align' => false,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_dedicate_assert' => true,
'php_unit_method_casing' => [
'case' => 'snake_case',
],
'php_unit_ordered_covers' => true,
'php_unit_test_annotation' => [
'style' => 'prefix',
'case' => 'snake',
'style' => 'prefix',
],
'self_static_accessor' => true,
'single_line_throw' => false,
'static_lambda' => true,
'strict_comparison' => true,
'yoda_style' => false,
'single_line_throw' => false,
])
->setFinder($finder)
;
19 changes: 10 additions & 9 deletions src/Command/ConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use function Safe\file_get_contents;
use function Safe\glob;
use function Safe\json_decode;
use stdClass;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -101,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$sourceDirGuesser = new SourceDirGuesser($content);
} else {
$sourceDirGuesser = new SourceDirGuesser(new \stdClass());
$sourceDirGuesser = new SourceDirGuesser(new stdClass());
}

$sourceDirsProvider = new SourceDirsProvider($consoleHelper, $questionHelper, $sourceDirGuesser);
Expand Down Expand Up @@ -152,14 +153,14 @@ private function saveConfig(
array $sourceDirs,
array $excludedDirs,
int $timeout,
string $phpUnitConfigPath = null,
string $phpUnitCustomExecutablePath = null,
string $textLogFilePath = null
?string $phpUnitConfigPath = null,
?string $phpUnitCustomExecutablePath = null,
?string $textLogFilePath = null
): void {
$configObject = new \stdClass();
$configObject = new stdClass();

$configObject->timeout = $timeout;
$configObject->source = new \stdClass();
$configObject->source = new stdClass();

if ($sourceDirs) {
$configObject->source->directories = $sourceDirs;
Expand All @@ -170,20 +171,20 @@ private function saveConfig(
}

if ($phpUnitConfigPath) {
$configObject->phpUnit = new \stdClass();
$configObject->phpUnit = new stdClass();
$configObject->phpUnit->configDir = $phpUnitConfigPath;
}

if ($phpUnitCustomExecutablePath) {
if (!isset($configObject->phpUnit)) {
$configObject->phpUnit = new \stdClass();
$configObject->phpUnit = new stdClass();
}

$configObject->phpUnit->customPath = $phpUnitCustomExecutablePath;
}

if ($textLogFilePath) {
$configObject->logs = new \stdClass();
$configObject->logs = new stdClass();
$configObject->logs->text = $textLogFilePath;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Command/InfectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

namespace Infection\Command;

use function dirname;
use Exception;
use Infection\Config\InfectionConfig;
use Infection\Configuration\Configuration;
use Infection\Console\ConsoleOutput;
Expand Down Expand Up @@ -466,7 +468,7 @@ private function runConfigurationCommand(Locator $locator): void
{
try {
$locator->locateOneOf(InfectionConfig::POSSIBLE_CONFIG_FILE_NAMES);
} catch (\Exception $e) {
} catch (Exception $e) {
$configureCommand = $this->getApplication()->find('configure');

$args = [
Expand Down Expand Up @@ -501,7 +503,7 @@ private function assertCodeCoverageExists(Process $initialTestsProcess, string $
throw CoverageDoesNotExistException::with(
$coverageIndexFilePath,
$testFrameworkKey,
\dirname($coverageIndexFilePath, 2),
dirname($coverageIndexFilePath, 2),
$processInfo
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/InvalidConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@

namespace Infection\Config\Exception;

use RuntimeException;

/**
* @internal
*/
final class InvalidConfigException extends \RuntimeException
final class InvalidConfigException extends RuntimeException
{
public static function invalidMutator(string $mutator): self
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Guesser/PhpUnitPathGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

namespace Infection\Config\Guesser;

use stdClass;

/**
* @internal
*/
Expand All @@ -44,7 +46,7 @@ final class PhpUnitPathGuesser implements Guesser

private $composerJsonContent;

public function __construct(\stdClass $composerJsonContent)
public function __construct(stdClass $composerJsonContent)
{
$this->composerJsonContent = $composerJsonContent;
}
Expand Down
21 changes: 14 additions & 7 deletions src/Config/Guesser/SourceDirGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@

namespace Infection\Config\Guesser;

use const DIRECTORY_SEPARATOR;
use function in_array;
use function is_array;
use function is_string;
use LogicException;
use stdClass;

/**
* @internal
*/
class SourceDirGuesser implements Guesser
{
private $composerJsonContent;

public function __construct(\stdClass $composerJsonContent)
public function __construct(stdClass $composerJsonContent)
{
$this->composerJsonContent = $composerJsonContent;
}
Expand Down Expand Up @@ -71,7 +78,7 @@ private function getValues(string $psr): array
$dirs = $this->parsePsrSection((array) $this->composerJsonContent->autoload->{$psr});

// we don't want to mix different framework's folders like "app" for Symfony
if (\in_array('src', $dirs, true)) {
if (in_array('src', $dirs, true)) {
return ['src'];
}

Expand All @@ -83,8 +90,8 @@ private function parsePsrSection(array $autoloadDirs): array
$dirs = [];

foreach ($autoloadDirs as $path) {
if (!\is_array($path) && !\is_string($path)) {
throw new \LogicException('autoload section does not match the expected JSON schema');
if (!is_array($path) && !is_string($path)) {
throw new LogicException('autoload section does not match the expected JSON schema');
}

$this->parsePath($path, $dirs);
Expand All @@ -98,7 +105,7 @@ private function parsePsrSection(array $autoloadDirs): array
*/
private function parsePath($path, array &$dirs): void
{
if (\is_array($path)) {
if (is_array($path)) {
array_walk_recursive(
$path,
function ($el) use (&$dirs): void {
Expand All @@ -107,8 +114,8 @@ function ($el) use (&$dirs): void {
);
}

if (\is_string($path)) {
$dirs[] = trim($path, \DIRECTORY_SEPARATOR);
if (is_string($path)) {
$dirs[] = trim($path, DIRECTORY_SEPARATOR);
}
}
}
16 changes: 10 additions & 6 deletions src/Config/InfectionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@

namespace Infection\Config;

use const DIRECTORY_SEPARATOR;
use Infection\TestFramework\TestFrameworkTypes;
use function is_array;
use stdClass;
use function strlen;
use Symfony\Component\Filesystem\Filesystem;

/**
Expand All @@ -55,7 +59,7 @@ class InfectionConfig
];

/**
* @var \stdClass
* @var stdClass
*/
private $config;

Expand All @@ -69,7 +73,7 @@ class InfectionConfig
*/
private $configLocation;

public function __construct(\stdClass $config, Filesystem $filesystem, string $configLocation)
public function __construct(stdClass $config, Filesystem $filesystem, string $configLocation)
{
$this->config = $config;
$this->filesystem = $filesystem;
Expand All @@ -86,7 +90,7 @@ public function getPhpUnitConfigDir(): string
return $this->config->phpUnit->configDir;
}

return $this->configLocation . \DIRECTORY_SEPARATOR . $this->config->phpUnit->configDir;
return $this->configLocation . DIRECTORY_SEPARATOR . $this->config->phpUnit->configDir;
}

public function getPhpUnitCustomPath(): string
Expand Down Expand Up @@ -170,7 +174,7 @@ public function getTestFrameworkOptions(): string

private function getExcludes(): array
{
if (isset($this->config->source->excludes) && \is_array($this->config->source->excludes)) {
if (isset($this->config->source->excludes) && is_array($this->config->source->excludes)) {
return $this->config->source->excludes;
}

Expand All @@ -194,8 +198,8 @@ private function getExcludedDirsByPattern(string $originalExcludedDir)
array_map(
static function ($excludeDir) use ($srcDir) {
return ltrim(
substr_replace($excludeDir, '', 0, \strlen($srcDir)),
\DIRECTORY_SEPARATOR
substr_replace($excludeDir, '', 0, strlen($srcDir)),
DIRECTORY_SEPARATOR
);
},
$unpackedPaths
Expand Down
6 changes: 4 additions & 2 deletions src/Config/ValueProvider/ExcludeDirsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

namespace Infection\Config\ValueProvider;

use function count;
use function in_array;
use Infection\Config\ConsoleHelper;
use Infection\Locator\Locator;
use Infection\Locator\RootsFileOrDirectoryLocator;
Expand Down Expand Up @@ -95,13 +97,13 @@ public function get(InputInterface $input, OutputInterface $output, array $dirsI

if ($sourceDirs === ['.']) {
foreach (self::EXCLUDED_ROOT_DIRS as $dir) {
if (\in_array($dir, $dirsInCurrentDir, true)) {
if (in_array($dir, $dirsInCurrentDir, true)) {
$excludedDirs[] = $dir;
}
}

$autocompleteValues = $dirsInCurrentDir;
} elseif (\count($sourceDirs) === 1) {
} elseif (count($sourceDirs) === 1) {
$globDirs = array_filter(glob($sourceDirs[0] . '/*'), 'is_dir');

$autocompleteValues = array_map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@

namespace Infection\Config\ValueProvider;

use Closure;
use const DIRECTORY_SEPARATOR;
use Infection\Config\ConsoleHelper;
use Infection\Finder\Exception\FinderException;
use Infection\Finder\TestFrameworkFinder;
use RuntimeException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -84,7 +87,7 @@ public function get(InputInterface $input, OutputInterface $output)
$question->setValidator($this->getValidator());

return str_replace(
\DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
'/',
$this->questionHelper->ask($input, $output, $question)
);
Expand All @@ -93,13 +96,13 @@ public function get(InputInterface $input, OutputInterface $output)
return null;
}

private function getValidator(): \Closure
private function getValidator(): Closure
{
return static function ($answerPath) {
$answerPath = $answerPath ? trim($answerPath) : $answerPath;

if (!$answerPath || !file_exists($answerPath)) {
throw new \RuntimeException(sprintf('Custom path "%s" is incorrect.', $answerPath));
throw new RuntimeException(sprintf('Custom path "%s" is incorrect.', $answerPath));
}

return $answerPath;
Expand Down
Loading

0 comments on commit 43a0566

Please sign in to comment.