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
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, sodium
coverage: pcov

- name: Setup problem matchers
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"require": {
"php": "^8.3",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan": "^2.1.13",
"php-standard-library/php-standard-library": "^4.0 || ^5.0 || ^6.0"
},
"require-dev": {
Expand Down
10 changes: 5 additions & 5 deletions src/Rules/RestrictImplicitDependencyUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ private function getInstalledJson(): array
'name' => Type\string(),
'autoload' => Type\optional(Type\shape([
'psr-4' => Type\optional(Type\dict(Type\string(), Type\union(Type\string(), Type\vec(Type\string())))),
], allowUnknownFields: true)),
], true)),
'replace' => Type\optional(Type\dict(Type\string(), Type\string())),
], allowUnknownFields: true)),
], allowUnknownFields: true)->assert(decode(read(basepath() . '/vendor/composer/installed.json')));
], true)),
], true)->assert(decode(read(basepath() . '/vendor/composer/installed.json')));
}

/**
Expand All @@ -249,7 +249,7 @@ private function getComposerJson(): array
'require-dev' => Type\optional(Type\dict(Type\string(), Type\string())),
'autoload' => Type\optional(Type\shape([
'psr-4' => Type\optional(Type\dict(Type\string(), Type\union(Type\string(), Type\vec(Type\string())))),
], allowUnknownFields: true)),
], allowUnknownFields: true)->assert(decode(read('composer.json')));
], true)),
], true)->assert(decode(read('composer.json')));
}
}
1 change: 1 addition & 0 deletions src/Rules/StrictComparisonOfObjectsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function processNode(Node $node, Scope $scope): array
$rightTypeDescription,
$expectedType->describe(VerbosityLevel::typeOnly())
))
->identifier('superscript.strictComparisonOfObjects')
->build(),
];
}
Expand Down
6 changes: 5 additions & 1 deletion src/basepath.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function basepath(): ?string
{
$real_path = realpath(__DIR__);

if ($real_path === false) {
return null;
}

preg_match(
"/.+\b(vendor\/.+)/",
$real_path,
Expand All @@ -30,7 +34,7 @@ function basepath(): ?string

$project_path = realpath(__DIR__ . DIRECTORY_SEPARATOR . $out);

if ( !file_exists($project_path . DIRECTORY_SEPARATOR . "composer.json") ) {
if ( $project_path === false || !file_exists($project_path . DIRECTORY_SEPARATOR . "composer.json") ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Psl\Collection\Vector;
use Superscript\PHPStanRules\Rules\RestrictImplicitDependencyUsage;

final class RestrictImplicitDependencyUsageTest extends PHPStanTestCase
Expand Down Expand Up @@ -65,6 +64,9 @@ public function it_can_be_restricted(string $class): void

public static function restrictedCases(): \Generator
{
yield 'class from undefined package' => [\Psl\Collection\Vector::class];
// sebastian/diff is installed transitively (via phpunit) but not
// declared in this package's composer.json, so a class from its
// namespace must be flagged as an implicit-dependency usage.
yield 'class from undefined package' => [\SebastianBergmann\Diff\Differ::class];
}
}
Loading