Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 29, 2024
1 parent e96d688 commit 353e482
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 42 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]);
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
"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",
"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"
},
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
5 changes: 2 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,10 +59,10 @@ 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);
Expand Down
8 changes: 4 additions & 4 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 @@ -63,10 +63,10 @@ public function processNode(Node $node, Scope $scope): ?array
$classType = $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);
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 353e482

Please sign in to comment.