Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"symplify/vendor-patches": "^11.5",
"tomasvotruba/class-leak": "^2.3",
"tomasvotruba/type-coverage": "^2.5",
"tomasvotruba/unused-public": "^2.2",
"shipmonk/dead-code-detector": "^1.4",
"tracy/tracy": "^2.12"
},
"autoload": {
Expand Down
17 changes: 11 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ parameters:
mocks: true
ctor: true

# see https://github.com/tomasVotruba/unused-public
unused_public:
methods: true
properties: true
constants: true

# see https://github.com/TomasVotruba/type-coverage
type_coverage:
return: 99
Expand Down Expand Up @@ -99,3 +93,14 @@ parameters:
-
identifier: symplify.noNullableServiceInConstructor
path: packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php

# constructors are invoked via DI autowiring, not detectable by dead-code-detector
-
identifier: shipmonk.deadMethod
message: '#::__construct$#'

# interface contracts and util method called dynamically
-
message: '#^Unused Symplify\\EasyCodingStandard\\Parallel\\Contract\\SerializableInterface\:\:decode$#'
identifier: shipmonk.deadMethod
path: src/Parallel/Contract/SerializableInterface.php
2 changes: 0 additions & 2 deletions src/Contract/Application/FileProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

interface FileProcessorInterface
{
public function processFileToString(string $filePath): string;

/**
* @return array{file_diffs?: FileDiff[], coding_standard_errors?: CodingStandardError[]}
*/
Expand Down
25 changes: 0 additions & 25 deletions src/FixerRunner/Application/FixerFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,6 @@ public function processFile(string $filePath, Configuration $configuration): arr
];
}

public function processFileToString(string $filePath): string
{
$tokens = $this->fileToTokensParser->parseFromFilePath($filePath);

$appliedFixers = [];
foreach ($this->fixers as $fixer) {
if ($this->processTokensByFixer($filePath, $tokens, $fixer)) {
$appliedFixers[] = $fixer::class;
}
}

$contents = FileSystem::read($filePath);
if ($appliedFixers === []) {
return $contents;
}

$diff = $this->differ->diff($contents, $tokens->generateCode());
// some fixer with feature overlap can null each other
if ($diff === '') {
return $contents;
}

return $tokens->generateCode();
}

/**
* @param FixerInterface[] $fixers
* @return FixerInterface[]
Expand Down
11 changes: 0 additions & 11 deletions src/SniffRunner/Application/SniffFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ public function processFile(string $filePath, Configuration $configuration): arr
return $errorsAndDiffs;
}

/**
* For tests or printing contenet
*/
public function processFileToString(string $filePath): string
{
$file = $this->fileFactory->createFromFile($filePath);
$this->fixFile($file, $filePath, $this->tokenListeners, []);

return $this->fixer->getContents();
}

private function addSniff(Sniff $sniff): void
{
$this->sniffs[] = $sniff;
Expand Down
14 changes: 9 additions & 5 deletions src/Testing/PHPUnit/AbstractCheckerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symplify\EasyCodingStandard\FixerRunner\Application\FixerFileProcessor;
use Symplify\EasyCodingStandard\SniffRunner\Application\SniffFileProcessor;
use Symplify\EasyCodingStandard\Testing\Contract\ConfigAwareInterface;
use Symplify\EasyCodingStandard\ValueObject\Configuration;
use Webmozart\Assert\Assert;

// needed for scoped version to load unprefixed classes; does not have any effect inside the class
Expand Down Expand Up @@ -72,15 +73,18 @@ protected function doTestFile(string $filePath): void
$inputFilePath = sys_get_temp_dir() . '/ecs_tests/' . md5($inputContents) . '.php';
FileSystem::write($inputFilePath, $inputContents, null);

$configuration = new Configuration(isFixer: true);

// 1. process php-cs-fixer
if ($this->fixerFileProcessor->getCheckers() !== []) {
$processedFileContent = $this->fixerFileProcessor->processFileToString($inputFilePath);
$this->assertEquals($expectedContents, $processedFileContent);
// 2. process php coce sniffer
$this->fixerFileProcessor->processFile($inputFilePath, $configuration);
// 2. process php code sniffer
} elseif ($this->sniffFileProcessor->getCheckers() !== []) {
$processedFileContent = $this->sniffFileProcessor->processFileToString($inputFilePath);
$this->assertEquals($expectedContents, $processedFileContent);
$this->sniffFileProcessor->processFile($inputFilePath, $configuration);
}

$processedFileContent = FileSystem::read($inputFilePath);
$this->assertEquals($expectedContents, $processedFileContent);
}

protected static function yieldFiles(string $directory, string $suffix = '*.php.inc'): Iterator
Expand Down
26 changes: 0 additions & 26 deletions src/Utils/ParametersMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,6 @@ public function merge(mixed $left, mixed $right): mixed
return $right;
}

/**
* The same as above, just with the case if both values being non-array, it will combined them to array:
*
* $this->mergeWithCombine(1, 2); // [1, 2]
*/
public function mergeWithCombine(mixed $left, mixed $right): mixed
{
if (is_array($left) && is_array($right)) {
return $this->mergeLeftToRightWithCallable(
$left,
$right,
fn ($leftValue, $rightValue): mixed => $this->mergeWithCombine($leftValue, $rightValue)
);
}

if ($left === null && is_array($right)) {
return $right;
}

if ($right && (array) $left !== (array) $right) {
return $this->mergeWithCombine((array) $right, (array) $left);
}

return $left;
}

/**
* @param array<int|string, mixed> $left
* @param array<int|string, mixed> $right
Expand Down
Loading