Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nette/utils to allow easier install #86

Merged
merged 2 commits into from
Jul 31, 2023
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
5 changes: 2 additions & 3 deletions build/composer-php-72.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"license": "MIT",
"keywords": ["static analysis", "phpstan-extension"],
"require": {
"php": "^7.2 || 8.0.*",
"php": "^7.2 || ^8.0",
TomasVotruba marked this conversation as resolved.
Show resolved Hide resolved
"phpstan/phpstan": "^1.10.19",
"nette/utils": "^3.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great move to drop the dependency

"webmozart/assert": "^1.11"
"webmozart/assert": "^1.12"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 5 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

declare(strict_types=1);

use Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

Expand All @@ -14,9 +15,10 @@
]);

$rectorConfig->importNames();
$rectorConfig->removeUnusedImports();

$rectorConfig->sets([
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_100,
LevelSetList::UP_TO_PHP_81,
SetList::TYPE_DECLARATION,
SetList::PRIVATIZATION,
Expand All @@ -26,7 +28,7 @@
SetList::CODING_STYLE,
]);

$rectorConfig->ruleWithConfiguration(\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class, [
$rectorConfig->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
'Twig\Extension\ExtensionInterface',
'PHPUnit\Framework\TestCase',
'Symfony\Bundle\FrameworkBundle\Controller\Controller',
Expand All @@ -36,9 +38,5 @@
$rectorConfig->skip([
'*/Fixture/*',
'*/Source/*',

VarConstantCommentRector::class => [
__DIR__ . '/src/PublicClassMethodMatcher.php',
],
]);
};
2 changes: 1 addition & 1 deletion src/Rules/UnusedPublicClassConstRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TomasVotruba\UnusedPublic\Rules;

use Nette\Utils\Arrays;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\CollectedDataNode;
Expand All @@ -17,6 +16,7 @@
use TomasVotruba\UnusedPublic\Enum\RuleTips;
use TomasVotruba\UnusedPublic\Enum\Template\BladeRegex;
use TomasVotruba\UnusedPublic\Templates\TemplateRegexFinder;
use TomasVotruba\UnusedPublic\Utils\Arrays;

/**
* @see \TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassConstRule\UnusedPublicClassConstRuleTest
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/UnusedPublicClassMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TomasVotruba\UnusedPublic\Rules;

use Nette\Utils\Arrays;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\CollectedDataNode;
Expand All @@ -24,6 +23,7 @@
use TomasVotruba\UnusedPublic\Enum\RuleTips;
use TomasVotruba\UnusedPublic\Templates\TemplateMethodCallsProvider;
use TomasVotruba\UnusedPublic\Templates\UsedMethodAnalyzer;
use TomasVotruba\UnusedPublic\Utils\Arrays;

/**
* @see \TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\UnusedPublicClassMethodRuleTest
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/UnusedPublicPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TomasVotruba\UnusedPublic\Rules;

use Nette\Utils\Arrays;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\CollectedDataNode;
Expand All @@ -16,6 +15,7 @@
use TomasVotruba\UnusedPublic\Collectors\PublicStaticPropertyFetchCollector;
use TomasVotruba\UnusedPublic\Configuration;
use TomasVotruba\UnusedPublic\Enum\RuleTips;
use TomasVotruba\UnusedPublic\Utils\Arrays;

/**
* @see \TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\UnusedPublicPropertyRuleTest
Expand Down
2 changes: 1 addition & 1 deletion src/Templates/TemplateRegexFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace TomasVotruba\UnusedPublic\Templates;

use Nette\Utils\Strings;
use TomasVotruba\UnusedPublic\Finder\TemplateFilesFinder;
use TomasVotruba\UnusedPublic\Utils\Strings;

final class TemplateRegexFinder
{
Expand Down
26 changes: 26 additions & 0 deletions src/Utils/Arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\UnusedPublic\Utils;

final class Arrays
{
/**
* @param mixed[] $array
* @return mixed[]
*
* @license nette/utils, where exactly copied from
*/
public static function flatten(array $array): array
{
$result = [];

$callback = static function ($value) use (&$result): void {
$result[] = $value;
};
array_walk_recursive($array, $callback);

return $result;
}
}
17 changes: 17 additions & 0 deletions src/Utils/Strings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\UnusedPublic\Utils;

final class Strings
{
/**
* @return mixed[]
*/
public static function matchAll(string $content, string $regex): array
{
preg_match_all($regex, $content, $matches, PREG_SET_ORDER);
return $matches;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassConstRule\Fixture\LocallyUsedPublicConstantByName;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassConstRule\Fixture\UnusedPublicConstant;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassConstRule\Fixture\UnusedPublicConstantFromInterface;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassConstRule\Fixture\UsedInTestCaseOnly;

final class UnusedPublicClassConstRuleTest extends RuleTestCase
{
Expand Down Expand Up @@ -75,7 +76,7 @@ public static function provideData(): Iterator

yield [[__DIR__ . '/Fixture/SkipInterfaceConstantUsed.php', __DIR__ . '/Source/InterfaceConstantUser.php'], []];

$errorMessage = sprintf(UnusedPublicClassConstRule::ERROR_MESSAGE, Fixture\UsedInTestCaseOnly::class, 'USE_ME');
$errorMessage = sprintf(UnusedPublicClassConstRule::ERROR_MESSAGE, UsedInTestCaseOnly::class, 'USE_ME');
yield [[
__DIR__ . '/Fixture/UsedInTestCaseOnly.php',
__DIR__ . '/Source/TestCaseUser.php',
Expand Down
Loading