mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-10 13:15:18 +02:00
Improved typing and phpdoc type annotations
This commit is contained in:
parent
3817ba774d
commit
b7c8ca2a48
39 changed files with 189 additions and 129 deletions
|
@ -45,7 +45,10 @@ class BigNumberNormalizer implements NormalizerInterface
|
|||
return (string) $object;
|
||||
}
|
||||
|
||||
public function getSupportedTypes(?string $format)
|
||||
/**
|
||||
* @return bool[]
|
||||
*/
|
||||
public function getSupportedTypes(?string $format): array
|
||||
{
|
||||
return [
|
||||
BigNumber::class => true,
|
||||
|
|
|
@ -68,7 +68,12 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface
|
|||
return $data instanceof Part;
|
||||
}
|
||||
|
||||
public function normalize($object, string $format = null, array $context = []): array
|
||||
/**
|
||||
* @return (float|mixed)[]|\ArrayObject|null|scalar
|
||||
*
|
||||
* @psalm-return \ArrayObject|array{total_instock: float|mixed,...}|null|scalar
|
||||
*/
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if (!$object instanceof Part) {
|
||||
throw new \InvalidArgumentException('This normalizer only supports Part objects!');
|
||||
|
@ -178,7 +183,10 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface
|
|||
return $object;
|
||||
}
|
||||
|
||||
public function getSupportedTypes(?string $format)
|
||||
/**
|
||||
* @return bool[]
|
||||
*/
|
||||
public function getSupportedTypes(?string $format): array
|
||||
{
|
||||
//Must be false, because we rely on is_array($data) in supportsDenormalization()
|
||||
return [
|
||||
|
|
|
@ -42,7 +42,12 @@ class StructuralElementFromNameDenormalizer implements DenormalizerInterface
|
|||
return is_string($data) && is_subclass_of($type, AbstractStructuralDBElement::class);
|
||||
}
|
||||
|
||||
public function denormalize($data, string $type, string $format = null, array $context = []): ?AbstractStructuralDBElement
|
||||
/**
|
||||
* @template T
|
||||
* @phpstan-param class-string<T> $type
|
||||
* @phpstan-return T|null
|
||||
*/
|
||||
public function denormalize($data, string $type, string $format = null, array $context = []): AbstractStructuralDBElement|null
|
||||
{
|
||||
//Retrieve the repository for the given type
|
||||
/** @var StructuralDBElementRepository $repo */
|
||||
|
@ -69,7 +74,10 @@ class StructuralElementFromNameDenormalizer implements DenormalizerInterface
|
|||
return end($elements);
|
||||
}
|
||||
|
||||
public function getSupportedTypes(?string $format)
|
||||
/**
|
||||
* @return bool[]
|
||||
*/
|
||||
public function getSupportedTypes(?string $format): array
|
||||
{
|
||||
//Cachable value Must be false, because we do an is_string check on data in supportsDenormalization
|
||||
return [
|
||||
|
|
|
@ -46,7 +46,10 @@ class StructuralElementNormalizer implements NormalizerInterface
|
|||
return $data instanceof AbstractStructuralDBElement;
|
||||
}
|
||||
|
||||
public function normalize($object, string $format = null, array $context = []): array
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if (!$object instanceof AbstractStructuralDBElement) {
|
||||
throw new \InvalidArgumentException('This normalizer only supports AbstractStructural objects!');
|
||||
|
@ -64,7 +67,10 @@ class StructuralElementNormalizer implements NormalizerInterface
|
|||
return $data;
|
||||
}
|
||||
|
||||
public function getSupportedTypes(?string $format)
|
||||
/**
|
||||
* @return bool[]
|
||||
*/
|
||||
public function getSupportedTypes(?string $format): array
|
||||
{
|
||||
return [
|
||||
AbstractStructuralDBElement::class => true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue