Skip to content

Commit

Permalink
Merge pull request #42 from driehle/feature/psalm-level-3
Browse files Browse the repository at this point in the history
Lowered Psalm level to 3
  • Loading branch information
driehle authored Nov 5, 2021
2 parents 91bb599 + c2875d0 commit f35233f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
33 changes: 17 additions & 16 deletions src/DoctrineObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use function is_int;
use function is_object;
use function is_string;
use function ltrim;
use function method_exists;
use function property_exists;
use function sprintf;
Expand All @@ -58,10 +57,10 @@ class DoctrineObject extends AbstractHydrator
/** @var bool */
protected $byValue = true;

/** @var string */
/** @var class-string<Strategy\AbstractCollectionStrategy> */
protected $defaultByValueStrategy = AllowRemoveByValue::class;

/** @var string */
/** @var class-string<Strategy\AbstractCollectionStrategy> */
protected $defaultByReferenceStrategy = AllowRemoveByReference::class;

/** @var Inflector */
Expand All @@ -79,15 +78,15 @@ public function __construct(ObjectManager $objectManager, $byValue = true, ?Infl
}

/**
* @return string
* @return class-string<Strategy\AbstractCollectionStrategy>
*/
public function getDefaultByValueStrategy()
{
return $this->defaultByValueStrategy;
}

/**
* @param string $defaultByValueStrategy
* @param class-string<Strategy\AbstractCollectionStrategy> $defaultByValueStrategy
*
* @return $this
*/
Expand All @@ -99,15 +98,15 @@ public function setDefaultByValueStrategy($defaultByValueStrategy)
}

/**
* @return string
* @return class-string<Strategy\AbstractCollectionStrategy>
*/
public function getDefaultByReferenceStrategy()
{
return $this->defaultByReferenceStrategy;
}

/**
* @param string $defaultByReferenceStrategy
* @param class-string<Strategy\AbstractCollectionStrategy> $defaultByReferenceStrategy
*
* @return $this
*/
Expand Down Expand Up @@ -351,6 +350,7 @@ protected function hydrateByValue(array $data, $object)

if ($metadata->hasAssociation($field)) {
$target = $metadata->getAssociationTargetClass($field);
assert($target !== null);

if ($metadata->isSingleValuedAssociation($field)) {
if (! is_callable([$object, $setter])) {
Expand Down Expand Up @@ -420,6 +420,7 @@ protected function hydrateByReference(array $data, $object)

if ($metadata->hasAssociation($field)) {
$target = $metadata->getAssociationTargetClass($field);
assert($target !== null);

if ($metadata->isSingleValuedAssociation($field)) {
$value = $this->toOne($target, $this->hydrateValue($field, $value, $data));
Expand Down Expand Up @@ -482,8 +483,8 @@ protected function tryConvertArrayToObject($data, $object)
* and a target instance will be initialized and then hydrated. The hydrated
* target will be returned.
*
* @param string $target
* @param mixed $value
* @param class-string $target
* @param mixed $value
*
* @return object|null
*/
Expand Down Expand Up @@ -511,16 +512,16 @@ protected function toOne($target, $value)
* strategies that inherit from AbstractCollectionStrategy class, and that add or remove elements but without
* changing the collection of the object
*
* @param object $object
* @param mixed $collectionName
* @param string $target
* @param mixed $values
* @param object $object
* @param mixed $collectionName
* @param class-string $target
* @param mixed $values
*
* @throws InvalidArgumentException
*/
protected function toMany($object, $collectionName, $target, $values)
{
$metadata = $this->objectManager->getClassMetadata(ltrim($target, '\\'));
$metadata = $this->objectManager->getClassMetadata($target);
$identifier = $metadata->getIdentifier();

if (! is_array($values) && ! $values instanceof Traversable) {
Expand Down Expand Up @@ -608,8 +609,8 @@ static function ($item) {
*
* @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#doctrine-mapping-types
*
* @param mixed $value
* @param string $typeOfField
* @param mixed $value
* @param ?string $typeOfField
*
* @return mixed|null
*/
Expand Down

0 comments on commit f35233f

Please sign in to comment.