Skip to content

Commit

Permalink
chore: Fix static analysis issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Jan 13, 2024
1 parent 75b97b8 commit c2bc215
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* refactor: Refactor exception.
* feat: Add attribute matching.
* refactor: Simplify object caching.
* refactor: Remove `$context` from `MapperInterface`
* chore: Fix static analysis issues.

## 0.5.4

Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ parameters:
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
reportMaybesInPropertyPhpDocTypes: true
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '#with type mixed is not subtype of native type mixed#'
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/bnf/phpstan-psr-container/extension.neon
- vendor/ekino/phpstan-banned-code/extension.neon
- vendor/dave-liddament/phpstan-php-language-extensions/extension.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
13 changes: 11 additions & 2 deletions src/Transformer/Model/TraversableCountableWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ public function getIterator(): \Traversable
return $this->traversable;
}

/**
* @return int<0,max>
*/
public function count(): int
{
if (is_int($this->countable)) {
return $this->countable;
$result = $this->countable;
} else {
$result = $this->countable->count();
}

if ($result < 0) {
throw new \LogicException('Countable must return positive integer.');
}

return $this->countable->count();
return $result;
}
}
4 changes: 1 addition & 3 deletions tests/Fixtures/MethodMapper/ObjectWithArrayPropertyDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ public static function mapFromObject(

$result = new self();

/** @var array<int,ObjectWithScalarPropertiesDto>|null $property */
$property = $mapper->mapForProperty(
$source->property,
ObjectWithArrayPropertyDto::class,
'property',
$context
);

assert(is_array($property));

/** @psalm-suppress MixedPropertyTypeCoercion */
$result->property = $property;

return $result;
Expand Down

0 comments on commit c2bc215

Please sign in to comment.