Skip to content
Open
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
11 changes: 2 additions & 9 deletions config/nextcloud-25/nextcloud-25-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,24 @@
declare(strict_types=1);

use Nextcloud\Rector\Rector\LegacyGetterToOcpServerGetRector;
use Nextcloud\Rector\Rector\OcHelperToOcpUtilRector;
use Nextcloud\Rector\Rector\OcServerToOcpServerRector;
use Nextcloud\Rector\Rector\OcpUtilAddScriptRector;
use Nextcloud\Rector\ValueObject\LegacyGetterToOcpServerGet;
use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector;
use Rector\CodingStyle\Rector\FuncCall\StrictInArrayRector;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\RenameStaticMethod;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
OcHelperToOcpUtilRector::class,
OcServerToOcpServerRector::class,
OcpUtilAddScriptRector::class,
StrictInArrayRector::class,
UseIdenticalOverEqualWithSameTypeRector::class,
]);

$rectorConfig->ruleWithConfiguration(RenameStaticMethodRector::class, [
// Deprecated since 4.0.0
new RenameStaticMethod('OC_Helper', 'computerFileSize', 'OCP\Util', 'computerFileSize'),
// Deprecated since 4.0.0
new RenameStaticMethod('OC_Helper', 'humanFileSize', 'OCP\Util', 'humanFileSize'),
]);

$rectorConfig->ruleWithConfiguration(
LegacyGetterToOcpServerGetRector::class,
[
Expand Down
69 changes: 0 additions & 69 deletions src/ClassNameImport/NextcloudNamespaceSkipVoter.php

This file was deleted.

18 changes: 9 additions & 9 deletions src/Rector/AnnotationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Override;
use PHPStan\PhpDocParser\Ast\Node as DocNode;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
Expand Down Expand Up @@ -42,9 +43,9 @@
use Rector\Php80\ValueObject\AttributeValueAndDocComment;
use Rector\Php80\ValueObject\DoctrineTagAndAnnotationToAttribute;
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\ValueObject\PhpVersion;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -166,12 +167,12 @@ public function configure(array $configuration): void
}

/**
* @return PhpVersionFeature::ATTRIBUTES
* @return PhpVersion::PHP_80
*/
#[Override]
public function provideMinPhpVersion(): int
{
return PhpVersionFeature::ATTRIBUTES;
return PhpVersion::PHP_80;
}

/**
Expand All @@ -180,10 +181,7 @@ public function provideMinPhpVersion(): int
private function processGenericTags(PhpDocInfo $phpDocInfo): array
{
$attributeGroups = [];
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable(
$phpDocInfo->getPhpDocNode(),
'',
$phpDocNodeVisitor = new CallablePhpDocNodeVisitor(
function (DocNode $docNode) use (&$attributeGroups) {
if (!$docNode instanceof PhpDocTagNode) {
return null;
Expand Down Expand Up @@ -225,12 +223,14 @@ function (DocNode $docNode) use (&$attributeGroups) {
return new PhpDocTextNode($attributeValueAndDocComment->docComment);
}

return PhpDocNodeTraverser::NODE_REMOVE;
return NodeTraverser::REMOVE_NODE;
}

return null;
},
);
$phpDocNodeTraverser = new NodeTraverser([$phpDocNodeVisitor]);
$phpDocNodeTraverser->traverse([$phpDocInfo->getPhpDocNode()]);

return $attributeGroups;
}
Expand Down
66 changes: 66 additions & 0 deletions src/Rector/OcHelperToOcpUtilRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

/*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace Nextcloud\Rector\Rector;

use Override;
use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name\FullyQualified;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class OcHelperToOcpUtilRector extends AbstractRector
{
private const METHODS = [
'computerFileSize',
'humanFileSize',
];

/**
* @return array<class-string<Node>>
*/
#[Override]
public function getNodeTypes(): array
{
return [StaticCall::class];
}

#[Override]
public function refactor(Node $node): ?Node
{
if (!($node instanceof StaticCall)) {
return null;
}
if (!$this->isName($node->class, 'OC_Helper')) {
return null;
}
if (!$this->isNames($node->name, self::METHODS)) {
return null;
}

$node->class = new FullyQualified('OCP\Util');

return $node;
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change static calls of OC_Helper::computerFileSize and OC_Helper::humanFileSize to OCP\Util.',
[
new CodeSample(
'\OC_Helper::humanFileSize(1223);',
'\OCP\Util::humanFileSize(1223);',
),
],
);
}
}
6 changes: 3 additions & 3 deletions src/Rector/ReplaceInjectedMethodCallRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Rector\Exception\Configuration\InvalidConfigurationException;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\MethodName;
use Rector\ValueObject\PhpVersionFeature;
use Rector\ValueObject\PhpVersion;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -199,12 +199,12 @@ public function configure(array $configuration): void
}

/**
* @return PhpVersionFeature::PROPERTY_PROMOTION
* @return PhpVersion::PHP_80
*/
#[Override]
public function provideMinPhpVersion(): int
{
return PhpVersionFeature::PROPERTY_PROMOTION;
return PhpVersion::PHP_80;
}

/**
Expand Down
46 changes: 0 additions & 46 deletions tests/ClassNameImport/Fixture/test_fixture.php.inc

This file was deleted.

45 changes: 0 additions & 45 deletions tests/ClassNameImport/NextcloudClassNameImportTest.php

This file was deleted.

13 changes: 0 additions & 13 deletions tests/ClassNameImport/config/config.php

This file was deleted.

33 changes: 33 additions & 0 deletions tests/Rector/OcHelperToOcpUtilRector/Fixture/test_fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Nextcloud\Rector\Test\Rector\OcHelperToOcpUtilRector\Fixture;

class SomeClass
{
public function foo()
{
$size = \OC_Helper::humanFileSize(1223);
$size2 = \OC_Helper::computerFileSize('12 KB');
$path = \OC_Helper::buildNotExistingFileName('/', 'a.txt');
$other = \OC_Util::humanFileSize(1223);
}
}

?>
-----
<?php

namespace Nextcloud\Rector\Test\Rector\OcHelperToOcpUtilRector\Fixture;

class SomeClass
{
public function foo()
{
$size = \OCP\Util::humanFileSize(1223);
$size2 = \OCP\Util::computerFileSize('12 KB');
$path = \OC_Helper::buildNotExistingFileName('/', 'a.txt');
$other = \OC_Util::humanFileSize(1223);
}
}

?>
Loading
Loading