Skip to content

Commit

Permalink
move to public readonly properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mathielen committed Jan 29, 2025
1 parent d6dd0bd commit 3277dcd
Show file tree
Hide file tree
Showing 95 changed files with 342 additions and 1,215 deletions.
4 changes: 2 additions & 2 deletions src/CXml/Authentication/SimpleSharedSecretAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function __construct(private string $sharedSecret)

public function authenticate(Header $header, Context $context): void
{
if ($this->sharedSecret !== $header->getSender()->getCredential()->getSharedSecret()) {
throw new CXmlAuthenticationInvalidException($header->getSender()->getCredential());
if ($this->sharedSecret !== $header->sender->credential->sharedSecret) {
throw new CXmlAuthenticationInvalidException($header->sender->credential);
}
}
}
26 changes: 13 additions & 13 deletions src/CXml/Builder/OrderRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public static function fromPunchOutOrderMessage(
?DateTimeInterface $orderDate = null,
string $language = 'en',
): self {
if (($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) instanceof SupplierOrderInfo) {
$orderId ??= $supplierOrderInfo->getOrderId();
$orderDate ??= $supplierOrderInfo->getOrderDate();
if (($supplierOrderInfo = $punchOutOrderMessage->punchOutOrderMessageHeader->getSupplierOrderInfo()) instanceof SupplierOrderInfo) {
$orderId ??= $supplierOrderInfo->orderId;
$orderDate ??= $supplierOrderInfo->orderDate;
}

$currency ??= $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getTotal()->getMoney()->getCurrency();
$currency ??= $punchOutOrderMessage->punchOutOrderMessageHeader->total->money->currency;

if (null === $orderId) {
throw new LogicException('orderId should either be given or present in the PunchOutOrderMessage');
Expand All @@ -109,15 +109,15 @@ public static function fromPunchOutOrderMessage(
null,
);

$orb->setShipTo($punchOutOrderMessage->getPunchOutOrderMessageHeader()->getShipTo());
$orb->setShipTo($punchOutOrderMessage->punchOutOrderMessageHeader->getShipTo());

foreach ($punchOutOrderMessage->getPunchoutOrderMessageItems() as $item) {
$orb->addItem(
$item->getQuantity(),
$item->getItemId(),
$item->getItemDetail()->getDescription()->getValue(),
$item->getItemDetail()->getUnitOfMeasure(),
$item->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(),
$item->quantity,
$item->itemId,
$item->itemDetail->description->value,
$item->itemDetail->unitOfMeasure,
$item->itemDetail->unitPrice->money->getValueCent(),
[
new Classification('custom', '0'), // TODO make this configurable
],
Expand Down Expand Up @@ -252,13 +252,13 @@ public function addItem(
$priceBasisQuantity,
),
$requestDeliveryDate,
$parent instanceof ItemOut ? $parent->getLineNumber() : null,
$parent instanceof ItemOut ? $parent->lineNumber : null,
);

$this->items[] = $item;

if ($priceBasisQuantity instanceof PriceBasisQuantity && $priceBasisQuantity->getQuantity() > 0) {
$this->total += (int)round($quantity * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $unitPrice);
if ($priceBasisQuantity instanceof PriceBasisQuantity && $priceBasisQuantity->quantity > 0) {
$this->total += (int)round($quantity * ($priceBasisQuantity->conversionFactor / $priceBasisQuantity->quantity) * $unitPrice);
} else {
$this->total += ($quantity * $unitPrice);
}
Expand Down
12 changes: 6 additions & 6 deletions src/CXml/Builder/PunchOutOrderMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ public function addItem(ItemIn $itemIn): self
{
$this->punchoutOrderMessageItems[] = $itemIn;

$moneyValueCent = $itemIn->getItemDetail()->getUnitPrice()->getMoney()->getValueCent();
$itemQty = $itemIn->getQuantity();
$moneyValueCent = $itemIn->itemDetail->unitPrice->money->getValueCent();
$itemQty = $itemIn->quantity;

if (
$itemIn->getItemDetail()->getPriceBasisQuantity() instanceof PriceBasisQuantity
&& $itemIn->getItemDetail()->getPriceBasisQuantity()->getQuantity() > 0
$itemIn->itemDetail->priceBasisQuantity instanceof PriceBasisQuantity
&& $itemIn->itemDetail->priceBasisQuantity->quantity > 0
) {
$priceBasisQuantity = $itemIn->getItemDetail()->getPriceBasisQuantity();
$this->total += (int)round($itemQty * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $moneyValueCent);
$priceBasisQuantity = $itemIn->itemDetail->priceBasisQuantity;
$this->total += (int)round($itemQty * ($priceBasisQuantity->conversionFactor / $priceBasisQuantity->quantity) * $moneyValueCent);
} else {
$this->total += $moneyValueCent * $itemQty;
}
Expand Down
6 changes: 3 additions & 3 deletions src/CXml/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public function getSenderUserAgent(): ?string
return null;
}

$header = $cxml->getHeader();
$header = $cxml->header;
if (!$header instanceof Header) {
return null;
}

return $header->getSender()->getUserAgent();
return $header->sender->userAgent;
}

public function getPayloadId(): ?string
Expand All @@ -76,6 +76,6 @@ public function getPayloadId(): ?string
return null;
}

return $cxml->getPayloadId();
return $cxml->payloadId;
}
}
16 changes: 8 additions & 8 deletions src/CXml/Credential/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function registerCredential(Credential $credential): void
public function getCredentialByDomainAndId(string $domain, string $identity): Credential
{
foreach ($this->registeredCredentials as $registeredCredential) {
if ($registeredCredential->getDomain() !== $domain) {
if ($registeredCredential->domain !== $domain) {
continue;
}

if ($registeredCredential->getIdentity() !== $identity) {
if ($registeredCredential->identity !== $identity) {
continue;
}

Expand All @@ -51,14 +51,14 @@ public function getCredentialByDomainAndId(string $domain, string $identity): Cr
*/
public function authenticate(Header $header, Context $context): void
{
$senderCredential = $header->getSender()->getCredential();
$senderCredential = $header->sender->credential;

$baseCredential = $this->getCredentialByDomainAndId(
$senderCredential->getDomain(),
$senderCredential->getIdentity(),
$senderCredential->domain,
$senderCredential->identity,
);

if ($baseCredential->getSharedSecret() !== $senderCredential->getSharedSecret()) {
if ($baseCredential->sharedSecret !== $senderCredential->sharedSecret) {
throw new CXmlAuthenticationInvalidException($senderCredential);
}
}
Expand All @@ -70,8 +70,8 @@ public function validate(Credential $credential): void
{
// provoke an exception if credential was not found
$this->getCredentialByDomainAndId(
$credential->getDomain(),
$credential->getIdentity(),
$credential->domain,
$credential->identity,
);
}
}
4 changes: 2 additions & 2 deletions src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function onPostSerializePayment(ObjectEvent $event): void
{
$visitor = $event->getVisitor();

$paymentImpl = $event->getObject()->getPaymentImpl();
$paymentImpl = $event->getObject()->paymentImpl;

$cls = (new ReflectionClass($paymentImpl))->getShortName();

Expand Down Expand Up @@ -147,7 +147,7 @@ public function onPostSerializeCXmlMainPayload(ObjectEvent $event): void

// this is the actual payload object of type MessagePayloadInterface
/** @phpstan-ignore-next-line */
$payload = $event->getObject()->getPayload();
$payload = $event->getObject()->payload ?? null;

if ($payload) {
$cls = (new ReflectionClass($payload))->getShortName();
Expand Down
6 changes: 3 additions & 3 deletions src/CXml/Model/Accounting.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
{
private function __construct(
#[Serializer\XmlAttribute]
private string $name,
public string $name,
/**
* @var AccountingSegment[]
*/
#[Serializer\XmlList(entry: 'AccountingSegment', inline: true)]
#[Serializer\Type('array<CXml\Model\AccountingSegment>')]
private array $accountingSegments,
public array $accountingSegments,
#[Serializer\SerializedName('Charge')]
private MoneyWrapper $charge,
public MoneyWrapper $charge,
) {
}
}
6 changes: 3 additions & 3 deletions src/CXml/Model/AccountingSegment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
{
private function __construct(
#[Serializer\XmlAttribute]
private int $id,
public int $id,
#[Serializer\SerializedName('Name')]
#[Serializer\XmlElement(cdata: false)]
private MultilanguageString $name,
public MultilanguageString $name,
#[Serializer\SerializedName('Description')]
#[Serializer\XmlElement(cdata: false)]
private MultilanguageString $description,
public MultilanguageString $description,
) {
}
}
56 changes: 8 additions & 48 deletions src/CXml/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,27 @@
public function __construct(
#[Serializer\SerializedName('Name')]
#[Serializer\XmlElement(cdata: false)]
private MultilanguageString $name,
public MultilanguageString $name,
#[Serializer\SerializedName('PostalAddress')]
private ?PostalAddress $postalAddress = null,
public ?PostalAddress $postalAddress = null,
#[Serializer\XmlAttribute]
#[Serializer\SerializedName('addressID')]
private ?string $addressId = null,
public ?string $addressId = null,
#[Serializer\XmlAttribute]
#[Serializer\SerializedName('addressIDDomain')]
private ?string $addressIdDomain = null,
public ?string $addressIdDomain = null,
#[Serializer\SerializedName('Email')]
#[Serializer\XmlElement(cdata: false)]
private ?string $email = null,
public ?string $email = null,
#[Serializer\SerializedName('Phone')]
#[Serializer\XmlElement(cdata: false)]
private ?Phone $phone = null,
public ?Phone $phone = null,
#[Serializer\SerializedName('Fax')]
#[Serializer\XmlElement(cdata: false)]
private ?string $fax = null,
public ?string $fax = null,
#[Serializer\SerializedName('URL')]
#[Serializer\XmlElement(cdata: false)]
private ?string $url = null,
public ?string $url = null,
) {
}

public function getAddressId(): ?string
{
return $this->addressId;
}

public function getAddressIdDomain(): ?string
{
return $this->addressIdDomain;
}

public function getName(): MultilanguageString
{
return $this->name;
}

public function getPostalAddress(): ?PostalAddress
{
return $this->postalAddress;
}

public function getEmail(): ?string
{
return $this->email;
}

public function getPhone(): ?Phone
{
return $this->phone;
}

public function getFax(): ?string
{
return $this->fax;
}

public function getUrl(): ?string
{
return $this->url;
}
}
8 changes: 2 additions & 6 deletions src/CXml/Model/BillTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace CXml\Model;

use CXml\Model\Trait\IdReferencesTrait;
use JMS\Serializer\Annotation as Serializer;

#[Serializer\AccessorOrder(order: 'custom', custom: ['address', 'idReferences'])]
Expand All @@ -13,12 +14,7 @@ class BillTo

public function __construct(
#[Serializer\SerializedName('Address')]
private readonly Address $address,
public readonly Address $address,
) {
}

public function getAddress(): Address
{
return $this->address;
}
}
9 changes: 5 additions & 4 deletions src/CXml/Model/BusinessPartner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace CXml\Model;

use CXml\Model\Trait\IdReferencesTrait;
use JMS\Serializer\Annotation as Serializer;

#[Serializer\AccessorOrder(order: 'custom', custom: ['type', 'role', 'address', 'idReferences'])]
class BusinessPartner
readonly class BusinessPartner
{
use IdReferencesTrait;
final public const ROLE_SOLD_TO = 'soldTo';
Expand All @@ -18,11 +19,11 @@ class BusinessPartner

public function __construct(
#[Serializer\XmlAttribute]
private string $role,
public string $role,
#[Serializer\SerializedName('Address')]
private Address $address,
public Address $address,
#[Serializer\XmlAttribute]
private string $type = 'organization',
public string $type = 'organization',
) {
}
}
Loading

0 comments on commit 3277dcd

Please sign in to comment.