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
29 changes: 29 additions & 0 deletions .github/workflows/duplicated_code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Duplicated Code

on:
pull_request: null
push:
branches:
- main

env:
COMPOSER_ROOT_VERSION: "dev-main"

jobs:
duplicated_code:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v4

-
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
coverage: none

- uses: "ramsey/composer-install@v2"

# fails when a large copy-pasted block (>= 150 tokens) is added
- run: composer duplicated-code
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"phpunit/phpunit": "^13.3",
"rector/jack": "^1.1",
"rector/rector-src": "dev-main",
"rector/swiss-knife": "^2.4",
"rector/swiss-knife": "^2.6",
"symplify/phpstan-rules": "^14.12",
"tomasvotruba/class-leak": "^2.1.8",
"tomasvotruba/type-coverage": "^2.3",
Expand All @@ -41,6 +41,7 @@
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse --ansi",
"duplicated-code": "vendor/bin/swiss-knife duplicated-code src rules --min-tokens 150 --min-lines 5",
"rector": "vendor/bin/rector --ansi",
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Doctrine\Orm32\Rector\MethodCall;

use PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
Expand Down Expand Up @@ -131,7 +132,7 @@ private function isTargetType(Node $node, string $className): bool
/**
* Extracts a normalized 'asc' or 'desc' string from Strings, Constants
*/
private function resolveSortDirectionValue(Node\Expr $expr): ?string
private function resolveSortDirectionValue(Expr $expr): ?string
{
if ($expr instanceof ClassConstFetch) {
$constName = $this->getName($expr->name);
Expand All @@ -141,6 +142,7 @@ private function resolveSortDirectionValue(Node\Expr $expr): ?string
if (in_array($normalized, ['asc', 'ascending'], true)) {
return 'asc';
}

if (in_array($normalized, ['desc', 'descending'], true)) {
return 'desc';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Doctrine\Orm37\Rector\Attribute;

use PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr\Array_;
Expand Down Expand Up @@ -103,7 +104,7 @@ public function refactor(Node $node): ?Node
return $hasChanged ? $node : null;
}

private function resolveSortDirectionValue(Node\Expr $expr): ?string
private function resolveSortDirectionValue(Expr $expr): ?string
{
if ($expr instanceof ClassConstFetch) {
$constName = $this->getName($expr->name);
Expand All @@ -113,6 +114,7 @@ private function resolveSortDirectionValue(Node\Expr $expr): ?string
if (in_array($normalized, ['asc', 'ascending'], true)) {
return 'asc';
}

if (in_array($normalized, ['desc', 'descending'], true)) {
return 'desc';
}
Expand Down
Loading