Skip to content

Commit

Permalink
chore(style): adjusted php-cs-fixer indent
Browse files Browse the repository at this point in the history
  • Loading branch information
ynnoig committed Nov 9, 2023
1 parent 9d67136 commit 4d39ec5
Show file tree
Hide file tree
Showing 104 changed files with 5,033 additions and 5,034 deletions.
51 changes: 25 additions & 26 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;

$config = new PhpCsFixer\Config();

return $config
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PSR1' => true,
'@PhpCsFixer' => true,
'@Symfony' => true,
'@Symfony:risky' => false,
'native_function_invocation' => [
'include' => [\PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer::SET_INTERNAL],
'scope' => 'namespaced',
'strict' => false,
],
'void_return' => true,
'random_api_migration' => true,
'pow_to_exponentiation' => true,
'combine_nested_dirname' => true,
'phpdoc_separation' => false,
'@PHP74Migration' => true,
'global_namespace_import' => [
'import_classes' => false,
],
])
->setIndent("\t")
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PSR1' => true,
'@PhpCsFixer' => true,
'@Symfony' => true,
'@Symfony:risky' => false,
'native_function_invocation' => [
'include' => [\PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer::SET_INTERNAL],
'scope' => 'namespaced',
'strict' => false,
],
'void_return' => true,
'random_api_migration' => true,
'pow_to_exponentiation' => true,
'combine_nested_dirname' => true,
'phpdoc_separation' => false,
'@PHP74Migration' => true,
'global_namespace_import' => [
'import_classes' => false,
],
])
->setFinder($finder)
;
8 changes: 4 additions & 4 deletions src/CXml/Authentication/AuthenticatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

interface AuthenticatorInterface
{
/**
* @throws CXmlAuthenticationInvalidException
*/
public function authenticate(Header $header, Context $context): void;
/**
* @throws CXmlAuthenticationInvalidException
*/
public function authenticate(Header $header, Context $context): void;
}
22 changes: 11 additions & 11 deletions src/CXml/Authentication/SimpleSharedSecretAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

class SimpleSharedSecretAuthenticator implements AuthenticatorInterface
{
private string $sharedSecret;
private string $sharedSecret;

public function __construct(string $sharedSecret)
{
$this->sharedSecret = $sharedSecret;
}
public function __construct(string $sharedSecret)
{
$this->sharedSecret = $sharedSecret;
}

public function authenticate(Header $header, Context $context): void
{
if ($this->sharedSecret !== $header->getSender()->getCredential()->getSharedSecret()) {
throw new CXmlAuthenticationInvalidException($header->getSender()->getCredential());
}
}
public function authenticate(Header $header, Context $context): void
{
if ($this->sharedSecret !== $header->getSender()->getCredential()->getSharedSecret()) {
throw new CXmlAuthenticationInvalidException($header->getSender()->getCredential());
}
}
}
288 changes: 144 additions & 144 deletions src/CXml/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,148 +20,148 @@

