mirror of
https://github.com/opencultureconsulting/oai-pmh2.git
synced 2025-03-30 00:00:30 +01:00
Update PHPstan and fix new issues
This commit is contained in:
parent
c983820539
commit
373104fff4
@ -11,12 +11,18 @@
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/cleancode.xml">
|
||||
<!--
|
||||
We want boolean flags for optional features of some methods.
|
||||
-->
|
||||
<exclude name="BooleanArgumentFlag" />
|
||||
<!--
|
||||
We sometimes want to use else expressions for better readability.
|
||||
-->
|
||||
<exclude name="ElseExpression" />
|
||||
<!--
|
||||
We need to statically access third-party helpers from Symfony.
|
||||
-->
|
||||
<exclude name="StaticAccess" />
|
||||
<exclude name="BooleanArgumentFlag" />
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml" />
|
||||
<rule ref="rulesets/controversial.xml" />
|
||||
|
@ -50,13 +50,15 @@
|
||||
"require-dev": {
|
||||
"phpdocumentor/shim": "^3.7",
|
||||
"phpmd/phpmd": "^2.15",
|
||||
"phpstan/phpstan": "^1.12",
|
||||
"phpstan/phpstan-doctrine": "^1.5",
|
||||
"phpstan/phpstan-strict-rules": "^1.6",
|
||||
"phpstan/phpstan-symfony": "^1.4",
|
||||
"friendsofphp/php-cs-fixer": "^3.71",
|
||||
"squizlabs/php_codesniffer": "^3.11",
|
||||
"vimeo/psalm": "^5.26"
|
||||
"phpstan/phpstan": "^2.1",
|
||||
"phpstan/phpstan-doctrine": "^2.0",
|
||||
"phpstan/phpstan-strict-rules": "^2.0",
|
||||
"phpstan/phpstan-symfony": "^2.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.73",
|
||||
"squizlabs/php_codesniffer": "^3.12",
|
||||
"vimeo/psalm": "^6.9",
|
||||
"psalm/plugin-symfony": "^5.2",
|
||||
"weirdan/doctrine-psalm-plugin": "^2.10"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
2197
composer.lock
generated
2197
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,7 @@
|
||||
findUnusedBaselineEntry="true"
|
||||
findUnusedCode="true"
|
||||
findUnusedVariablesAndParams="true"
|
||||
memoizeMethodCallResults="true"
|
||||
reportMixedIssues="false"
|
||||
>
|
||||
<issueHandlers>
|
||||
@ -61,4 +62,8 @@
|
||||
<directory name="vendor"/>
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
<plugins>
|
||||
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
|
||||
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
|
||||
</plugins>
|
||||
</psalm>
|
||||
|
@ -38,7 +38,7 @@ use Symfony\Component\Yaml\Yaml;
|
||||
* @property-read string $repositoryName Common name of this repository
|
||||
* @property-read string $adminEmail Repository contact's e-mail address
|
||||
* @property-read string $database Database's data source name (DSN)
|
||||
* @property-read array $metadataPrefix Array of served metadata prefixes
|
||||
* @property-read array<string, array<string, string>> $metadataPrefix Array of served metadata prefixes
|
||||
* @property-read string $deletedRecords Repository's deleted records policy
|
||||
* @property-read int $maxRecords Maximum number of records served per request
|
||||
* @property-read int $tokenValid Number of seconds resumption tokens are valid
|
||||
|
@ -139,30 +139,36 @@ class CsvImportCommand extends Console
|
||||
$progressIndicator = new ProgressIndicator($output, null, 100, ['⠏', '⠛', '⠹', '⢸', '⣰', '⣤', '⣆', '⡇']);
|
||||
$progressIndicator->start('Importing...');
|
||||
|
||||
while ($row = fgetcsv($file)) {
|
||||
/** @var Format */
|
||||
$format = $this->em->getMetadataFormat($this->arguments['format']);
|
||||
$record = new Record($row[$columnMapping['idColumn']], $format);
|
||||
if (strlen(trim($row[$columnMapping['contentColumn']])) > 0) {
|
||||
$record->setContent($row[$columnMapping['contentColumn']], !$this->arguments['noValidation']);
|
||||
}
|
||||
if (isset($columnMapping['dateColumn'])) {
|
||||
$record->setLastChanged(new DateTime($row[$columnMapping['dateColumn']]));
|
||||
}
|
||||
if (isset($columnMapping['setColumn'])) {
|
||||
$sets = $row[$columnMapping['setColumn']];
|
||||
foreach (explode(',', $sets) as $set) {
|
||||
/** @var Set */
|
||||
$setSpec = $this->em->getSet(trim($set));
|
||||
$record->addSet($setSpec);
|
||||
while ($row = fgetcsv($file, null, ",", "\"", "\\")) {
|
||||
if (!is_null($row[0])) {
|
||||
/** @var Format */
|
||||
$format = $this->em->getMetadataFormat($this->arguments['format']);
|
||||
/** @phpstan-ignore-next-line - see https://github.com/phpstan/phpstan/issues/12195 */
|
||||
$record = new Record($row[$columnMapping['idColumn']], $format);
|
||||
/** @phpstan-ignore-next-line - see https://github.com/phpstan/phpstan/issues/12195 */
|
||||
if (strlen(trim($row[$columnMapping['contentColumn']])) > 0) {
|
||||
$record->setContent($row[$columnMapping['contentColumn']], !$this->arguments['noValidation']);
|
||||
}
|
||||
}
|
||||
$this->em->addOrUpdate($record, true);
|
||||
if (isset($columnMapping['dateColumn'])) {
|
||||
/** @phpstan-ignore-next-line - see https://github.com/phpstan/phpstan/issues/12195 */
|
||||
$record->setLastChanged(new DateTime($row[$columnMapping['dateColumn']]));
|
||||
}
|
||||
if (isset($columnMapping['setColumn'])) {
|
||||
$sets = $row[$columnMapping['setColumn']];
|
||||
/** @phpstan-ignore-next-line - see https://github.com/phpstan/phpstan/issues/12195 */
|
||||
foreach (explode(',', $sets) as $set) {
|
||||
/** @var Set */
|
||||
$setSpec = $this->em->getSet(trim($set));
|
||||
$record->addSet($setSpec);
|
||||
}
|
||||
}
|
||||
$this->em->addOrUpdate($record, true);
|
||||
|
||||
++$count;
|
||||
$progressIndicator->advance();
|
||||
$progressIndicator->setMessage('Importing... ' . (string) $count . ' records processed.');
|
||||
$this->checkMemoryUsage();
|
||||
++$count;
|
||||
$progressIndicator->advance();
|
||||
$progressIndicator->setMessage('Importing... ' . (string) $count . ' records processed.');
|
||||
$this->checkMemoryUsage();
|
||||
}
|
||||
}
|
||||
$this->em->flush();
|
||||
$this->em->pruneOrphanedSets();
|
||||
@ -204,20 +210,19 @@ class CsvImportCommand extends Console
|
||||
'setColumn' => $input->getOption('setColumn')
|
||||
];
|
||||
|
||||
$headers = fgetcsv($file);
|
||||
if (!is_array($headers) || !isset($headers[0])) {
|
||||
$headers = fgetcsv($file, null, ",", "\"", "\\");
|
||||
if (!is_array($headers) || is_null($headers[0])) {
|
||||
$output->writeln([
|
||||
'',
|
||||
sprintf(
|
||||
' [ERROR] File "%s" does not contain valid CSV. ',
|
||||
/** @phpstan-ignore-next-line - URI is always set for fopen() resources. */
|
||||
stream_get_meta_data($file)['uri'] ?: 'unknown'
|
||||
stream_get_meta_data($file)['uri'] ?? 'unknown'
|
||||
),
|
||||
''
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
/** @var array<string, int> */
|
||||
/** @phpstan-ignore-next-line - see https://github.com/phpstan/phpstan/issues/12195 */
|
||||
$headers = array_flip($headers);
|
||||
|
||||
$callback = function (string $column) use ($headers): ?int {
|
||||
@ -231,8 +236,7 @@ class CsvImportCommand extends Console
|
||||
'',
|
||||
sprintf(
|
||||
' [ERROR] File "%s" does not contain mandatory columns. ',
|
||||
/** @phpstan-ignore-next-line - URI is always set for fopen() resources. */
|
||||
stream_get_meta_data($file)['uri'] ?: 'unknown'
|
||||
stream_get_meta_data($file)['uri'] ?? 'unknown'
|
||||
),
|
||||
''
|
||||
]);
|
||||
|
@ -53,17 +53,16 @@ class UpdateFormatsCommand extends Console
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
/** @var array<string, array<string, string>> */
|
||||
$formats = Configuration::getInstance()->metadataPrefix;
|
||||
$this->clearResultCache();
|
||||
$inDatabase = $this->em->getMetadataFormats();
|
||||
$failure = false;
|
||||
foreach ($formats as $prefix => $format) {
|
||||
if (
|
||||
$inDatabase->containsKey(key: $prefix)
|
||||
/** @phpstan-ignore-next-line - $inDatabase[$prefix] is always of type Format. */
|
||||
$inDatabase->containsKey($prefix)
|
||||
/** @phpstan-ignore-next-line - see line 62 */
|
||||
and $format['namespace'] === $inDatabase[$prefix]->getNamespace()
|
||||
/** @phpstan-ignore-next-line - $inDatabase[$prefix] is always of type Format. */
|
||||
/** @phpstan-ignore-next-line - see line 62 */
|
||||
and $format['schema'] === $inDatabase[$prefix]->getSchema()
|
||||
) {
|
||||
continue;
|
||||
|
@ -179,8 +179,7 @@ class Record extends Entity
|
||||
*
|
||||
* @return bool TRUE if content exists, FALSE otherwise
|
||||
*
|
||||
* @psalm-assert-if-true string $this->content
|
||||
* @psalm-assert-if-true string $this->getContent()
|
||||
* @phpstan-assert-if-true !null $this->getContent()
|
||||
*/
|
||||
public function hasContent(): bool
|
||||
{
|
||||
|
@ -131,8 +131,7 @@ class Set extends Entity
|
||||
*
|
||||
* @return bool TRUE if description exists, FALSE otherwise
|
||||
*
|
||||
* @psalm-assert-if-true string $this->description
|
||||
* @psalm-assert-if-true string $this->getDescription()
|
||||
* @phpstan-assert-if-true !null $this->getDescription()
|
||||
*/
|
||||
public function hasDescription(): bool
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ use Symfony\Component\Filesystem\Path;
|
||||
* @mixin DoctrineEntityManager
|
||||
*
|
||||
* @psalm-import-type Params from DriverManager
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
|
||||
*/
|
||||
final class EntityManager extends EntityManagerDecorator
|
||||
{
|
||||
@ -431,8 +431,6 @@ final class EntityManager extends EntityManagerDecorator
|
||||
'sqlite' => 'pdo_sqlite'
|
||||
]);
|
||||
$conn = DriverManager::getConnection(
|
||||
// Generic return type of DsnParser::parse() is not correctly recognized.
|
||||
// phpcs:ignore
|
||||
$parser->parse($dsn),
|
||||
$config
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user