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