Skip to content

Commit

Permalink
Merge pull request #277 from driehle/update/psalm
Browse files Browse the repository at this point in the history
Update to Psalm 5 an lower Psalm error level to 3
  • Loading branch information
driehle authored Aug 3, 2023
2 parents 53d15ff + 17010b3 commit 243d143
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"phpspec/prophecy-phpunit": "^2.0.2",
"phpstan/phpstan": "^1.10.26",
"phpunit/phpunit": "^9.6.10",
"vimeo/psalm": "^4.30.0"
"vimeo/psalm": "^5.14.1"
},
"suggest": {
"laminas/laminas-developer-tools": "laminas-developer-tools if you want to profile operations executed by the ODM during development",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ parameters:
- tests
ignoreErrors:
- '#Method class@anonymous/tests/Assets/CustomRepositoryFactory.*has parameter.*with no type specified#'
- '#defaultDocumentRepositoryClassName with type .* is not subtype of native type string#'
includes:
- vendor/jangregor/phpstan-prophecy/extension.neon
5 changes: 3 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
phpVersion="8.1"
errorLevel="3"
resolveFromConfigFile="true"
findUnusedBaselineEntry="false"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function init(ModuleManagerInterface $manager): void
$events->attach('profiler_init', static function (EventInterface $e) use ($manager): void {
$manager->getEvent()->getParam('ServiceManager')->get('doctrine.mongo_logger_collector.odm_default');
});
$events->getSharedManager()->attach('doctrine', 'loadCli.post', [$this, 'loadCli']);
$events->getSharedManager()?->attach('doctrine', 'loadCli.post', [$this, 'loadCli']);
}

public function loadCli(EventInterface $event): void
Expand Down
24 changes: 20 additions & 4 deletions src/Options/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace DoctrineMongoODMModule\Options;

use Doctrine\ODM\MongoDB\Configuration as MongoDbConfiguration;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository as DefaultDocumentRepository;
use Doctrine\Persistence\ObjectRepository;
use Laminas\Stdlib\AbstractOptions;

/**
Expand Down Expand Up @@ -73,11 +75,15 @@ final class Configuration extends AbstractOptions

/**
* Persistent collection factory service name.
*
* @var class-string|null
*/
protected string|null $persistentCollectionFactory = null;

/**
* Persistent collection generator service name.
*
* @var class-string|null
*/
protected string|null $persistentCollectionGenerator = null;

Expand All @@ -98,10 +104,13 @@ final class Configuration extends AbstractOptions
*/
protected string|null $logger = null;

/** @var class-string<ClassMetadataFactory>|null */
protected string|null $classMetadataFactoryName = null;

/** @var class-string|null */
protected string|null $repositoryFactory = null;

/** @var class-string<ObjectRepository<object>>|null */
protected string $defaultDocumentRepositoryClassName = DefaultDocumentRepository::class;

/**
Expand Down Expand Up @@ -255,6 +264,7 @@ public function getPersistentCollectionFactory(): string|null
return $this->persistentCollectionFactory;
}

/** @param class-string|null $persistentCollectionFactory */
public function setPersistentCollectionFactory(string|null $persistentCollectionFactory): self
{
$this->persistentCollectionFactory = $persistentCollectionFactory;
Expand All @@ -267,9 +277,10 @@ public function getPersistentCollectionGenerator(): string|null
return $this->persistentCollectionGenerator;
}

/** @param class-string|null $persistentCollectionGenerator */
public function setPersistentCollectionGenerator(string|null $persistentCollectionGenerator): self
{
$this->persistentCollectionGenerator = (string) $persistentCollectionGenerator;
$this->persistentCollectionGenerator = $persistentCollectionGenerator;

return $this;
}
Expand Down Expand Up @@ -312,14 +323,16 @@ public function getLogger(): string|null
return $this->logger;
}

/** @psalm-return class-string<ClassMetadataFactory>|null */
public function getClassMetadataFactoryName(): string|null
{
return $this->classMetadataFactoryName;
}

/** @param class-string<ClassMetadataFactory>|null $classMetadataFactoryName */
public function setClassMetadataFactoryName(string|null $classMetadataFactoryName): void
{
$this->classMetadataFactoryName = (string) $classMetadataFactoryName;
$this->classMetadataFactoryName = $classMetadataFactoryName;
}

/** @param mixed[] $types */
Expand All @@ -339,18 +352,21 @@ public function getRepositoryFactory(): string|null
return $this->repositoryFactory;
}

/** @param class-string|null $repositoryFactory */
public function setRepositoryFactory(string|null $repositoryFactory): Configuration
{
$this->repositoryFactory = (string) $repositoryFactory;
$this->repositoryFactory = $repositoryFactory;

return $this;
}

public function getDefaultDocumentRepositoryClassName(): string
/** @psalm-return class-string<ObjectRepository<object>> */
public function getDefaultDocumentRepositoryClassName(): string|null
{
return $this->defaultDocumentRepositoryClassName;
}

/** @param class-string<ObjectRepository<object>> $defaultDocumentRepositoryClassName */
public function setDefaultDocumentRepositoryClassName(string $defaultDocumentRepositoryClassName): self
{
$this->defaultDocumentRepositoryClassName = $defaultDocumentRepositoryClassName;
Expand Down
13 changes: 11 additions & 2 deletions src/Service/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@ public function getOptions(ContainerInterface $container, string $key, string|nu
);
}

$optionsClass = $this->getOptionsClass();
$optionsClass = $this->getOptionsClass();
$optionsObject = new $optionsClass($options);

if (! $optionsObject instanceof AbstractOptions) {
throw new RuntimeException(sprintf(
'Class %s must inherit from %s, but does not.',
$optionsClass,
AbstractOptions::class,
));
}

return new $optionsClass($options);
return $optionsObject;
}
}

0 comments on commit 243d143

Please sign in to comment.