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

phpstan-dba: improve coverage #1232

Closed
wants to merge 12 commits into from
Closed
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"phpstan/phpstan-doctrine": "^1",
"phpstan/phpstan-symfony": "^1.1",
"phpunit/phpunit": "^9.5",
"staabm/phpstan-dba": "^0.2",
"staabm/phpstan-dba": "dev-main",
"symfony/browser-kit": "^5.2",
"symfony/css-selector": "^5.2",
"symfony/debug-bundle": "^5.2",
Expand Down
161 changes: 84 additions & 77 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion phpstan-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// phpstan-dba
$cacheFile = __DIR__.'/.phpstan-dba.cache';
$config = new RuntimeConfiguration();
// $config->debugMode(true);
$config->debugMode(true);

(new Dotenv())->bootEnv(__DIR__ . '/.env');
$dsn = parse_url($_SERVER['DATABASE_URL']);
Expand Down
3 changes: 3 additions & 0 deletions src/Command/IndexPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ private function getTags(Package $package): array
}, $tags)));
}

/**
* @param int[] $idsToUpdate
*/
private function updateIndexedAt(array $idsToUpdate, string $time)
{
$retries = 5;
Expand Down
8 changes: 8 additions & 0 deletions src/Entity/PackageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ public function getDependents(string $name, int $offset = 0, int $limit = 15, st
return $this->getEntityManager()->getConnection()->fetchAllAssociative($sql, $args);
Copy link
Member

Choose a reason for hiding this comment

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

Interesting failure here, it seems to pick up the conditional d.total usage but not the join declaring it? TBH this is quite messy code and I don't expect perfect handling here, but it should at least ignore it rather than error I guess.

Copy link
Author

Choose a reason for hiding this comment

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

will investigate in staabm/phpstan-dba#188

Copy link
Member

Choose a reason for hiding this comment

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

Cool, no rush, glad to provide this repo as playground :) I have another project with hundreds of pure SQL queries I could run the extension on once it matured a bit, but sadly it's private.

}

/**
* @param string $name
*/
public function getSuggestCount($name): int
{
$sql = 'SELECT COUNT(*) count FROM suggester WHERE packageName = :name';
Expand All @@ -477,6 +480,11 @@ public function getSuggestCount($name): int
return (int) $this->getEntityManager()->getConnection()->fetchOne($sql, $args);
}

/**
* @param string $name
* @param int $offset
* @param int $limit
Copy link
Contributor

Choose a reason for hiding this comment

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

you could use actual parameter types rather than phpdoc

Copy link
Member

Choose a reason for hiding this comment

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

Yes please go wild with PHP 8 syntax in this repo 😄

*/
public function getSuggests($name, $offset = 0, $limit = 15)
{
$sql = 'SELECT p.id, p.name, p.description, p.language, p.abandoned, p.replacementPackage
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/SecurityAdvisoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function getPackageSecurityAdvisories(string $name): array
->fetchAllAssociative($sql, ['name' => $name]);
}

/**
* @param string[] $packageNames
*/
public function searchSecurityAdvisories(array $packageNames, int $updatedSince): array
{
$sql = 'SELECT s.packagistAdvisoryId as advisoryId, s.packageName, s.remoteId, s.title, s.link, s.cve, s.affectedVersions, s.source, s.reportedAt, s.composerRepository
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/VersionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public function detachToArray(array $versions, array $versionData, bool $seriali
return $res;
}

/**
* @param int[] $versionIds
*/
public function getVersionData(array $versionIds)
{
$links = [
Expand Down
4 changes: 2 additions & 2 deletions src/Package/SymlinkDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public function __construct(ManagerRegistry $doctrine, Filesystem $filesystem, U
* Dump a set of packages to the web root
*
* @param int[] $packageIds
* @param Boolean $force
* @param Boolean $verbose
* @param boolean $force
* @param boolean $verbose
*/
public function dump(array $packageIds, $force = false, $verbose = false)
{
Expand Down
11 changes: 6 additions & 5 deletions src/Package/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,12 @@ public function update(IOInterface $io, Config $config, Package $package, VcsRep
}

/**
* @return array with keys:
* - updated (whether the version was updated or needs to be marked as updated)
* - id (version id, can be null for newly created versions)
* - version (normalized version from the composer package)
* - object (Version instance if it was updated)
* @return array{updated: true, id: int|null, version: string, object: Version}|array{updated: false, id: int|null, version: string, object: null}
*
* - updated (whether the version was updated or needs to be marked as updated)
* - id (version id, can be null for newly created versions)
* - version (normalized version from the composer package)
* - object (Version instance if it was updated)
*/
private function updateInformation(IOInterface $io, VersionRepository $versionRepo, Package $package, array $existingVersions, CompletePackageInterface $data, $flags, $rootIdentifier)
{
Expand Down