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 04686b3 commit 6fdabab
Show file tree
Hide file tree
Showing 38 changed files with 133 additions and 147 deletions.
16 changes: 1 addition & 15 deletions build/phprectorconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,4 @@
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
])
->withPhp73Sets()
->withSets([
SetList::DEAD_CODE,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
])
->withConfiguredRule(EncapsedStringsToSprintfRector::class, [
'always' => true,
])
->withRules([
RenamePropertyToMatchTypeRector::class,
RenameParamToMatchTypeRector::class,
RenameVariableToMatchNewTypeRector::class,
])
->withTypeCoverageLevel(0);
->withPhp73Sets();
12 changes: 6 additions & 6 deletions make/genchangelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function str_starts_with(string $haystack, string $needle): bool
if (!function_exists('str_contains')) {
function str_contains($haystack, $needle)
{
return (strpos($haystack, $needle) !== false);
return (strpos($haystack, (string) $needle) !== false);
}
}

Expand Down Expand Up @@ -222,7 +222,7 @@ function getMarkDown($prevTag, $currTag)
$noOfHiddenCommits = 0;

$commits = array_filter($commits, function ($commit) use (&$noOfHiddenCommits) {
list($commitHash, $commitAuthor, $commitDate, $commitSubject) = explode("|", $commit);
[$commitHash, $commitAuthor, $commitDate, $commitSubject] = explode("|", $commit);
$hidden = mustHideCommit($commitHash, $commitAuthor, $commitDate, $commitSubject);
if ($hidden) {
$noOfHiddenCommits++;
Expand All @@ -240,7 +240,7 @@ function getMarkDown($prevTag, $currTag)
$markDown[] = '| :--- | :------ | :------ | :------ | :------- | :-----------: ';

foreach ($commits as $commit) {
list($commitHash, $commitAuthor, $commitDate, $commitSubject) = explode("|", $commit);
[$commitHash, $commitAuthor, $commitDate, $commitSubject] = explode("|", $commit);

if (mustHideCommit($commitHash, $commitAuthor, $commitDate, $commitSubject)) {
$noOfHiddenCommits++;
Expand Down Expand Up @@ -301,7 +301,7 @@ function printMarkdown(array $markDown): void
echo "Found tags..." . PHP_EOL;
echo " - prevTag: $prevTag" . PHP_EOL;
echo " - currTag: $currTag" . PHP_EOL;
file_put_contents(dirname(__FILE__) . '/CHANGELOG.md', implode("\n", getMarkDown($prevTag, $currTag)));
file_put_contents(__DIR__ . '/CHANGELOG.md', implode("\n", getMarkDown($prevTag, $currTag)));
} elseif (isset($argv[1]) && $argv[1] == "all") {
echo "All-argument was presented. Looking for all tags" . PHP_EOL;
$completeMarkDown = [];
Expand All @@ -322,7 +322,7 @@ function printMarkdown(array $markDown): void
$completeMarkDown[] = $markDownLine;
}
}
file_put_contents(dirname(__FILE__) . '/CHANGELOG.md', implode("\n", $completeMarkDown));
file_put_contents(__DIR__ . '/CHANGELOG.md', implode("\n", $completeMarkDown));
} else {
echo "No tags were found" . PHP_EOL;
}
Expand All @@ -332,5 +332,5 @@ function printMarkdown(array $markDown): void
$currTag = $argv[2];
echo " - prevTag: $prevTag" . PHP_EOL;
echo " - currTag: $currTag" . PHP_EOL;
file_put_contents(dirname(__FILE__) . '/CHANGELOG.md', implode("\n", getMarkDown($prevTag, $currTag)));
file_put_contents(__DIR__ . '/CHANGELOG.md', implode("\n", getMarkDown($prevTag, $currTag)));
}
32 changes: 16 additions & 16 deletions make/gencodelists.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use horstoeko\stringmanagement\PathUtils;

require dirname(__FILE__) . "/../vendor/autoload.php";
require __DIR__ . "/../vendor/autoload.php";

define('DOWNLOADDEF_KEY_ENABLED', 'enabled');
define('DOWNLOADDEF_LIB_NAME', 'libname');
Expand Down Expand Up @@ -194,7 +194,7 @@ function createCodeClassFromKositJson(array $fileToDownload): void
$classGenerationEnabled = $fileToDownload[DOWNLOADDEF_KEY_ENABLED] ?? false;
$classNamespace = $fileToDownload[DOWNLOADDEF_KEY_CLASSNAMESPACE];
$className = $fileToDownload[DOWNLOADDEF_KEY_CLASSNAME];
$classDir = PathUtils::combineAllPaths(dirname(__FILE__), "classes");
$classDir = PathUtils::combineAllPaths(__DIR__, "classes");
$classTitle = $fileToDownload[DOWNLOADDEF_KEY_TITLE];
$classTitleList = $fileToDownload[DOWNLOADDEF_KEY_TITLE_LIST];
$classHomepageUrls = !is_array($fileToDownload[DOWNLOADDEF_KEY_URL_HP]) ? [$fileToDownload[DOWNLOADDEF_KEY_URL_HP]] : $fileToDownload[DOWNLOADDEF_KEY_URL_HP];
Expand Down Expand Up @@ -404,8 +404,8 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:untdid.5189_3/download/UNTDID_5189_3.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_7161.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_5189.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_7161.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_5189.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:untdid.7161",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -425,7 +425,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:country-codes_8/download/Country_Codes_8.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "ISO_COUNTRY_CODES.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "ISO_COUNTRY_CODES.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:country-codes",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -448,7 +448,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:currency-codes_3/download/Currency_Codes_3.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "ISO_CURRENCY_CODES.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "ISO_CURRENCY_CODES.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:currency-codes",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -471,7 +471,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:untdid.5305_3/download/UNTDID_5305_3.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_5305.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_5305.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:untdid.5305",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -494,7 +494,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:untdid.1001_4/download/UNTDID_1001_4.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_1001.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_1001.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:untdid.1001",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -514,7 +514,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:untdid.7143_4/download/UNTDID_7143_4.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_7143.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_7143.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:untdid.7143",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -534,7 +534,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:xrechnung:codeliste:untdid.4461_3/download/UNTDID_4461_3.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_4461.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_4461.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:xrechnung:codeliste:untdid.4461",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -554,7 +554,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:untdid.1153_3/download/UNTDID_1153_3.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_1153.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_1153.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:untdid.1153",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -574,7 +574,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:untdid.4451_4/download/UNTDID_4451_4.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_4451.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_4451.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:untdid.4451",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -594,7 +594,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:icd_5/download/ICD_5.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "ICD_5.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "ICD_5.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:icd",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand All @@ -615,8 +615,8 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:rec21_3/download/UN_ECE_Recommendation_N_21_3.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNECE_REC_20.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNECE_REC_21.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNECE_REC_20.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNECE_REC_21.json"),
],
DOWNLOADDEF_KEY_URL_HP => [
"https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:rec20",
Expand All @@ -639,7 +639,7 @@ function createCodeClasses(array $filesToDownload): void
"https://www.xrepository.de/api/xrepository/urn:xoev-de:kosit:codeliste:untdid.5305_3/download/UNTDID_5305_3.json",
],
DOWNLOADDEF_KEY_TOFILE => [
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(dirname(__FILE__), "download"), "UNTDID_5305.json"),
PathUtils::combinePathWithFile(PathUtils::combineAllPaths(__DIR__, "download"), "UNTDID_5305.json"),
],
DOWNLOADDEF_KEY_URL_HP => "https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:untdid.5305_3",
DOWNLOADDEF_KEY_CLASSNAMESPACE => "horstoeko\zugferd\codelists",
Expand Down
46 changes: 23 additions & 23 deletions make/genmethoddocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use phpDocumentor\Reflection\Exception\PcreException;
use Webmozart\Assert\InvalidArgumentException;

