apply code quality + add number of applied changes

This commit is contained in:
Tomas Votruba 2019-02-09 20:08:08 +01:00
parent 7297138fbd
commit a45eff72df
12 changed files with 27 additions and 48 deletions

View File

@ -111,11 +111,7 @@ CODE_SAMPLE
return null;
}
if ($node->stmts[0] instanceof Expression) {
$innerNode = $node->stmts[0]->expr;
} else {
$innerNode = $node->stmts[0];
}
$innerNode = $node->stmts[0] instanceof Expression ? $node->stmts[0]->expr : $node->stmts[0];
if ($innerNode instanceof Assign || $innerNode instanceof Return_) {
return $innerNode;

View File

@ -21,9 +21,7 @@ final class DiffConsoleFormatter
public function __construct()
{
$this->template = sprintf(
'<comment> ---------- begin diff ----------</comment>' .
'%s%%s%s' .
'<comment> ----------- end diff -----------</comment>',
'<comment> ---------- begin diff ----------</comment>%s%%s%s<comment> ----------- end diff -----------</comment>',
PHP_EOL,
PHP_EOL
);

View File

@ -101,7 +101,7 @@ final class EregToPcreTransformer
$i + 1 < $l && strpos('.=:', $s[$i + 1]) !== false) {
$ii = strpos($s, ']', $i);
if ($ii === false) {
throw new InvalidEregException('"[" does not have a matching ' . '"]"');
throw new InvalidEregException('"[" does not have a matching "]"');
}
$ccls = substr($s, $i + 1, $ii - ($i + 1));
$cclsmap = [
@ -120,8 +120,7 @@ final class EregToPcreTransformer
];
if (! isset($cclsmap[$ccls])) {
throw new InvalidEregException(
'an invalid or unsupported ' .
'character class [' . $ccls . ']'
'an invalid or unsupported character class [' . $ccls . ']'
);
}
$cls .= $cclsmap[$ccls];
@ -130,8 +129,7 @@ final class EregToPcreTransformer
$a = $s[$i++];
if ($a === '-' && ! $start && ! ($i < $l && $s[$i] === ']')) {
throw new InvalidEregException(
'"-" is invalid for the start ' .
'character in the brackets'
'"-" is invalid for the start character in the brackets'
);
}
if ($i < $l && $s[$i] === '-') {

View File

@ -181,11 +181,7 @@ abstract class AbstractTypeDeclarationRector extends AbstractRector
Node $node,
Node $childClassMethodOrParam
): ?Node {
if ($returnTypeInfo->getTypeNode() instanceof NullableType) {
$nakedType = $returnTypeInfo->getTypeNode()->type;
} else {
$nakedType = $returnTypeInfo->getTypeNode();
}
$nakedType = $returnTypeInfo->getTypeNode() instanceof NullableType ? $returnTypeInfo->getTypeNode()->type : $returnTypeInfo->getTypeNode();
if ($nakedType === null) {
return null;

View File

@ -29,8 +29,7 @@ final class SymfonyKernelParameterGuard
}
throw new InvalidConfigurationException(sprintf(
'Kernel class "%s" provided in "parameters > %s" is not autoloadable. ' .
'Make sure composer.json of your application is valid and rector is loading "vendor/autoload.php" of your application.',
'Kernel class "%s" provided in "parameters > %s" is not autoloadable. Make sure composer.json of your application is valid and rector is loading "vendor/autoload.php" of your application.',
$kernelClass,
Option::KERNEL_CLASS_PARAMETER
));

View File

@ -115,11 +115,7 @@ CODE_SAMPLE
*/
private function resolveUniqueName(Node $node, string $name): string
{
if ($node instanceof ClassMethod) {
$candidates = $node->params;
} else {
$candidates = $node->args;
}
$candidates = $node instanceof ClassMethod ? $node->params : $node->args;
$candidateNames = [];
foreach ($candidates as $candidate) {

View File

@ -148,11 +148,9 @@ final class RectorApplication
} else {
$oldContent = $fileInfo->getContents();
if ($this->configuration->isDryRun()) {
$newContent = $this->fileProcessor->printToString($fileInfo);
} else {
$newContent = $this->fileProcessor->printToFile($fileInfo);
}
$newContent = $this->configuration->isDryRun() ? $this->fileProcessor->printToString(
$fileInfo
) : $this->fileProcessor->printToFile($fileInfo);
$this->errorAndDiffCollector->addFileDiff($fileInfo, $newContent, $oldContent);

View File

@ -155,8 +155,9 @@ final class ProcessCommand extends AbstractCommand
}
$this->symfonyStyle->success(sprintf(
'Rector is done! %d changed files', count($this->errorAndDiffCollector->getFileDiffs()))
);
'Rector is done! %d changed files',
count($this->errorAndDiffCollector->getFileDiffs())
));
if ($this->configuration->isDryRun() && count($this->errorAndDiffCollector->getFileDiffs())) {
return Shell::CODE_ERROR;

View File

@ -120,7 +120,12 @@ final class CallMaintainer
return false;
}
$externalFileContent = $this->parser->parseFile($reflectionFunctionAbstract->getFileName());
$filePath = $reflectionFunctionAbstract->getFileName();
if (file_exists($filePath) === false) {
return true;
}
$externalFileContent = $this->parser->parseFile($filePath);
$requiredExternalType = $this->resolveMotherType($callNode);
$functionName = $reflectionFunctionAbstract->getName();

View File

@ -49,11 +49,9 @@ final class NodeFactory
*/
public function createClassConstant(string $className, string $constantName): ClassConstFetch
{
if (in_array($className, ['static', 'parent', 'self'], true)) {
$classNameNode = new Name($className);
} else {
$classNameNode = new FullyQualified($className);
}
$classNameNode = in_array($className, ['static', 'parent', 'self'], true) ? new Name(
$className
) : new FullyQualified($className);
$classConstFetchNode = $this->builderFactory->classConstFetch($classNameNode, $constantName);
$classConstFetchNode->class->setAttribute(Attribute::RESOLVED_NAME, $classNameNode);

View File

@ -77,11 +77,7 @@ final class FunctionReplaceRector extends AbstractRector
$newFunctions = array_reverse($newFunctions);
foreach ($newFunctions as $wrapFunction) {
if ($previousNode === null) {
$arguments = $funcCallNode->args;
} else {
$arguments = [new Arg($previousNode)];
}
$arguments = $previousNode === null ? $funcCallNode->args : [new Arg($previousNode)];
$funcCallNode = new FuncCall(new FullyQualified($wrapFunction), $arguments);
$previousNode = $funcCallNode;

View File

@ -86,11 +86,9 @@ final class NamespaceReplacerRector extends AbstractRector
return $node;
}
if ($this->isPartialNamespace($node)) {
$newName = $this->resolvePartialNewName($node);
} else {
$newName = $this->resolveNewNameFromNode($name);
}
$newName = $this->isPartialNamespace($node) ? $this->resolvePartialNewName(
$node
) : $this->resolveNewNameFromNode($name);
if ($newName === null) {
return null;