class Builder
{
private PayloadIdentityFactoryInterface $payloadIdentityFactory;

private ?PayloadInterface $payload = null;
private Credential $from;
private Credential $to;
private Credential $sender;
private ?string $senderUserAgent;
private ?Status $status = null;
private ?string $locale;

private function __construct(string $senderUserAgent, string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null)
{
$this->locale = $locale;
$this->payloadIdentityFactory = $payloadIdentityFactory ?? new DefaultPayloadIdentityFactory();
$this->senderUserAgent = $senderUserAgent;
}

public static function create(string $senderUserAgent = 'cxml-php UserAgent', string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null): self
{
return new self($senderUserAgent, $locale, $payloadIdentityFactory);
}

public function payload(PayloadInterface $payload = null): self
{
$this->payload = $payload;

return $this;
}

public function status(Status $status): self
{
$this->status = $status;

return $this;
}

public function sender(Credential $sender): self
{
$this->sender = $sender;

return $this;
}

public function setSenderUserAgent(?string $senderUserAgent): self
{
$this->senderUserAgent = $senderUserAgent;

return $this;
}

public function from(Credential $from): self
{
$this->from = $from;

return $this;
}

public function to(Credential $to): self
{
$this->to = $to;

return $this;
}

private function buildHeader(): Header
{
if (!isset($this->from)) {
throw new \LogicException("No 'from' has been set. Necessary for building a header.");
}
if (!isset($this->to)) {
throw new \LogicException("No 'to' has been set. Necessary for building a header.");
}
if (!isset($this->sender)) {
throw new \LogicException("No 'sender' has been set. Necessary for building a header.");
}

return new Header(
new Party($this->from),
new Party($this->to),
new Party($this->sender, $this->senderUserAgent)
);
}

/**
* @throws CXmlException
*/
public function build(string $deploymentMode = null): CXml
{
switch (true) {
case $this->payload instanceof RequestPayloadInterface:
/** @noinspection PhpParamsInspection */
$cXml = CXml::forRequest(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Request($this->payload, $this->status, null, $deploymentMode),
$this->buildHeader(),
$this->locale
);
break;

case $this->payload instanceof MessagePayloadInterface:
/** @noinspection PhpParamsInspection */
$cXml = CXml::forMessage(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Message($this->payload, $this->status),
$this->buildHeader(),
$this->locale
);
break;

case $this->payload instanceof ResponsePayloadInterface:
$status = $this->status;

// response requires a status
if (null === $status) {
$status = new Status(); // 200 OK
}

/** @noinspection PhpParamsInspection */
$cXml = CXml::forResponse(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Response($status, $this->payload),
$this->locale
);
break;

default:
// simple status ping-pong response
if ($this->status) {
$cXml = CXml::forResponse(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Response($this->status),
$this->locale
);

break;
}
}

if (!isset($cXml)) {
throw new CXmlException('Neither payload (Request, Message, Response) was set.');
}

return $cXml;
}
private PayloadIdentityFactoryInterface $payloadIdentityFactory;

private ?PayloadInterface $payload = null;
private Credential $from;
private Credential $to;
private Credential $sender;
private ?string $senderUserAgent;
private ?Status $status = null;
private ?string $locale;

private function __construct(string $senderUserAgent, string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null)
{
$this->locale = $locale;
$this->payloadIdentityFactory = $payloadIdentityFactory ?? new DefaultPayloadIdentityFactory();
$this->senderUserAgent = $senderUserAgent;
}

public static function create(string $senderUserAgent = 'cxml-php UserAgent', string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null): self
{
return new self($senderUserAgent, $locale, $payloadIdentityFactory);
}

public function payload(PayloadInterface $payload = null): self
{
$this->payload = $payload;

return $this;
}

public function status(Status $status): self
{
$this->status = $status;

return $this;
}

public function sender(Credential $sender): self
{
$this->sender = $sender;

return $this;
}

public function setSenderUserAgent(?string $senderUserAgent): self
{
$this->senderUserAgent = $senderUserAgent;

return $this;
}

public function from(Credential $from): self
{
$this->from = $from;

return $this;
}

public function to(Credential $to): self
{
$this->to = $to;

return $this;
}

private function buildHeader(): Header
{
if (!isset($this->from)) {
throw new \LogicException("No 'from' has been set. Necessary for building a header.");
}
if (!isset($this->to)) {
throw new \LogicException("No 'to' has been set. Necessary for building a header.");
}
if (!isset($this->sender)) {
throw new \LogicException("No 'sender' has been set. Necessary for building a header.");
}

return new Header(
new Party($this->from),
new Party($this->to),
new Party($this->sender, $this->senderUserAgent)
);
}

/**
* @throws CXmlException
*/
public function build(string $deploymentMode = null): CXml
{
switch (true) {
case $this->payload instanceof RequestPayloadInterface:
/** @noinspection PhpParamsInspection */
$cXml = CXml::forRequest(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Request($this->payload, $this->status, null, $deploymentMode),
$this->buildHeader(),
$this->locale
);
break;

case $this->payload instanceof MessagePayloadInterface:
/** @noinspection PhpParamsInspection */
$cXml = CXml::forMessage(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Message($this->payload, $this->status),
$this->buildHeader(),
$this->locale
);
break;

case $this->payload instanceof ResponsePayloadInterface:
$status = $this->status;

// response requires a status
if (null === $status) {
$status = new Status(); // 200 OK
}

/** @noinspection PhpParamsInspection */
$cXml = CXml::forResponse(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Response($status, $this->payload),
$this->locale
);
break;

default:
// simple status ping-pong response
if ($this->status) {
$cXml = CXml::forResponse(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Response($this->status),
$this->locale
);

break;
}
}

if (!isset($cXml)) {
throw new CXmlException('Neither payload (Request, Message, Response) was set.');
}

return $cXml;
}
}
Loading

0 comments on commit 4d39ec5

Please sign in to comment.