Skip to content

Commit

Permalink
Merge branch 'master' into fix-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
tamiroh committed Feb 12, 2024
2 parents 9b6e485 + aba9464 commit a40623a
Show file tree
Hide file tree
Showing 40 changed files with 866 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ jobs:

- name: Disable time limit for tests when collecting coverage
if: matrix.collect-code-coverage == 'yes'
run: sed 's/enforceTimeLimit="true"/enforceTimeLimit="false"/g' phpunit.xml.dist > phpunit.xml
run: sed -e 's/enforceTimeLimit="true"/enforceTimeLimit="false"/g' -e 's/coverage/source/g' phpunit.xml.dist > phpunit.xml

- name: Disable time limit for tests under Windows # due to https://github.com/sebastianbergmann/phpunit/issues/5589
if: matrix.operating-system == 'windows-latest'
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ext-tokenizer": "*",
"composer/semver": "^3.4",
"composer/xdebug-handler": "^3.0.3",
"sebastian/diff": "^4.0 || ^5.0",
"sebastian/diff": "^4.0 || ^5.0 || ^6.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
"symfony/filesystem": "^5.4 || ^6.0 || ^7.0",
Expand All @@ -47,7 +47,7 @@
"php-cs-fixer/accessible-object": "^1.1",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.4",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.4",
"phpunit/phpunit": "^9.6 || ^10.5.5",
"phpunit/phpunit": "^9.6 || ^10.5.5 || ^11.0.2",
"symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
},
Expand Down
2 changes: 1 addition & 1 deletion doc/ruleSets/Symfony.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Rules
- `no_spaces_around_offset <./../rules/whitespace/no_spaces_around_offset.rst>`_
- `no_superfluous_phpdoc_tags <./../rules/phpdoc/no_superfluous_phpdoc_tags.rst>`_ with config:

``['remove_inheritdoc' => true]``
``['allow_hidden_params' => true, 'remove_inheritdoc' => true]``

- `no_trailing_comma_in_singleline <./../rules/basic/no_trailing_comma_in_singleline.rst>`_
- `no_unneeded_braces <./../rules/control_structure/no_unneeded_braces.rst>`_ with config:
Expand Down
32 changes: 31 additions & 1 deletion doc/rules/phpdoc/no_superfluous_phpdoc_tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ information.
Configuration
-------------

``allow_hidden_params``
~~~~~~~~~~~~~~~~~~~~~~~

Whether ``param`` annotation for hidden params in method signature are allowed.

Allowed types: ``bool``

Default value: ``false``

``allow_mixed``
~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -99,6 +108,26 @@ With configuration: ``['remove_inheritdoc' => true]``.
Example #4
~~~~~~~~~~

With configuration: ``['allow_hidden_params' => true]``.

.. code-block:: diff
--- Original
+++ New
<?php
class Foo {
/**
- * @param Bar $bar
- * @param mixed $baz
* @param string|int|null $qux
- * @param mixed $foo
*/
public function doFoo(Bar $bar, $baz /*, $qux = null */) {}
}
Example #5
~~~~~~~~~~

With configuration: ``['allow_unused_params' => true]``.

.. code-block:: diff
Expand All @@ -111,6 +140,7 @@ With configuration: ``['allow_unused_params' => true]``.
- * @param Bar $bar
- * @param mixed $baz
* @param string|int|null $qux
* @param mixed $foo
*/
public function doFoo(Bar $bar, $baz /*, $qux = null */) {}
}
Expand All @@ -126,7 +156,7 @@ The rule is part of the following rule sets:

- `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:

``['remove_inheritdoc' => true]``
``['allow_hidden_params' => true, 'remove_inheritdoc' => true]``


References
Expand Down
2 changes: 1 addition & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
-
message: '#^Method PhpCsFixer\\Tests\\.+::provide.+Cases\(\) return type has no value type specified in iterable type iterable\.$#'
path: tests
count: 1023
count: 1021

-
message: '#Call to static method .+ with .+ will always evaluate to true.$#'
Expand Down
29 changes: 22 additions & 7 deletions src/Console/Report/FixReport/GitlabReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use PhpCsFixer\Console\Application;
use SebastianBergmann\Diff\Chunk;
use SebastianBergmann\Diff\Diff;
use SebastianBergmann\Diff\Parser;
use Symfony\Component\Console\Formatter\OutputFormatter;

Expand Down Expand Up @@ -51,9 +52,6 @@ public function generate(ReportSummary $reportSummary): string

$report = [];
foreach ($reportSummary->getChanged() as $fileName => $change) {
$diffs = $this->diffParser->parse($change['diff']);
$firstChunk = isset($diffs[0]) ? $diffs[0]->getChunks() : [];
$firstChunk = array_shift($firstChunk);
foreach ($change['appliedFixers'] as $fixerName) {
$report[] = [
'check_name' => 'PHP-CS-Fixer.'.$fixerName,
Expand All @@ -63,10 +61,7 @@ public function generate(ReportSummary $reportSummary): string
'severity' => 'minor',
'location' => [
'path' => $fileName,
'lines' => [
'begin' => $firstChunk instanceof Chunk ? $firstChunk->getStart() : 0,
'end' => $firstChunk instanceof Chunk ? $firstChunk->getStartRange() : 0,
],
'lines' => self::getLines($this->diffParser->parse($change['diff'])),
],
];
}
Expand All @@ -76,4 +71,24 @@ public function generate(ReportSummary $reportSummary): string

return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($jsonString) : $jsonString;
}

/**
* @param array<Diff> $diffs
*
* @return array{begin: int, end: int}
*/
private static function getLines(array $diffs): array
{
if (isset($diffs[0])) {
$firstDiff = $diffs[0];

$firstChunk = \Closure::bind(static fn (Diff $diff) => array_shift($diff->chunks), null, $firstDiff)($firstDiff);

if ($firstChunk instanceof Chunk) {
return \Closure::bind(static fn (Chunk $chunk): array => ['begin' => $chunk->start, 'end' => $chunk->startRange], null, $firstChunk)($firstChunk);
}
}

return ['begin' => 0, 'end' => 0];
}
}
4 changes: 3 additions & 1 deletion src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private function ensureFunctionFullyMultiline(Tokens $tokens, int $startFunction
do {
$prevWhitespaceTokenIndex = $tokens->getPrevTokenOfKind(
$searchIndex,
[[T_WHITESPACE]]
[[T_ENCAPSED_AND_WHITESPACE], [T_WHITESPACE]],
);

$searchIndex = $prevWhitespaceTokenIndex;
Expand All @@ -311,6 +311,8 @@ private function ensureFunctionFullyMultiline(Tokens $tokens, int $startFunction

if (null === $prevWhitespaceTokenIndex) {
$existingIndentation = '';
} elseif (!$tokens[$prevWhitespaceTokenIndex]->isGivenKind(T_WHITESPACE)) {
return;
} else {
$existingIndentation = $tokens[$prevWhitespaceTokenIndex]->getContent();
$lastLineIndex = strrpos($existingIndentation, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$uses = [];
$lastUse = null;

foreach ($namespaceUsesAnalyzer->getDeclarationsInNamespace($tokens, $namespace) as $use) {
foreach ($namespaceUsesAnalyzer->getDeclarationsInNamespace($tokens, $namespace, true) as $use) {
if (!$use->isClass()) {
continue;
}
Expand Down

0 comments on commit a40623a

Please sign in to comment.