Skip to content

Commit

Permalink
Bump deps (#125)
Browse files Browse the repository at this point in the history
* misc

* add symplify rules

* rector
  • Loading branch information
TomasVotruba committed Aug 29, 2024
1 parent e96d688 commit 6d5d529
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 53 deletions.
8 changes: 4 additions & 4 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;

$config = new Configuration();

return $config
->ignoreErrorsOnPaths([
__DIR__ . '/tests',
], [ErrorType::UNKNOWN_CLASS]);
->ignoreErrorsOnPaths([__DIR__ . '/tests'], [ErrorType::UNKNOWN_CLASS]);
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
"keywords": ["static analysis", "phpstan-extension"],
"require": {
"php": "^8.2",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan": "^1.12",
"webmozart/assert": "^1.11",
"nikic/php-parser": "^4.19"
},
"require-dev": {
"phpstan/extension-installer": "^1.3",
"phpstan/extension-installer": "^1.4",
"tracy/tracy": "^2.10",
"symplify/easy-coding-standard": "^12.1",
"rector/rector": "^1.0",
"symplify/easy-coding-standard": "^12.3",
"rector/rector": "^1.2.4",
"phpunit/phpunit": "^10.5",
"tomasvotruba/class-leak": "^0.2.11",
"tomasvotruba/cognitive-complexity": "^0.2.2",
"tomasvotruba/type-coverage": "^0.2",
"tomasvotruba/type-coverage": "^0.3",
"symplify/easy-ci": "^12.0",
"shipmonk/composer-dependency-analyser": "^1.5"
"shipmonk/composer-dependency-analyser": "^1.5",
"symplify/phpstan-rules": "^13.0"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 3 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ parameters:
return_type: 99
param_type: 99
property_type: 99
# print_suggestions: true

cognitive_complexity:
function: 11

level: 8

paths:
- src
- tests

checkGenericClassInNonGenericObjectType: false

excludePaths:
- "*/Fixture/*"
- "*/Source/*"

ignoreErrors:
-
identifier: missingType.generics

# overly detailed
-
message: '#testRule\(\) has parameter (.*?) with no value type specified in iterable type array#'
Expand Down
6 changes: 3 additions & 3 deletions src/Collectors/PublicPropertyCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ private function shouldSkipProperty(ClassReflection $classReflection, string $pr
return false;
}

$propertyReflection = $classReflection->getProperty($propertyName, $scope);
$extendedPropertyReflection = $classReflection->getProperty($propertyName, $scope);
// don't inherit doc from a private property
if ($propertyReflection->isPrivate()) {
if ($extendedPropertyReflection->isPrivate()) {
return false;
}

$docComment = $propertyReflection->getDocComment();
$docComment = $extendedPropertyReflection->getDocComment();
if ($docComment !== null && $this->apiDocStmtAnalyzer->isApiDocComment($docComment)) {
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Collectors/PublicPropertyFetchCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Collectors\Collector;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\TypeWithClassName;
use TomasVotruba\UnusedPublic\ClassTypeDetector;
use TomasVotruba\UnusedPublic\Configuration;

Expand Down Expand Up @@ -60,12 +59,13 @@ public function processNode(Node $node, Scope $scope): ?array

$result = [];
$propertyFetcherType = $scope->getType($node->var);
foreach($propertyFetcherType->getObjectClassReflections() as $classReflection) {
foreach ($propertyFetcherType->getObjectClassReflections() as $classReflection) {
$propertyName = $node->name->toString();

if (!$classReflection->hasProperty($propertyName)) {
if (! $classReflection->hasProperty($propertyName)) {
continue;
}

$propertyReflection = $classReflection->getProperty($propertyName, $scope);
$result[] = $propertyReflection->getDeclaringClass()->getName() . '::' . $propertyName;
}
Expand Down
16 changes: 7 additions & 9 deletions src/Collectors/PublicStaticPropertyFetchCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function getNodeType(): string
*/
public function processNode(Node $node, Scope $scope): ?array
{
if (!$this->configuration->isUnusedPropertyEnabled()) {
if (! $this->configuration->isUnusedPropertyEnabled()) {
return null;
}

if (!$node->name instanceof Identifier) {
if (! $node->name instanceof Identifier) {
return null;
}

Expand All @@ -57,18 +57,16 @@ public function processNode(Node $node, Scope $scope): ?array
return null;
}

if ($node->class instanceof Name) {
$classType = $scope->resolveTypeByName($node->class);
} else {
$classType = $scope->getType($node->class);
}
$classType = $node->class instanceof Name ? $scope->resolveTypeByName($node->class) : $scope->getType($node->class);

$result = [];
foreach($classType->getObjectClassReflections() as $classReflection) {
foreach ($classType->getObjectClassReflections() as $classReflection) {
$propertyName = $node->name->toString();

if (!$classReflection->hasProperty($propertyName)) {
if (! $classReflection->hasProperty($propertyName)) {
continue;
}

$propertyReflection = $classReflection->getProperty($propertyName, $scope);
$result[] = $propertyReflection->getDeclaringClass()->getName() . '::' . $propertyName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicClassMethodRule\Fixture;

class SkipJsonSerialize implements \JsonSerializable {
public function jsonSerialize() : array {
class SkipJsonSerialize implements \JsonSerializable
{
public function jsonSerialize(): array
{
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class PropertyUsedViaSubClass
{
private SubClass $prop;

protected function doFoo() {
protected function doFoo()
{
$this->prop->x = 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class StaticPropertyUsedViaSubClass
{
private SubClass $prop;

protected function doFoo() {
protected function doFoo()
{
$this->prop::$x = 1;
}
}
Expand All @@ -19,5 +20,5 @@ class SubClass extends BaseClass

class BaseClass
{
static public int $x;
public static int $x;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

final class StaticUsedInTestCaseOnly
{
static public $property = 'public static';
public static $property = 'public static';
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture;

class StaticUsedInUnionA {
static public float $amount;
class StaticUsedInUnionA
{
public static float $amount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture;

class StaticUsedInUnionB {
static public float $amount;
class StaticUsedInUnionB
{
public static float $amount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture;

class UsedInUnionA {
class UsedInUnionA
{
public float $amount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture;

class UsedInUnionB {
class UsedInUnionB
{
public float $amount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\StaticUsedInUnionA;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\StaticUsedInUnionB;

function doFooBar(StaticUsedInUnionA|StaticUsedInUnionB $aOrB): void {
function doFooBar(StaticUsedInUnionA|StaticUsedInUnionB $aOrB): void
{
echo $aOrB::$amount;
}

4 changes: 2 additions & 2 deletions tests/Rules/UnusedPublicPropertyRule/Source/UsedInUnion.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\UsedInUnionA;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\UsedInUnionB;

function doFooBar(UsedInUnionA|UsedInUnionB $aOrB): void {
function doFooBar(UsedInUnionA|UsedInUnionB $aOrB): void
{
echo $aOrB->amount;
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\UsedInUnionB;

/** @param UsedInUnionA|UsedInUnionB $aOrB */
function doFoo($aOrB): void {
function doFoo($aOrB): void
{
echo $aOrB->amount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\LocallyUsedStaticProperty;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\LocallyUsedStaticPropertyViaStatic;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\LocalyUsedPublicProperty;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\UsedInTestCaseOnly;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\StaticUsedInTestCaseOnly;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\UsedInTestCaseOnly;

final class UnusedPublicPropertyRuleTest extends RuleTestCase
{
Expand Down Expand Up @@ -120,9 +120,18 @@ public static function provideData(): Iterator
[],
];

yield [[__DIR__ . '/Fixture/UsedInUnionA.php', __DIR__ . '/Fixture/UsedInUnionB.php', __DIR__ . '/Source/UsedInUnion.php'], []];
yield [[__DIR__ . '/Fixture/UsedInUnionA.php', __DIR__ . '/Fixture/UsedInUnionB.php', __DIR__ . '/Source/UsedInUnionPhpdoc.php'], []];
yield [[__DIR__ . '/Fixture/StaticUsedInUnionA.php', __DIR__ . '/Fixture/StaticUsedInUnionB.php', __DIR__ . '/Source/StaticUsedInUnion.php'], []];
yield [[
__DIR__ . '/Fixture/UsedInUnionA.php', __DIR__ . '/Fixture/UsedInUnionB.php', __DIR__ . '/Source/UsedInUnion.php'],
[],
];
yield [[
__DIR__ . '/Fixture/UsedInUnionA.php', __DIR__ . '/Fixture/UsedInUnionB.php', __DIR__ . '/Source/UsedInUnionPhpdoc.php'],
[],
];
yield [[
__DIR__ . '/Fixture/StaticUsedInUnionA.php', __DIR__ . '/Fixture/StaticUsedInUnionB.php', __DIR__ . '/Source/StaticUsedInUnion.php'],
[],
];

}

Expand Down

0 comments on commit 6d5d529

Please sign in to comment.