require dirname(__FILE__) . "/../vendor/autoload.php";
require __DIR__ . "/../vendor/autoload.php";

class CustomPhpPrinter extends Printer
{
Expand Down Expand Up @@ -211,7 +211,7 @@ public function getArray(): array

$parameters[] = [
'name' => $parameterName,
'type' => $parameterTypeString ? $parameterTypeString : 'mixed',
'type' => $parameterTypeString ?: 'mixed',
'isNullable' => $parameterType && $parameterType->allowsNull(),
'defaultValueavailable' => $parameter->isOptional() ? ($parameter->isDefaultValueAvailable() ? true : false) : false,
'defaultValue' => $parameter->isOptional() ? ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null) : null,
Expand Down Expand Up @@ -309,7 +309,7 @@ public function generateMarkdown(): MarkDownGenerator
$this->addEmptyLine();
}

$this->addExample(dirname(__FILE__) . sprintf('/md/%s.md', $this->extractor->getClassBasename()), true);
$this->addExample(__DIR__ . sprintf('/md/%s.md', $this->extractor->getClassBasename()), true);

if (!empty($metaData['methods'])) {
$this->addLineH2("Methods");
Expand Down Expand Up @@ -401,7 +401,7 @@ public function generateMarkdown(): MarkDownGenerator
$this->addEmptyLine();
}

$this->addExample(dirname(__FILE__) . sprintf('/md/%s_%s.md', $this->extractor->getClassBasename(), $methodName));
$this->addExample(__DIR__ . sprintf('/md/%s_%s.md', $this->extractor->getClassBasename(), $methodName));
}

return $this;
Expand Down Expand Up @@ -623,7 +623,7 @@ private function addExample(string $exampleFilename, bool $isClass = false): Mar
$this->addLineH4("Example");
}

$exampleFileContent = str_replace(array("\r\n", "\r", "\n"), "\n", $exampleFileContent);
$exampleFileContent = str_replace(["\r\n", "\r", "\n"], "\n", $exampleFileContent);

foreach (explode("\n", $exampleFileContent) as $exampleFileContentLine) {
$this->lines[] = $exampleFileContentLine;
Expand Down Expand Up @@ -719,24 +719,24 @@ public static function generate(array $classes, array $ignoreInheritance = [])
}

