Skip to content

Commit

Permalink
[CS] Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Jan 18, 2025
1 parent 3cf2f56 commit 35b3d4c
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 108 deletions.
2 changes: 1 addition & 1 deletion build/phprectorconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
earlyReturn: true,
phpunitCodeQuality: true,
privatization: true,
deadCode: true,
//
carbon: false,
deadCode: false,
doctrineCodeQuality: false,
naming: false,
rectorPreset: false,
Expand Down
12 changes: 4 additions & 8 deletions make/gencodelists.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ function handleUmlauts(string $str): string
$str = str_replace("ö", "oe", $str);
$str = str_replace("ä", "ae", $str);
$str = str_replace("ü", "ue", $str);
$str = str_replace("Å", "A", $str);
return $str;
return str_replace("Å", "A", $str);
}

/**
Expand All @@ -62,8 +61,7 @@ function strComment(string $str): string
$str = str_replace("\r", "", $str);
$str = str_replace("\t", "", $str);
$str = preg_replace('/\s+/', ' ', $str);
$str = wordwrap($str);
return $str;
return wordwrap($str);
}

/**
Expand Down Expand Up @@ -102,8 +100,7 @@ function strIdentifier(string $str, bool $shortIdentifier): string

$strNew = preg_replace('/__+/', '_', $strNew);
$strNew = preg_replace('~\d~', '', $strNew, 5);
$strNew = rtrim(ltrim($strNew, "_"), "_");
return $strNew;
return rtrim(ltrim($strNew, "_"), "_");
}

/**
Expand All @@ -119,8 +116,7 @@ function strDesc(string $str): string
$str = str_replace("\n", " ", $str);
$str = str_replace("\r", " ", $str);
$str = str_replace("\t", " ", $str);
$str = preg_replace('/\s+/', ' ', $str);
return $str;
return preg_replace('/\s+/', ' ', $str);
}

/**
Expand Down
55 changes: 4 additions & 51 deletions make/genmethoddocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function getArray(): array
'name' => $parameterName,
'type' => $parameterTypeString ?: 'mixed',
'isNullable' => $parameterType && $parameterType->allowsNull(),
'defaultValueavailable' => $parameter->isOptional() ? ($parameter->isDefaultValueAvailable()) : false,
'defaultValueavailable' => $parameter->isOptional() && $parameter->isDefaultValueAvailable(),
'defaultValue' => $parameter->isOptional() ? ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null) : null,
'description' => $paramDescriptions[$parameterName]['description'] ?? ''
];
Expand Down Expand Up @@ -261,7 +261,7 @@ class MarkDownGenerator
*
* @var ExtractClass
*/
protected $extractor = null;
protected $extractor;

/**
* The lines for the MD
Expand Down Expand Up @@ -455,20 +455,6 @@ private function addLineRaw(string $string, ...$args): MarkDownGenerator
return $this;
}

/**
* Add a line to internal container
*
* @param string $string
* @param mixed ...$args
* @return MarkDownGenerator
*/
private function addLineRawAllowEmpty(string $string, ...$args): MarkDownGenerator
{
$this->lines[] = sprintf($string, ...$args);

return $this;
}

/**
* Add an empty line to internal container
*
Expand All @@ -481,24 +467,6 @@ private function addEmptyLine(): MarkDownGenerator
return $this;
}

/**
* Add an H1-Line to internal container
*
* @param string $string
* @param boolean $newLine
* @return MarkDownGenerator
*/
private function addLineH1(string $string, bool $newLine = true): MarkDownGenerator
{
$this->addLine("# %s", $string);

if ($newLine) {
$this->addEmptyLine();
}

return $this;
}

/**
* Add an H2-Line to internal container
*
Expand Down Expand Up @@ -585,18 +553,6 @@ private function addLineItalic(string $string, ...$args): MarkDownGenerator
return $this->addLine(sprintf("_%s_", $string), ...$args);
}

/**
* Add line as bold formatted
*
* @param string $string
* @param mixed ...$args
* @return MarkDownGenerator
*/
private function addLineBold(string $string, ...$args): MarkDownGenerator
{
return $this->addLine(sprintf("__%s__", $string), ...$args);
}

