Skip to content

Commit

Permalink
Upgrade to Psalm 5.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed May 2, 2024
1 parent 46248db commit e9c7fbd
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require-dev": {
"ext-pdo": "*",
"phpunit/phpunit": "^9.0",
"vimeo/psalm": "4.2.1"
"vimeo/psalm": "5.24.0"
},
"autoload": {
"psr-4": {
Expand Down
36 changes: 36 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.24.0@462c80e31c34e58cc4f750c656be3927e80e550e">
<file src="src/Gateway.php">
<MixedInferredReturnType>
<code><![CDATA[array<string, mixed>]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$result]]></code>
</MixedReturnStatement>
<MixedReturnTypeCoercion>
<code><![CDATA[[$tableAlias, $propertyMapping]]]></code>
<code><![CDATA[array{string, PropertyMapping}]]></code>
</MixedReturnTypeCoercion>
</file>
<file src="src/IdentityMap.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$ref = & $this->entities[$class]]]></code>
<code><![CDATA[$ref = & $this->entities[$class]]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="src/PropertyMapping/BoolMapping.php">
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$values[0]]]></code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="src/PropertyMapping/IntMapping.php">
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$values[0]]]></code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="src/PropertyMapping/StringMapping.php">
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$values[0]]]></code>
</PossiblyUndefinedArrayOffset>
</file>
</files>
4 changes: 3 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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"
errorBaseline="psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand All @@ -15,7 +18,6 @@
</ignoreFiles>
</projectFiles>


<issueHandlers>
<MissingConstructor>
<errorLevel type="suppress">
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function getCustomPropertyMappings() : array
*/
public function setTransientProperties(string $class, string ...$properties) : Configuration
{
$this->transientProperties[$class] = $properties;
$this->transientProperties[$class] = array_values($properties);

return $this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/EntityConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public function setIdentityProperties(string ...$identityProperties) : EntityCon
throw new \InvalidArgumentException('The list of identity properties cannot be empty.');
}

$identityProperties = array_values($identityProperties);

$this->checkProperties($identityProperties);

$this->identityProperties = $identityProperties;
Expand Down
3 changes: 2 additions & 1 deletion src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public function hydrate(object $entity, int $options = 0, string ...$props) : vo
$class = $this->getEntityClass($entity);
$identity = $this->getIdentity($class, $entity);

$props = array_values($props);
$values = $this->loadProps($class, $identity, $props, $options);

if ($values === null) {
Expand Down Expand Up @@ -492,7 +493,7 @@ private function doFind(Query $query, int $options = 0) : array
} else {
$expressionsAndOutputValues = $propertyMapping->convertPropToFields($value);

foreach ($fieldNames as $fieldNameIndex => $fieldName) {
foreach ($fieldNames as $fieldNameIndex => $_) {
foreach ($expressionsAndOutputValues[$fieldNameIndex] as $index => $expressionOrValue) {
if ($index === 0) {
/** @var string $expressionOrValue */
Expand Down
12 changes: 4 additions & 8 deletions src/ObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function instantiate(ClassMetadata $classMetadata, array $values = []) :

$object = $reflectionClass->newInstanceWithoutConstructor();

/** @psalm-suppress PossiblyInvalidFunctionCall bindTo() should never return false here */
/** @psalm-suppress PossiblyNullFunctionCall bindTo() should never return null here */
(function() use ($classMetadata, $values, $reflectionClass) {
// Unset persistent properties
// @todo PHP 7.4: for even better performance, only unset typed properties that have a default value, as
Expand All @@ -79,7 +79,6 @@ public function instantiate(ClassMetadata $classMetadata, array $values = []) :
// @todo temporary fix: do not set null values when typed property is not nullable;
// needs investigation to see why these null values are being passed in the first place

/** @var \ReflectionType|null $reflectionType */
$reflectionType = $reflectionClass->getProperty($key)->getType();

if ($reflectionType !== null && ! $reflectionType->allowsNull()) {
Expand Down Expand Up @@ -221,11 +220,8 @@ private function getPropertyValueConverter(\ReflectionProperty $property) : Clos
throw new \InvalidArgumentException(sprintf('Expected array for property $%s of class %s, got %s.', $propertyName, $className, gettype($value)));
}

/** @psalm-var class-string $typeName */
$typeName = $type->getName();

/** @psalm-var array<string, mixed> $value */
return $this->instantiateDTO($typeName, $value);
return $this->instantiateDTO($type->getName(), $value);
};
}

Expand All @@ -249,7 +245,7 @@ private function getPropertyValueConverter(\ReflectionProperty $property) : Clos
*/
public function read(object $object) : array
{
/** @psalm-suppress PossiblyInvalidFunctionCall bindTo() should never return false here */
/** @psalm-suppress PossiblyNullFunctionCall bindTo() should never return null here */
return (function() {
return get_object_vars($this);
})->bindTo($object, $object)();
Expand All @@ -267,7 +263,7 @@ public function read(object $object) : array
*/
public function write(object $object, array $values) : void
{
/** @psalm-suppress PossiblyInvalidFunctionCall bindTo() should never return false here */
/** @psalm-suppress PossiblyNullFunctionCall bindTo() should never return null here */
(function() use ($values) {
foreach ($values as $key => $value) {
$this->{$key} = $value;
Expand Down
9 changes: 5 additions & 4 deletions src/PropertyMapping/EmbeddableMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ public function convertPropToFields(mixed $propValue) : array
/** @var object|null $entity */
$entity = $propValue;

if ($entity !== null) {
$r = new \ReflectionObject($entity);
}
$r = null;

foreach ($this->classMetadata->properties as $prop) {
if ($entity === null) {
$idPropValue = null;
} else {
/** @psalm-var ReflectionObject $r */
if ($r === null) {
$r = new ReflectionObject($entity);
}

$p = $r->getProperty($prop);
$idPropValue = $p->getValue($entity);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyMapping/EntityMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function convertPropToFields(mixed $propValue) : array
$identity = [];

if ($entity !== null) {
/** @psalm-suppress PossiblyInvalidFunctionCall bindTo() should never return false here */
/** @psalm-suppress PossiblyNullFunctionCall bindTo() should never return null here */
(function() use ($idProperties, & $identity) {
foreach ($idProperties as $prop) {
$identity[$prop] = $this->{$prop};
Expand Down
2 changes: 1 addition & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(string $className)

public function setProperties(string ...$properties) : Query
{
$this->properties = $properties;
$this->properties = array_values($properties);

return $this;
}
Expand Down

0 comments on commit e9c7fbd

Please sign in to comment.