Skip to content

Commit

Permalink
Introduce soap-fault support
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Jun 6, 2024
1 parent d0ac7fd commit adf9a9e
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Encoder/Fault/Soap11FaultEncoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace Soap\Encoding\Encoder\Fault;

use RuntimeException;
use Soap\Encoding\Encoder\Context;
use Soap\Encoding\Encoder\XmlEncoder;
use Soap\Encoding\Model\Soap11Fault;
use VeeWee\Reflecta\Iso\Iso;

/**
* @implements XmlEncoder<Soap11Fault, string>
*/
final class Soap11FaultEncoder implements XmlEncoder

Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap11FaultEncoder.php:15:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap11FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap11FaultEncoder.php:15:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap11FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap11FaultEncoder.php:15:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap11FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap11FaultEncoder.php:15:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap11FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap11FaultEncoder.php:15:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap11FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap11FaultEncoder.php:15:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap11FaultEncoder is never used (see https://psalm.dev/075)
{
/**
* @return Iso<Soap11Fault, string>
*/
public function iso(Context $context): Iso
{
return new Iso(
static fn (Soap11Fault $fault): string => throw new RuntimeException('not implemented yet'),

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:23:36: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:23:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:23:36: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:23:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:23:36: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:23:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:23:36: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:23:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:23:36: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:23:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:23:36: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:23:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)
static fn (string $fault): Soap11Fault => throw new RuntimeException('not implemented yet')

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:24:31: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:24:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:24:31: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:24:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:24:31: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:24:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:24:31: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:24:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:24:31: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:24:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClosureParam

src/Encoder/Fault/Soap11FaultEncoder.php:24:31: UnusedClosureParam: Param fault is never referenced in this method (see https://psalm.dev/188)

Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

NoValue

src/Encoder/Fault/Soap11FaultEncoder.php:24:55: NoValue: All possible types for this return were invalidated - This may be dead code (see https://psalm.dev/179)
);
}
}


/*
*
* <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">
a:Microsoft.Dynamics.Nav.Service.WebServices.ServiceBrokerException
</faultcode>
<faultstring xml:lang="nl-BE">Parameter languagecode in method CategoryList in service DumpServices is
null!
</faultstring>
<detail>
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Parameter languagecode in method
CategoryList in service DumpServices is null!
</string>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
*/
139 changes: 139 additions & 0 deletions src/Encoder/Fault/Soap12FaultEncoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php
declare(strict_types=1);

namespace Soap\Encoding\Encoder\Fault;

use Soap\Encoding\Encoder\Context;
use Soap\Encoding\Encoder\XmlEncoder;
use Soap\Encoding\Model\Soap12Fault;
use VeeWee\Reflecta\Iso\Iso;
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Writer\Writer;
use function VeeWee\Xml\Dom\Xpath\Configurator\namespaces;
use function VeeWee\Xml\Writer\Builder\children;
use function VeeWee\Xml\Writer\Builder\namespaced_element;
use function VeeWee\Xml\Writer\Builder\prefixed_element;
use function VeeWee\Xml\Writer\Builder\raw;
use function VeeWee\Xml\Writer\Builder\value;
use function VeeWee\Xml\Writer\Mapper\memory_output;

/**
* @implements XmlEncoder<Soap12Fault, non-empty-string>
*/
final class Soap12FaultEncoder implements XmlEncoder

Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap12FaultEncoder.php:23:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap12FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap12FaultEncoder.php:23:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap12FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap12FaultEncoder.php:23:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap12FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap12FaultEncoder.php:23:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap12FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap12FaultEncoder.php:23:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap12FaultEncoder is never used (see https://psalm.dev/075)

Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

UnusedClass

src/Encoder/Fault/Soap12FaultEncoder.php:23:13: UnusedClass: Class Soap\Encoding\Encoder\Fault\Soap12FaultEncoder is never used (see https://psalm.dev/075)
{
private const ENV_NAMESPACE = 'http://www.w3.org/2003/05/soap-envelope';

/**
* @return Iso<Soap12Fault, non-empty-string>

Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MoreSpecificReturnType

src/Encoder/Fault/Soap12FaultEncoder.php:28:16: MoreSpecificReturnType: The declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso is more specific than the inferred return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' (see https://psalm.dev/070)

Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MoreSpecificReturnType

src/Encoder/Fault/Soap12FaultEncoder.php:28:16: MoreSpecificReturnType: The declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso is more specific than the inferred return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' (see https://psalm.dev/070)

Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MoreSpecificReturnType

src/Encoder/Fault/Soap12FaultEncoder.php:28:16: MoreSpecificReturnType: The declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso is more specific than the inferred return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' (see https://psalm.dev/070)

Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MoreSpecificReturnType

src/Encoder/Fault/Soap12FaultEncoder.php:28:16: MoreSpecificReturnType: The declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso is more specific than the inferred return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' (see https://psalm.dev/070)

Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MoreSpecificReturnType

src/Encoder/Fault/Soap12FaultEncoder.php:28:16: MoreSpecificReturnType: The declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso is more specific than the inferred return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' (see https://psalm.dev/070)

Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MoreSpecificReturnType

src/Encoder/Fault/Soap12FaultEncoder.php:28:16: MoreSpecificReturnType: The declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso is more specific than the inferred return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' (see https://psalm.dev/070)
*/
public function iso(Context $context): Iso
{
return new Iso(

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

ArgumentTypeCoercion

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: ArgumentTypeCoercion: Type string should be a subtype of non-empty-string (see https://psalm.dev/193)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

LessSpecificReturnStatement

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: LessSpecificReturnStatement: The type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' is more general than the declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso (see https://psalm.dev/129)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

ArgumentTypeCoercion

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: ArgumentTypeCoercion: Type string should be a subtype of non-empty-string (see https://psalm.dev/193)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

LessSpecificReturnStatement

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: LessSpecificReturnStatement: The type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' is more general than the declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso (see https://psalm.dev/129)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

ArgumentTypeCoercion

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: ArgumentTypeCoercion: Type string should be a subtype of non-empty-string (see https://psalm.dev/193)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

LessSpecificReturnStatement

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: LessSpecificReturnStatement: The type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' is more general than the declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso (see https://psalm.dev/129)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

ArgumentTypeCoercion

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: ArgumentTypeCoercion: Type string should be a subtype of non-empty-string (see https://psalm.dev/193)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

LessSpecificReturnStatement

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: LessSpecificReturnStatement: The type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' is more general than the declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso (see https://psalm.dev/129)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

ArgumentTypeCoercion

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: ArgumentTypeCoercion: Type string should be a subtype of non-empty-string (see https://psalm.dev/193)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

LessSpecificReturnStatement

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: LessSpecificReturnStatement: The type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' is more general than the declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso (see https://psalm.dev/129)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

ArgumentTypeCoercion

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: ArgumentTypeCoercion: Type string should be a subtype of non-empty-string (see https://psalm.dev/193)

Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

LessSpecificReturnStatement

src/Encoder/Fault/Soap12FaultEncoder.php:32:16: LessSpecificReturnStatement: The type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, string>' is more general than the declared return type 'VeeWee\Reflecta\Iso\Iso<Soap\Encoding\Model\Soap12Fault, non-empty-string>' for Soap\Encoding\Encoder\Fault\Soap12FaultEncoder::iso (see https://psalm.dev/129)
$this->to(...),
$this->from(...)
);
}

private function to(Soap12Fault $fault): string
{
return Writer::inMemory()
->write(children([
namespaced_element(
self::ENV_NAMESPACE,
'env',
'Fault',
children([
prefixed_element(
'env',
'Code',
children([
prefixed_element(
'env',
'Value',
value($fault->code)
),
...(
$fault->subCode

Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

RiskyTruthyFalsyComparison

src/Encoder/Fault/Soap12FaultEncoder.php:57:37: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

RiskyTruthyFalsyComparison

src/Encoder/Fault/Soap12FaultEncoder.php:57:37: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

RiskyTruthyFalsyComparison

src/Encoder/Fault/Soap12FaultEncoder.php:57:37: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

RiskyTruthyFalsyComparison

src/Encoder/Fault/Soap12FaultEncoder.php:57:37: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

RiskyTruthyFalsyComparison

src/Encoder/Fault/Soap12FaultEncoder.php:57:37: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

RiskyTruthyFalsyComparison

src/Encoder/Fault/Soap12FaultEncoder.php:57:37: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
? [
prefixed_element(
'env',
'Subcode',
children([
prefixed_element(
'env',
'Value',
value($fault->subCode)
)
])
)
]
: []
),

])
),
prefixed_element(
'env',
'Reason',
children([
prefixed_element(
'env',
'Text',
value($fault->reason)
)
])
),
...(
$fault->node
? [
prefixed_element(
'env',
'Node',
value($fault->node)
)
]
: []
),
...(
$fault->role
? [
prefixed_element(
'env',
'Role',
value($fault->role)
)
]
: []
),
...($fault->detail ? [raw($fault->detail)] : []),
])
)
]))
->map(memory_output());
}

/**
* @param non-empty-string $fault
*/
private function from(string $fault): Soap12Fault
{
$document = Document::fromXmlString($fault);
$documentElement = $document->locateDocumentElement();
$xpath = $document->xpath(namespaces(['env' => $documentElement->namespaceURI]));

$subCode = $xpath->query('//env:Code/env:Subcode/env:Value');
$node = $xpath->query('//env:Node');
$role = $xpath->query('//env:Role');
$detail = $xpath->query('//env:Detail');

return new Soap12Fault(
code: $xpath->querySingle('//env:Code/env:Value')->textContent,
reason: $xpath->querySingle('//env:Reason/env:Text')->textContent,
subCode: $subCode->count() ? $subCode->first()->textContent : null,
node: $node->count() ? $node->first()->textContent : null,
role: $role->count() ? $role->first()->textContent : null,
detail: $detail->count() ? Document::fromXmlNode($detail->first())->stringifyDocumentElement() : null,
);
}
}
28 changes: 28 additions & 0 deletions src/Exception/SoapFaultException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

namespace Soap\Encoding\Exception;

use Psl\Str;
use RuntimeException;
use Soap\Encoding\Model\SoapFault;

final class SoapFaultException extends RuntimeException implements ExceptionInterface
{
public function __construct(
private readonly SoapFault $fault
) {
parent::__construct(
Str\format(
'A SOAP Fault got triggered: %s (Code: %s)',
$this->fault->reason(),
$this->fault->code(),
),
);
}

public function fault(): SoapFault
{
return $this->fault;
}
}
11 changes: 11 additions & 0 deletions src/Model/Soap11Fault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Soap\Encoding\Model;

/**
* @see https://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383507
*/
final class Soap11Fault implements SoapFault
{
}
41 changes: 41 additions & 0 deletions src/Model/Soap12Fault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

namespace Soap\Encoding\Model;

/**
* https://www.w3.org/TR/soap12-part1/#soapfault
*
* A mandatory Code element information item (see 5.4.1 SOAP Code Element).
* A mandatory Reason element information item (see 5.4.2 SOAP Reason Element).
* An optional Node element information item (see 5.4.3 SOAP Node Element).
* An optional Role element information item (see 5.4.4 SOAP Role Element).
* An optional Detail element information item (see 5.4.5 SOAP Detail Element).
*/
final class Soap12Fault implements SoapFault
{
public function __construct(
public readonly string $code,
public readonly string $reason,
public readonly ?string $subCode = null,
public readonly ?string $node = null,
public readonly ?string $role = null,
public readonly ?string $detail = null
) {
}

public function code(): string
{
return $this->code;
}

public function reason(): string
{
return $this->reason;
}

public function detail(): ?string
{
return $this->detail;
}
}
13 changes: 13 additions & 0 deletions src/Model/SoapFault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace Soap\Encoding\Model;

interface SoapFault
{
public function code(): string;

public function reason(): string;

public function detail(): ?string;
}
Loading

0 comments on commit adf9a9e

Please sign in to comment.