Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"php-standard-library/str": "^6.1",
"php-standard-library/type": "^6.1",
"php-standard-library/vec": "^6.1",
"veewee/reflecta": "~0.16",
"veewee/reflecta": "^1.0.0",
"veewee/xml": "^4.10",
"php-soap/engine": "^2.20",
"php-soap/wsdl": "^1.19",
Expand Down
10 changes: 5 additions & 5 deletions src/Encoder/AnyElementEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
use function Psl\Type\vec;

/**
* @implements XmlEncoder<array|string|null, string>
* @implements XmlEncoder<array|string|null, array<array-key, string>|string|null, string, ElementList|string>
*
* @psalm-import-type LookupArray from DocumentToLookupArrayReader
*
* @template-implements Feature\ProvidesObjectDecoderLens<LookupArray, ElementList>
* @template-implements Feature\ProvidesObjectDecoderLens<LookupArray, LookupArray, ElementList, ElementList>
*/
final class AnyElementEncoder implements Feature\ListAware, Feature\OptionalAware, Feature\ProvidesObjectDecoderLens, XmlEncoder
{
Expand All @@ -32,7 +32,7 @@ final class AnyElementEncoder implements Feature\ListAware, Feature\OptionalAwar
* It will contain all the XML tags available in the object that is surrounding the 'any' property.
* Properties that are already known by the object, will be omitted.
*
* @return Lens<LookupArray, ElementList>
* @return Lens<LookupArray, LookupArray, ElementList, ElementList>
*/
public static function createObjectDecoderLens(Type $parentType, Property $currentProperty): Lens
{
Expand All @@ -51,7 +51,7 @@ public static function createObjectDecoderLens(Type $parentType, Property $curre
*/
$omit = static fn (array $data): array => diff_by_key($data, array_flip($omittedKeys));

/** @var Lens<LookupArray, ElementList> */
/** @var Lens<LookupArray, LookupArray, ElementList, ElementList> */
return Lens::readonly(
/**
* @psalm-suppress MixedArgumentTypeCoercion - Psalm gets confused about the result of omit.
Expand All @@ -62,7 +62,7 @@ public static function createObjectDecoderLens(Type $parentType, Property $curre
}

/**
* @return Iso<array|string|null, string>
* @return Iso<array|string|null, array<array-key, string>|string|null, string, ElementList|string>
*/
public function iso(Context $context): Iso
{
Expand Down
6 changes: 3 additions & 3 deletions src/Encoder/ElementEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
use VeeWee\Reflecta\Iso\Iso;

/**
* @implements XmlEncoder<mixed, string>
* @implements XmlEncoder<mixed, mixed, non-empty-string, Element|non-empty-string>
*/
final class ElementEncoder implements Feature\ElementAware, XmlEncoder
{
/**
* @param XmlEncoder<mixed, string> $typeEncoder
* @param XmlEncoder<mixed, mixed, string, string> $typeEncoder
*/
public function __construct(
private readonly XmlEncoder $typeEncoder
) {
}

/**
* @return Iso<mixed, string>
* @return Iso<mixed, mixed, non-empty-string, Element|non-empty-string>
*/
public function iso(Context $context): Iso
{
Expand Down
18 changes: 8 additions & 10 deletions src/Encoder/EncoderDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace Soap\Encoding\Encoder;

use Soap\Encoding\Cache\ScopedCache;
use Soap\Encoding\Xml\Node\Element;
use Soap\Encoding\Xml\Node\ElementList;
use Soap\Engine\Metadata\Model\XsdType;
use stdClass;

Expand All @@ -18,7 +20,7 @@ public static function default(): self
}

/**
* @return ScopedCache<XsdType, XmlEncoder<mixed, string>>
* @return ScopedCache<XsdType, XmlEncoder<mixed, mixed, string|null, Element|ElementList|string|null>>
*
* @psalm-suppress LessSpecificReturnStatement, MoreSpecificReturnType, MixedReturnStatement
*/
Expand All @@ -30,9 +32,7 @@ private static function cache(): ScopedCache
}

/**
* @return XmlEncoder<mixed, string>
*
* @psalm-suppress InvalidArgument, InvalidReturnType, PossiblyInvalidArgument, InvalidReturnStatement - The simple type detector could return string|null, but should not be an issue here.
* @return XmlEncoder<mixed, mixed, string|null, Element|ElementList|string|null>
*/
public function __invoke(Context $context): XmlEncoder
{
Expand All @@ -44,9 +44,7 @@ public function __invoke(Context $context): XmlEncoder
}

/**
* @return XmlEncoder<mixed, string>
*
* @psalm-suppress PossiblyInvalidArgument - The simple type detector could return string|null, but should not be an issue here.
* @return XmlEncoder<mixed, mixed, string|null, Element|ElementList|string|null>
*/
private function detect(Context $context): XmlEncoder
{
Expand All @@ -62,8 +60,8 @@ private function detect(Context $context): XmlEncoder
}

/**
* @param XmlEncoder<mixed, string> $encoder
* @return XmlEncoder<mixed, string>
* @param XmlEncoder<mixed, mixed, string|null, Element|ElementList|string|null> $encoder
* @return XmlEncoder<mixed, mixed, string|null, Element|ElementList|string|null>
*/
private function enhanceEncoder(Context $context, XmlEncoder $encoder): XmlEncoder
{
Expand All @@ -86,7 +84,7 @@ private function enhanceEncoder(Context $context, XmlEncoder $encoder): XmlEncod
}

/**
* @return XmlEncoder<mixed, string>
* @return XmlEncoder<mixed, mixed, string, Element|ElementList|string>
*/
private function detectComplexTypeEncoder(XsdType $type, Context $context): XmlEncoder
{
Expand Down
24 changes: 13 additions & 11 deletions src/Encoder/ErrorHandlingEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,43 @@
use VeeWee\Reflecta\Iso\Iso;

/**
* @template-covariant TData
* @template-covariant TXml
* @template TDataIn
* @template TDataOut
* @template TXmlOut
* @template TXmlIn
*
* @implements XmlEncoder<TData, TXml>
* @implements Feature\DecoratingEncoder<TData, TXml>
* @implements XmlEncoder<TDataIn, TDataOut, TXmlOut, TXmlIn>
* @implements Feature\DecoratingEncoder<TDataIn, TDataOut, TXmlOut, TXmlIn>
*/
final class ErrorHandlingEncoder implements Feature\DecoratingEncoder, XmlEncoder
{
/**
* @param XmlEncoder<TData, TXml> $encoder
* @param XmlEncoder<TDataIn, TDataOut, TXmlOut, TXmlIn> $encoder
*/
public function __construct(
private readonly XmlEncoder $encoder
) {
}

/**
* @return XmlEncoder<TData, TXml>
* @return XmlEncoder<TDataIn, TDataOut, TXmlOut, TXmlIn>
*/
public function decoratedEncoder(): XmlEncoder
{
return $this->encoder;
}

/**
* @return Iso<TData, TXml>
* @return Iso<TDataIn, TDataOut, TXmlOut, TXmlIn>
*/
public function iso(Context $context): Iso
{
$innerIso = $this->encoder->iso($context);

return new Iso(
/**
* @psalm-param TData $value
* @psalm-return TXml
* @psalm-param TDataIn $value
* @psalm-return TXmlOut
*/
static function (mixed $value) use ($innerIso, $context): mixed {
try {
Expand All @@ -52,8 +54,8 @@ static function (mixed $value) use ($innerIso, $context): mixed {
}
},
/**
* @psalm-param TXml $value
* @psalm-return TData
* @psalm-param TXmlIn $value
* @psalm-return TDataOut
*/
static function (mixed $value) use ($innerIso, $context): mixed {
try {
Expand Down
8 changes: 5 additions & 3 deletions src/Encoder/Feature/DecoratingEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Soap\Encoding\Encoder\XmlEncoder;

/**
* @template-covariant TData
* @template-covariant TXml
* @template-covariant TDataIn
* @template-covariant TDataOut
* @template-covariant TXmlOut
* @template-covariant TXmlIn
*/
interface DecoratingEncoder
{
/**
* @return XmlEncoder<TData, TXml>
* @return XmlEncoder<TDataIn, TDataOut, TXmlOut, TXmlIn>
*/
public function decoratedEncoder(): XmlEncoder;
}
10 changes: 6 additions & 4 deletions src/Encoder/Feature/ProvidesObjectDecoderLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

use Soap\Engine\Metadata\Model\Property;
use Soap\Engine\Metadata\Model\Type;
use VeeWee\Reflecta\Lens\Lens;
use VeeWee\Reflecta\Lens\LensInterface;

/**
* When an encoder implements this feature interface, it knows how to create a lens that will be applied on the parent data that is being decoded.
*
* @template-covariant S
* @template-covariant S of array<array-key, mixed>
* @template-covariant T of array<array-key, mixed>
* @template-covariant A
* @template-covariant B
*/
interface ProvidesObjectDecoderLens
{
/**
* @return Lens<S, A>
* @return LensInterface<S, T, A, B>
*/
public static function createObjectDecoderLens(Type $parentType, Property $currentProperty): Lens;
public static function createObjectDecoderLens(Type $parentType, Property $currentProperty): LensInterface;
}
10 changes: 6 additions & 4 deletions src/Encoder/Feature/ProvidesObjectEncoderLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

use Soap\Engine\Metadata\Model\Property;
use Soap\Engine\Metadata\Model\Type;
use VeeWee\Reflecta\Lens\Lens;
use VeeWee\Reflecta\Lens\LensInterface;

/**
* When an encoder implements this feature interface, it knows how to create a lens that will be applied on the parent data that is being encoded.
*
* @template-covariant S
* @template-covariant S of object
* @template-covariant T of object
* @template-covariant A
* @template-covariant B
*/
interface ProvidesObjectEncoderLens
{
/**
* @return Lens<S, A>
* @return LensInterface<S, T, A, B>
*/
public static function createObjectEncoderLens(Type $parentType, Property $currentProperty): Lens;
public static function createObjectEncoderLens(Type $parentType, Property $currentProperty): LensInterface;
}
14 changes: 8 additions & 6 deletions src/Encoder/FixedIsoEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

namespace Soap\Encoding\Encoder;

use VeeWee\Reflecta\Iso\Iso;
use VeeWee\Reflecta\Iso\IsoInterface;

/**
* @template S
* @template T
* @template A
* @implements XmlEncoder<S, A>
* @template B
* @implements XmlEncoder<S, T, A, B>
*/
final readonly class FixedIsoEncoder implements XmlEncoder
{
/**
* @param Iso<S, A> $iso
* @param IsoInterface<S, T, A, B> $iso
*/
public function __construct(
private Iso $iso,
private IsoInterface $iso,
) {
}

/**
* @return Iso<S, A>
* @return IsoInterface<S, T, A, B>
*/
public function iso(Context $context): Iso
public function iso(Context $context): IsoInterface
{
return $this->iso;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Encoder/MatchingValueEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
* This encoder can be used to select an encoder based on the value being encoded.
* For decoding, it will always use the default encoder.
*
* @psalm-type MatchedEncoderInfo = Context | array{0: Context, 1 ?: XmlEncoder<mixed, string>|null}
* @psalm-type MatchedEncoderInfo = Context | array{0: Context, 1 ?: XmlEncoder<mixed, mixed, string, Element|string>|null}
* @psalm-type MatchingEncoderDetector = \Closure(Context, mixed): MatchedEncoderInfo
*
* @psalm-suppress UnusedClass
*
* @implements XmlEncoder<mixed, string>
* @implements XmlEncoder<mixed, mixed, string, Element|string>
*/
final readonly class MatchingValueEncoder implements XmlEncoder
{
/**
* @param MatchingEncoderDetector $encoderDetector
* @param XmlEncoder<mixed, string> $defaultEncoder
* @param XmlEncoder<mixed, mixed, string, Element|string> $defaultEncoder
*/
public function __construct(
private Closure $encoderDetector,
Expand All @@ -32,7 +32,6 @@ public function __construct(

public function iso(Context $context): Iso
{
/** @var Iso<string, mixed> $defaultIso */
$defaultIso = $this->defaultEncoder->iso($context);

return new Iso(
Expand Down
6 changes: 3 additions & 3 deletions src/Encoder/Method/RequestEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
use function VeeWee\Reflecta\Lens\index;

/**
* @template-implements SoapMethodEncoder<list<mixed>, non-empty-string>
* @template-implements SoapMethodEncoder<list<mixed>, list<mixed>, non-empty-string, non-empty-string>
*/
final class RequestEncoder implements SoapMethodEncoder
{
/**
* @return Iso<list<mixed>, non-empty-string>
* @return Iso<list<mixed>, list<mixed>, non-empty-string, non-empty-string>
*/
public function iso(MethodContext $context): Iso
{
Expand All @@ -35,7 +35,7 @@ public function iso(MethodContext $context): Iso
->unwrapOr(BindingUse::LITERAL)
);

/** @var Iso<list<mixed>, non-empty-string> */
/** @var Iso<list<mixed>, list<mixed>, non-empty-string, non-empty-string> */
return new Iso(
/**
* @param list<mixed> $arguments
Expand Down
6 changes: 3 additions & 3 deletions src/Encoder/Method/ResponseEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use function Psl\Vec\map;

/**
* @template-implements SoapMethodEncoder<mixed, string>
* @template-implements SoapMethodEncoder<list<mixed>, list<mixed>, string, string>
*/
final class ResponseEncoder implements SoapMethodEncoder
{
/**
* @return Iso<mixed, string>
* @return Iso<list<mixed>, list<mixed>, string, string>
*/
public function iso(MethodContext $context): Iso
{
Expand All @@ -33,7 +33,7 @@ public function iso(MethodContext $context): Iso
->unwrapOr(BindingUse::LITERAL)
);

/** @var Iso<list<mixed>, string> */
/** @var Iso<list<mixed>, list<mixed>, string, string> */
return new Iso(
/**
* @param list<mixed> $arguments
Expand Down
Loading