BatchMarkDownGenerator::generate([
ZugferdDocument::class => dirname(__FILE__) . '/Class-ZugferdDocument.md',
ZugferdSettings::class => dirname(__FILE__) . '/Class-ZugferdSettings.md',
ZugferdDocumentBuilder::class => dirname(__FILE__) . '/Class-ZugferdDocumentBuilder.md',
ZugferdDocumentReader::class => dirname(__FILE__) . '/Class-ZugferdDocumentReader.md',
ZugferdDocumentPdfReader::class => dirname(__FILE__) . '/Class-ZugferdDocumentPdfReader.md',
ZugferdDocumentPdfReaderExt::class => dirname(__FILE__) . '/Class-ZugferdDocumentPdfReaderExt.md',
ZugferdDocumentPdfBuilder::class => dirname(__FILE__) . '/Class-ZugferdDocumentPdfBuilder.md',
ZugferdDocumentPdfMerger::class => dirname(__FILE__) . '/Class-ZugferdDocumentPdfMerger.md',
ZugferdDocumentValidator::class => dirname(__FILE__) . '/Class-ZugferdDocumentValidator.md',
ZugferdXsdValidator::class => dirname(__FILE__) . '/Class-ZugferdXsdValidator.md',
ZugferdKositValidator::class => dirname(__FILE__) . '/Class-ZugferdKositValidator.md',
ZugferdPdfValidator::class => dirname(__FILE__) . '/Class-ZugferdPdfValidator.md',
ZugferdQuickDescriptor::class => dirname(__FILE__) . '/Class-ZugferdQuickDescriptor.md',
ZugferdQuickDescriptorEn16931::class => dirname(__FILE__) . '/Class-ZugferdQuickDescriptorEn16931.md',
ZugferdQuickDescriptorExtended::class => dirname(__FILE__) . '/Class-ZugferdQuickDescriptorExtended.md',
ZugferdQuickDescriptorXRechnung::class => dirname(__FILE__) . '/Class-ZugferdQuickDescriptorXRechnung.md',
ZugferdQuickDescriptorXRechnung2::class => dirname(__FILE__) . '/Class-ZugferdQuickDescriptorXRechnung2.md',
ZugferdQuickDescriptorXRechnung3::class => dirname(__FILE__) . '/Class-ZugferdQuickDescriptorXRechnung3.md',
ZugferdDocument::class => __DIR__ . '/Class-ZugferdDocument.md',
ZugferdSettings::class => __DIR__ . '/Class-ZugferdSettings.md',
ZugferdDocumentBuilder::class => __DIR__ . '/Class-ZugferdDocumentBuilder.md',
ZugferdDocumentReader::class => __DIR__ . '/Class-ZugferdDocumentReader.md',
ZugferdDocumentPdfReader::class => __DIR__ . '/Class-ZugferdDocumentPdfReader.md',
ZugferdDocumentPdfReaderExt::class => __DIR__ . '/Class-ZugferdDocumentPdfReaderExt.md',
ZugferdDocumentPdfBuilder::class => __DIR__ . '/Class-ZugferdDocumentPdfBuilder.md',
ZugferdDocumentPdfMerger::class => __DIR__ . '/Class-ZugferdDocumentPdfMerger.md',
ZugferdDocumentValidator::class => __DIR__ . '/Class-ZugferdDocumentValidator.md',
ZugferdXsdValidator::class => __DIR__ . '/Class-ZugferdXsdValidator.md',
ZugferdKositValidator::class => __DIR__ . '/Class-ZugferdKositValidator.md',
ZugferdPdfValidator::class => __DIR__ . '/Class-ZugferdPdfValidator.md',
ZugferdQuickDescriptor::class => __DIR__ . '/Class-ZugferdQuickDescriptor.md',
ZugferdQuickDescriptorEn16931::class => __DIR__ . '/Class-ZugferdQuickDescriptorEn16931.md',
ZugferdQuickDescriptorExtended::class => __DIR__ . '/Class-ZugferdQuickDescriptorExtended.md',
ZugferdQuickDescriptorXRechnung::class => __DIR__ . '/Class-ZugferdQuickDescriptorXRechnung.md',
ZugferdQuickDescriptorXRechnung2::class => __DIR__ . '/Class-ZugferdQuickDescriptorXRechnung2.md',
ZugferdQuickDescriptorXRechnung3::class => __DIR__ . '/Class-ZugferdQuickDescriptorXRechnung3.md',
], [
'horstoeko\zugferd\ZugferdDocumentPdfBuilder::generateDocument',
'horstoeko\zugferd\ZugferdDocumentPdfMerger::generateDocument',
Expand Down
8 changes: 4 additions & 4 deletions src/ZugferdDocumentPdfBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,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 = array(
$pdfMetadata = [
'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 @@ -651,12 +651,12 @@ protected function extractInvoiceInformations(): array
break;
}

$invoiceInformation = array(
$invoiceInformation = [
'invoiceId' => $invoiceId,
'docTypeName' => $docTypeName,
'seller' => $sellerName,
'date' => $dateReformatted,
);
];

return $invoiceInformation;
}
Expand Down
Loading

0 comments on commit 6fdabab

Please sign in to comment.