/**
* Import an example from a markdown file
*
Expand Down Expand Up @@ -644,9 +600,8 @@ private function sanatizeString(string $string): string
$string = str_replace("\n", "<br/>", $string);
$string = str_replace("__BT-, From __", "", $string);
$string = str_replace("__BT-, From", "__BT-??, From", $string);
$string = trim($string);

return $string;
return trim($string);
}

/**
Expand All @@ -657,9 +612,7 @@ private function sanatizeString(string $string): string
*/
private function removeSprintfPlaceholder(string $string): string
{
$string = str_replace("%", "", $string);

return $string;
return str_replace("%", "", $string);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ZugferdDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ class ZugferdDocument
/**
* @var \horstoeko\zugferd\entities\basic\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\basicwl\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\en16931\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\extended\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\minimum\rsm\CrossIndustryInvoice $invoiceObject The internal invoice object
*/
private $invoiceObject = null;
private $invoiceObject;

/**
* @var ZugferdObjectHelper $objectHelper Object Helper
*/
private $objectHelper = null;
private $objectHelper;

/**
* Constructor
Expand Down
16 changes: 7 additions & 9 deletions src/ZugferdDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,42 @@ class ZugferdDocumentBuilder extends ZugferdDocument
*
* @var object
*/
protected $headerTradeAgreement = null;
protected $headerTradeAgreement;

/**
* HeaderTradeDelivery
*
* @var object
*/
protected $headerTradeDelivery = null;
protected $headerTradeDelivery;

/**
* HeaderTradeSettlement
*
* @var object
*/
protected $headerTradeSettlement = null;
protected $headerTradeSettlement;

/**
* SupplyChainTradeTransactionType
*
* @var object
*/
protected $headerSupplyChainTradeTransaction = null;
protected $headerSupplyChainTradeTransaction;

/**
* Last added payment terms
*
* @var object
*/
protected $currentPaymentTerms = null;
protected $currentPaymentTerms;

/**
* Last added position (line) to the docuemnt
*
* @var object
*/
protected $currentPosition = null;
protected $currentPosition;

/**
* Receive the content as XML string
Expand Down Expand Up @@ -153,9 +153,7 @@ public function getContentAsDomDocument(): DOMDocument
*/
public function getContentAsDomXPath(): DOMXpath
{
$domXPath = new DOMXPath($this->getContentAsDomDocument());

return $domXPath;
return new DOMXPath($this->getContentAsDomDocument());
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/ZugferdDocumentJsonExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ZugferdDocumentJsonExporter
*
* @var ZugferdDocument
*/
private $document = null;
private $document;

/**
* Constructor
Expand Down Expand Up @@ -57,9 +57,7 @@ public function toJsonString(): string
*/
public function toJsonObject(): ?\stdClass
{
$jsonObject = json_decode($this->toJsonString());

return $jsonObject;
return json_decode($this->toJsonString());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ZugferdDocumentPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ZugferdDocumentPdfBuilder extends ZugferdDocumentPdfBuilderAbstract
*
* @var ZugferdDocumentBuilder
*/
private $documentBuilder = null;
private $documentBuilder;

/**
* Cached XML data
Expand Down
12 changes: 4 additions & 8 deletions src/ZugferdDocumentPdfBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class ZugferdDocumentPdfBuilderAbstract
*
* @var ZugferdPdfWriter
*/
private $pdfWriter = null;
private $pdfWriter;

/**
* Contains the data of the original PDF document
Expand Down Expand Up @@ -120,7 +120,7 @@ abstract class ZugferdDocumentPdfBuilderAbstract
*
* @var callable|null
*/
private $metaInformationCallback = null;
private $metaInformationCallback;

/**
* Constructor
Expand Down Expand Up @@ -606,16 +606,14 @@ private function preparePdfMetadata(): array
$title = sprintf('%s : %s %s', $invoiceInformations['seller'], $invoiceInformations['docTypeName'], $invoiceInformations['invoiceId']);
$subject = sprintf('FacturX/ZUGFeRD %s %s dated %s issued by %s', $invoiceInformations['docTypeName'], $invoiceInformations['invoiceId'], $dateString, $invoiceInformations['seller']);

$pdfMetadata = [
return [
'author' => $this->buildMetadataField('author', $author, $invoiceInformations),
'keywords' => $this->buildMetadataField('keywords', $keywords, $invoiceInformations),
'title' => $this->buildMetadataField('title', $title, $invoiceInformations),
'subject' => $this->buildMetadataField('subject', $subject, $invoiceInformations),
'createdDate' => $invoiceInformations['date'],
'modifiedDate' => (new DateTime())->format('Y-m-d\TH:i:sP'),
];

return $pdfMetadata;
}

/**
Expand Down Expand Up @@ -652,14 +650,12 @@ protected function extractInvoiceInformations(): array
break;
}

$invoiceInformation = [
return [
'invoiceId' => $invoiceId,
'docTypeName' => $docTypeName,
'seller' => $sellerName,
'date' => $dateReformatted,
];

return $invoiceInformation;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ZugferdDocumentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ZugferdDocumentValidator
/**
* The validator instance
*/
private $validator = null;
private $validator;

/**
* Constructor
Expand Down
4 changes: 1 addition & 3 deletions src/ZugferdObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ public function getCountryIDType(?string $id = null): ?object
return null;
}

$countryIDType = $this->createClassInstance('qdt\CountryIDType', $id);

return $countryIDType;
return $this->createClassInstance('qdt\CountryIDType', $id);
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/ZugferdPdfValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,6 @@ public function validate(): ZugferdPdfValidator
return $this;
}

/**
* Internal get the content of the PDF
*
* @return string
*/
private function getPdfContent(): string
{
return $this->pdfContent;
}

/**
* Internal get (and create) the directory for downloads and file creation
*
Expand Down
4 changes: 2 additions & 2 deletions src/ZugferdPdfWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function setDeterministicModeEnabled(bool $deterministicModeEnabled): voi
*/
protected function _putfiles(): void
{
foreach ($this->files as $_ => &$info) {
foreach ($this->files as &$info) {
$this->putFileSpecification($info);
$info['file_index'] = $this->n;
$this->putFileStream($info);
Expand Down Expand Up @@ -328,7 +328,7 @@ protected function putMetadataDescriptions(): void
$s .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">' . "\n";
$this->_newobj();
$this->descriptionIndex = $this->n;
foreach ($this->metaDataDescriptions as $_ => $desc) {
foreach ($this->metaDataDescriptions as $desc) {
$s .= $desc . "\n";
}

Expand Down
7 changes: 2 additions & 5 deletions src/jms/ZugferdTypesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,14 @@ public function serializeQuantityType(XmlSerializationVisitor $visitor, $data)
*/
public function serializePercentType(XmlSerializationVisitor $visitor, $data)
{
$node = $visitor->getDocument()->createTextNode(
return $visitor->getDocument()->createTextNode(
number_format(
$data->value(),
ZugferdSettings::getSpecialDecimalPlacesMap($visitor->getCurrentNode()->getNodePath(), ZugferdSettings::getPercentDecimals()),
ZugferdSettings::getDecimalSeparator(),
ZugferdSettings::getThousandsSeparator()
)
);

return $node;
}

/**
Expand Down Expand Up @@ -283,7 +281,6 @@ public function serializeMeasureType(XmlSerializationVisitor $visitor, $data)
*/
public function serializeIndicatorType(XmlSerializationVisitor $visitor, $data)
{
$node = $visitor->getDocument()->createElement('udt:Indicator', $data->getIndicator() == false ? 'false' : 'true');
return $node;
return $visitor->getDocument()->createElement('udt:Indicator', $data->getIndicator() == false ? 'false' : 'true');
}
}
Loading

0 comments on commit 35b3d4c

Please sign in to comment.