From a5c8026e6b86e26a69e8d59e61c6bc42841b7150 Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Sat, 18 Jan 2025 12:15:22 +0100 Subject: [PATCH] [CS] Code Cleanup --- build/phprectorconfig.php | 2 +- .../02_ZugferdDocumentPdfBuilder_EN16931.php | 9 +- ...02_ZugferdDocumentPdfBuilder_XRECHNUNG.php | 9 +- make/genchangelog.php | 19 +++-- make/gencodelists.php | 3 + make/genmethoddocs.php | 71 ++++++++-------- src/ZugferdDocumentBuilder.php | 2 + src/ZugferdDocumentPdfBuilderAbstract.php | 7 +- src/ZugferdDocumentPdfMerger.php | 2 +- src/ZugferdDocumentReader.php | 82 +++++++++++++++++++ src/ZugferdObjectHelper.php | 25 ++++++ src/ZugferdPdfWriter.php | 13 ++- src/ZugferdProfileResolver.php | 3 +- src/exception/ZugferdExceptionCodes.php | 12 +++ src/quick/ZugferdQuickDescriptor.php | 10 +++ tests/testcases/PdfBuilderEn16931Test.php | 4 + tests/testcases/ProfileResolverTest.php | 2 +- tests/traits/HandlesXmlTests.php | 1 + 18 files changed, 223 insertions(+), 53 deletions(-) diff --git a/build/phprectorconfig.php b/build/phprectorconfig.php index debde2b1..e035d9d1 100644 --- a/build/phprectorconfig.php +++ b/build/phprectorconfig.php @@ -29,9 +29,9 @@ ->withPhp73Sets() ->withPreparedSets( codeQuality: true, + codingStyle: true, // carbon: false, - codingStyle: false, deadCode: false, doctrineCodeQuality: false, earlyReturn: false, diff --git a/examples/02_ZugferdDocumentPdfBuilder_EN16931.php b/examples/02_ZugferdDocumentPdfBuilder_EN16931.php index ad31551a..aa557e24 100644 --- a/examples/02_ZugferdDocumentPdfBuilder_EN16931.php +++ b/examples/02_ZugferdDocumentPdfBuilder_EN16931.php @@ -185,13 +185,16 @@ function ($which) { if ($which === 'title') { return "DummyTitle"; - } + } + if ($which === 'author') { return "DummyAuthor"; - } + } + if ($which === 'subject') { return "DummySubject"; - } + } + if ($which === 'keywords') { return "DummyKeywords"; } diff --git a/examples/02_ZugferdDocumentPdfBuilder_XRECHNUNG.php b/examples/02_ZugferdDocumentPdfBuilder_XRECHNUNG.php index 78f7b6c9..1019ba46 100644 --- a/examples/02_ZugferdDocumentPdfBuilder_XRECHNUNG.php +++ b/examples/02_ZugferdDocumentPdfBuilder_XRECHNUNG.php @@ -185,13 +185,16 @@ function ($which) { if ($which === 'title') { return "DummyTitle"; - } + } + if ($which === 'author') { return "DummyAuthor"; - } + } + if ($which === 'subject') { return "DummySubject"; - } + } + if ($which === 'keywords') { return "DummyKeywords"; } diff --git a/make/genchangelog.php b/make/genchangelog.php index f89008e2..71b283fa 100644 --- a/make/genchangelog.php +++ b/make/genchangelog.php @@ -68,14 +68,15 @@ function mustHideCommit(?string $commitHash = "", ?string $commitAuthor = "", ?s if (!$commitSubject) { return true; } - return stricontains($commitSubject, '[CS]') || stricontains($commitSubject, '[DOC]') || stricontains($commitSubject, '[INFR]') || stricontains($commitSubject, '[INFR}') || stricontains($commitSubject, 'Added CheckStyƶe Script to composer') || stricontains($commitSubject, 'Added dependabot.yml') || stricontains($commitSubject, 'Added PHP8.4 Build') || stricontains($commitSubject, 'Added single workflow for PHP 8.4') || stricontains($commitSubject, 'Added WIKI-Update workflow') || stricontains($commitSubject, 'build.ci') || stricontains($commitSubject, 'build.release') || stricontains($commitSubject, 'buildv2') || stricontains($commitSubject, 'build.yml') || stricontains($commitSubject, 'maintain-issues-stale') || stricontains($commitSubject, 'Class Documentation (Wiki) Generator improved') || stricontains($commitSubject, 'Class markdown generation for the wiki') || stricontains($commitSubject, 'Code styling') || stricontains($commitSubject, 'composer.json') || stricontains($commitSubject, 'Documentation') || stricontains($commitSubject, 'Enable all sources in gencodelists.php') || stricontains($commitSubject, 'Fix .gitgnore') || stricontains($commitSubject, 'Fix build.wiki.yml') || stricontains($commitSubject, 'Fix Class doc generation script') || stricontains($commitSubject, 'Fix class doc generator script') || stricontains($commitSubject, 'Fix DocBlock') || stricontains($commitSubject, 'Fix docs') || stricontains($commitSubject, 'Fix for generator of Wiki class documentation') || stricontains($commitSubject, 'Fix genmethoddocs') || stricontains($commitSubject, 'Fix GitHub workflows') || stricontains($commitSubject, 'Fix maintain-issues-stale.yml') || stricontains($commitSubject, 'Fix name of release workflow') || stricontains($commitSubject, 'Fix PHPStan Config') || stricontains($commitSubject, 'Fix README.md') || stricontains($commitSubject, 'Fix README.mD') || stricontains($commitSubject, 'Fix workflow') || stricontains($commitSubject, 'Fixed CheckStyle Issues') || stricontains($commitSubject, 'Fixed Fixed genmethoddocs') || stricontains($commitSubject, 'Fixed PHPMD issue') || stricontains($commitSubject, 'Format build.phpall.ant') || stricontains($commitSubject, 'Improved class documentation generator script') || stricontains($commitSubject, 'Improved DocBlocks') || stricontains($commitSubject, 'Improved docs') || stricontains($commitSubject, 'Improved linting in github actions') || stricontains($commitSubject, 'Improved matrix build') || stricontains($commitSubject, 'issue templates') || stricontains($commitSubject, 'Matrix build') || stricontains($commitSubject, 'Merge branch') || stricontains($commitSubject, 'Moved pull_request_template.md') || stricontains($commitSubject, 'New Release workflow added') || stricontains($commitSubject, 'PHPDoc') || stricontains($commitSubject, 'README.md') || stricontains($commitSubject, 'Removed build.php84.ant.yml') || stricontains($commitSubject, 'Removed dependabot.yml') || stricontains($commitSubject, 'Reordered methods') || stricontains($commitSubject, 'Reorganized test') || stricontains($commitSubject, 'Run Release Build on PHP 8.4') || stricontains($commitSubject, 'Set XDEBUG mode') || stricontains($commitSubject, 'Update build.wiki.yml') || stricontains($commitSubject, 'Update PHPDoc') || stricontains($commitSubject, 'Update wiki on release build') || stricontains($commitSubject, 'Updated action versions in all workflows') || stricontains($commitSubject, 'Updated README.md') || stricontains($commitSubject, 'Updated README.README.md') || stricontains($commitSubject, 'Updated script to create class overview for WIKI') || stricontains($commitSubject, 'Run CI\'s on PR\'s') || stricontains($commitSubject, 'Added badges') || stricontains($commitSubject, 'Fix Mock Tests') || stricontains($commitSubject, 'More code coverage') || stricontains($commitSubject, 'Code Doc Styling') || stricontains($commitSubject, 'Updated actions') || stricontains($commitSubject, 'Exclude .github-folder from action runner') || stricontains($commitSubject, 'config.yml') || stricontains($commitSubject, 'CONTRIBUTING.md') || stricontains($commitSubject, 'SECURITY.md') || stricontains($commitSubject, 'CODE_OF_CONDUCT.md') || stricontains($commitSubject, 'pull request template') || stricontains($commitSubject, 'Excluded examples folder from workflow runs') || stricontains($commitSubject, 'Allow manually run specific workflows') || stricontains($commitSubject, 'Added issue template for a question') || stricontains($commitSubject, 'Fix template for bug-report') || stricontains($commitSubject, 'Added issue template for a new feature') || stricontains($commitSubject, 'Fix bug report template') || stricontains($commitSubject, 'pull_request_template.md') || stricontains($commitSubject, 'Fixed CheckStyle Errors') || stricontains($commitSubject, 'Cleanup Buildscript') || stricontains($commitSubject, 'Ignore changes on MD-Files') || stricontains($commitSubject, 'Reformatted code') || stricontains($commitSubject, 'Code beautify') || stricontains($commitSubject, 'Code cleabing') || stricontains($commitSubject, 'Code cleaning') || stricontains($commitSubject, 'Used PHPCBF to make clean code') || stricontains($commitSubject, 'Used PHPCBF to make clean code') || stricontains($commitSubject, 'CheckStyle') || stricontains($commitSubject, 'Test reorganization') || stricontains($commitSubject, 'Made tests ready for PHPUnit10') || stricontains($commitSubject, 'Removed phpdox') || stricontains($commitSubject, 'Rename workflows') || stricontains($commitSubject, 'Removed useless .Jenkinsfile') || stricontains($commitSubject, 'Fix github action') || stricontains($commitSubject, 'Build infrastructure') || stricontains($commitSubject, 'Enhance build target') || stricontains($commitSubject, 'Fix ANT build script') || stricontains($commitSubject, 'Rename release workflow file') || stricontains($commitSubject, 'Fix build scrip') || stricontains($commitSubject, 'Removed temp files') || stricontains($commitSubject, 'gitignore') || stricontains($commitSubject, 'Removed sami') || stricontains($commitSubject, 'GitHub-Actions') || stricontains($commitSubject, 'Fix phpdox download url') || stricontains($commitSubject, 'Added composer scripts') || stricontains($commitSubject, 'Added build workflow') || stricontains($commitSubject, 'Added release workflow') || stricontains($commitSubject, 'Added action for php') || stricontains($commitSubject, 'Phing') || stricontains($commitSubject, 'Fix tests') || stricontains($commitSubject, 'Excluded entities subdirectory from phpdox') || stricontains($commitSubject, 'Fixed code with PHPCBF using PSR12 Standard') || stricontains($commitSubject, 'Added PHPCS Rulez for PSR12') || stricontains($commitSubject, 'Include PHPStan to ANT buildscript') || stricontains($commitSubject, 'Better code quality using phpstan') || stricontains($commitSubject, 'Code cleanup') || stricontains($commitSubject, 'Added workflows/build.ant.yml') || strcasecmp("Fixes", $commitSubject) === 0 || strcasecmp("Fix", $commitSubject) === 0; + + return stricontains($commitSubject, '[CS]') || stricontains($commitSubject, '[DOC]') || stricontains($commitSubject, '[INFR]') || stricontains($commitSubject, '[INFR}') || stricontains($commitSubject, 'Added CheckStyƶe Script to composer') || stricontains($commitSubject, 'Added dependabot.yml') || stricontains($commitSubject, 'Added PHP8.4 Build') || stricontains($commitSubject, 'Added single workflow for PHP 8.4') || stricontains($commitSubject, 'Added WIKI-Update workflow') || stricontains($commitSubject, 'build.ci') || stricontains($commitSubject, 'build.release') || stricontains($commitSubject, 'buildv2') || stricontains($commitSubject, 'build.yml') || stricontains($commitSubject, 'maintain-issues-stale') || stricontains($commitSubject, 'Class Documentation (Wiki) Generator improved') || stricontains($commitSubject, 'Class markdown generation for the wiki') || stricontains($commitSubject, 'Code styling') || stricontains($commitSubject, 'composer.json') || stricontains($commitSubject, 'Documentation') || stricontains($commitSubject, 'Enable all sources in gencodelists.php') || stricontains($commitSubject, 'Fix .gitgnore') || stricontains($commitSubject, 'Fix build.wiki.yml') || stricontains($commitSubject, 'Fix Class doc generation script') || stricontains($commitSubject, 'Fix class doc generator script') || stricontains($commitSubject, 'Fix DocBlock') || stricontains($commitSubject, 'Fix docs') || stricontains($commitSubject, 'Fix for generator of Wiki class documentation') || stricontains($commitSubject, 'Fix genmethoddocs') || stricontains($commitSubject, 'Fix GitHub workflows') || stricontains($commitSubject, 'Fix maintain-issues-stale.yml') || stricontains($commitSubject, 'Fix name of release workflow') || stricontains($commitSubject, 'Fix PHPStan Config') || stricontains($commitSubject, 'Fix README.md') || stricontains($commitSubject, 'Fix README.mD') || stricontains($commitSubject, 'Fix workflow') || stricontains($commitSubject, 'Fixed CheckStyle Issues') || stricontains($commitSubject, 'Fixed Fixed genmethoddocs') || stricontains($commitSubject, 'Fixed PHPMD issue') || stricontains($commitSubject, 'Format build.phpall.ant') || stricontains($commitSubject, 'Improved class documentation generator script') || stricontains($commitSubject, 'Improved DocBlocks') || stricontains($commitSubject, 'Improved docs') || stricontains($commitSubject, 'Improved linting in github actions') || stricontains($commitSubject, 'Improved matrix build') || stricontains($commitSubject, 'issue templates') || stricontains($commitSubject, 'Matrix build') || stricontains($commitSubject, 'Merge branch') || stricontains($commitSubject, 'Moved pull_request_template.md') || stricontains($commitSubject, 'New Release workflow added') || stricontains($commitSubject, 'PHPDoc') || stricontains($commitSubject, 'README.md') || stricontains($commitSubject, 'Removed build.php84.ant.yml') || stricontains($commitSubject, 'Removed dependabot.yml') || stricontains($commitSubject, 'Reordered methods') || stricontains($commitSubject, 'Reorganized test') || stricontains($commitSubject, 'Run Release Build on PHP 8.4') || stricontains($commitSubject, 'Set XDEBUG mode') || stricontains($commitSubject, 'Update build.wiki.yml') || stricontains($commitSubject, 'Update PHPDoc') || stricontains($commitSubject, 'Update wiki on release build') || stricontains($commitSubject, 'Updated action versions in all workflows') || stricontains($commitSubject, 'Updated README.md') || stricontains($commitSubject, 'Updated README.README.md') || stricontains($commitSubject, 'Updated script to create class overview for WIKI') || stricontains($commitSubject, "Run CI's on PR's") || stricontains($commitSubject, 'Added badges') || stricontains($commitSubject, 'Fix Mock Tests') || stricontains($commitSubject, 'More code coverage') || stricontains($commitSubject, 'Code Doc Styling') || stricontains($commitSubject, 'Updated actions') || stricontains($commitSubject, 'Exclude .github-folder from action runner') || stricontains($commitSubject, 'config.yml') || stricontains($commitSubject, 'CONTRIBUTING.md') || stricontains($commitSubject, 'SECURITY.md') || stricontains($commitSubject, 'CODE_OF_CONDUCT.md') || stricontains($commitSubject, 'pull request template') || stricontains($commitSubject, 'Excluded examples folder from workflow runs') || stricontains($commitSubject, 'Allow manually run specific workflows') || stricontains($commitSubject, 'Added issue template for a question') || stricontains($commitSubject, 'Fix template for bug-report') || stricontains($commitSubject, 'Added issue template for a new feature') || stricontains($commitSubject, 'Fix bug report template') || stricontains($commitSubject, 'pull_request_template.md') || stricontains($commitSubject, 'Fixed CheckStyle Errors') || stricontains($commitSubject, 'Cleanup Buildscript') || stricontains($commitSubject, 'Ignore changes on MD-Files') || stricontains($commitSubject, 'Reformatted code') || stricontains($commitSubject, 'Code beautify') || stricontains($commitSubject, 'Code cleabing') || stricontains($commitSubject, 'Code cleaning') || stricontains($commitSubject, 'Used PHPCBF to make clean code') || stricontains($commitSubject, 'Used PHPCBF to make clean code') || stricontains($commitSubject, 'CheckStyle') || stricontains($commitSubject, 'Test reorganization') || stricontains($commitSubject, 'Made tests ready for PHPUnit10') || stricontains($commitSubject, 'Removed phpdox') || stricontains($commitSubject, 'Rename workflows') || stricontains($commitSubject, 'Removed useless .Jenkinsfile') || stricontains($commitSubject, 'Fix github action') || stricontains($commitSubject, 'Build infrastructure') || stricontains($commitSubject, 'Enhance build target') || stricontains($commitSubject, 'Fix ANT build script') || stricontains($commitSubject, 'Rename release workflow file') || stricontains($commitSubject, 'Fix build scrip') || stricontains($commitSubject, 'Removed temp files') || stricontains($commitSubject, 'gitignore') || stricontains($commitSubject, 'Removed sami') || stricontains($commitSubject, 'GitHub-Actions') || stricontains($commitSubject, 'Fix phpdox download url') || stricontains($commitSubject, 'Added composer scripts') || stricontains($commitSubject, 'Added build workflow') || stricontains($commitSubject, 'Added release workflow') || stricontains($commitSubject, 'Added action for php') || stricontains($commitSubject, 'Phing') || stricontains($commitSubject, 'Fix tests') || stricontains($commitSubject, 'Excluded entities subdirectory from phpdox') || stricontains($commitSubject, 'Fixed code with PHPCBF using PSR12 Standard') || stricontains($commitSubject, 'Added PHPCS Rulez for PSR12') || stricontains($commitSubject, 'Include PHPStan to ANT buildscript') || stricontains($commitSubject, 'Better code quality using phpstan') || stricontains($commitSubject, 'Code cleanup') || stricontains($commitSubject, 'Added workflows/build.ant.yml') || strcasecmp("Fixes", $commitSubject) === 0 || strcasecmp("Fix", $commitSubject) === 0; } function getMarkDown($prevTag, $currTag) { $markDown = []; - echo "Getting commits from $prevTag to $currTag" . PHP_EOL; + echo sprintf('Getting commits from %s to %s', $prevTag, $currTag) . PHP_EOL; $commitStr = shell_exec(sprintf('git log --oneline --format="%%h|%%an|%%ad|%%s" "%s..%s"', $prevTag, $currTag)); @@ -97,6 +98,7 @@ function getMarkDown($prevTag, $currTag) if ($hidden) { $noOfHiddenCommits++; } + return !$hidden; }); @@ -144,6 +146,7 @@ function getMarkDown($prevTag, $currTag) $markDown[] = ":exclamation: _There is one internal commit_"; $markDown[] = ''; } + if ($noOfHiddenCommits > 1) { $markDown[] = sprintf(":exclamation: _There are %s internal commit(s)_", $noOfHiddenCommits); $markDown[] = ''; @@ -169,8 +172,8 @@ function printMarkdown(array $markDown): void $prevTag = trim(shell_exec(sprintf('git describe --abbrev=0 --tags %s', $lastHash))); $currTag = trim(shell_exec('git describe --tags --abbrev=0')); echo "Found tags..." . PHP_EOL; - echo " - prevTag: $prevTag" . PHP_EOL; - echo " - currTag: $currTag" . PHP_EOL; + echo ' - prevTag: ' . $prevTag . PHP_EOL; + echo ' - currTag: ' . $currTag . PHP_EOL; 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; @@ -185,13 +188,15 @@ function printMarkdown(array $markDown): void if (!isset($allTags[$currTagKey + 1])) { continue; } + $prevTag = $allTags[$currTagKey + 1]; - echo "Looking for tag $currTag (Previous: $prevTag)" . PHP_EOL; + echo sprintf('Looking for tag %s (Previous: %s)', $currTag, $prevTag) . PHP_EOL; $markDown = getMarkDown($prevTag, $currTag); foreach ($markDown as $markDownLine) { $completeMarkDown[] = $markDownLine; } } + file_put_contents(__DIR__ . '/CHANGELOG.md', implode("\n", $completeMarkDown)); } else { echo "No tags were found" . PHP_EOL; @@ -200,7 +205,7 @@ function printMarkdown(array $markDown): void echo "First and previous tag were presented" . PHP_EOL; $prevTag = $argv[1]; $currTag = $argv[2]; - echo " - prevTag: $prevTag" . PHP_EOL; - echo " - currTag: $currTag" . PHP_EOL; + echo ' - prevTag: ' . $prevTag . PHP_EOL; + echo ' - currTag: ' . $currTag . PHP_EOL; file_put_contents(__DIR__ . '/CHANGELOG.md', implode("\n", getMarkDown($prevTag, $currTag))); } diff --git a/make/gencodelists.php b/make/gencodelists.php index fd937ddf..d57dd6ad 100644 --- a/make/gencodelists.php +++ b/make/gencodelists.php @@ -82,6 +82,7 @@ function strIdentifier(string $str, bool $shortIdentifier): string $str = str_replace("\t", "", $str); $str = strtoupper($str); $str = preg_replace("/[^A-Za-z0-9\s]/", "", $str); + $strArray = explode(" ", $str); if (count($strArray) == 1) { $strNew = $strArray[0]; @@ -90,6 +91,7 @@ function strIdentifier(string $str, bool $shortIdentifier): string if ($strNew !== "") { $strNew .= "_"; } + if ($shortIdentifier) { $strNew .= substr($item, 0, 4); } else { @@ -97,6 +99,7 @@ function strIdentifier(string $str, bool $shortIdentifier): string } } } + $strNew = preg_replace('/__+/', '_', $strNew); $strNew = preg_replace('~\d~', '', $strNew, 5); $strNew = rtrim(ltrim($strNew, "_"), "_"); diff --git a/make/genmethoddocs.php b/make/genmethoddocs.php index d4b56e36..6c5aa335 100644 --- a/make/genmethoddocs.php +++ b/make/genmethoddocs.php @@ -200,6 +200,7 @@ public function getArray(): array foreach ($types as $type) { $parameterTypeString .= $type->getName() . '|'; } + $parameterTypeString = rtrim($parameterTypeString, '|'); } elseif ($parameterType instanceof ReflectionNamedType) { $parameterTypeString = $parameterType->getName(); @@ -672,9 +673,11 @@ private function fixPhpType(string $string): string if (stripos($string, '[]') !== false) { $string = 'array'; } + if (stripos($string, 'array<') === 0) { $string = 'array'; } + if ($string === '$this') { $string = 'static'; } @@ -736,38 +739,38 @@ public static function generate(array $classes, array $ignoreInheritance = []) ZugferdQuickDescriptorXRechnung2::class => __DIR__ . '/Class-ZugferdQuickDescriptorXRechnung2.md', ZugferdQuickDescriptorXRechnung3::class => __DIR__ . '/Class-ZugferdQuickDescriptorXRechnung3.md', ], [ - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::generateDocument', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::generateDocument', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::saveDocument', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::saveDocument', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::saveDocumentInline', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::saveDocumentInline', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::downloadString', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::downloadString', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setAdditionalCreatorTool', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setAdditionalCreatorTool', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setAttachmentRelationshipType', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setAttachmentRelationshipType', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setAttachmentRelationshipTypeToData', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setAttachmentRelationshipTypeToData', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setAttachmentRelationshipTypeToAlternative', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setAttachmentRelationshipTypeToAlternative', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setAttachmentRelationshipTypeToSource', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setAttachmentRelationshipTypeToSource', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::attachAdditionalFileByRealFile', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::attachAdditionalFileByRealFile', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::attachAdditionalFileByContent', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::attachAdditionalFileByContent', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setDeterministicModeEnabled', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setDeterministicModeEnabled', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setAuthorTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setAuthorTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setKeywordTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setKeywordTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setTitleTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setTitleTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setSubjectTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setSubjectTemplate', - 'horstoeko\zugferd\ZugferdDocumentPdfBuilder::setMetaInformationCallback', - 'horstoeko\zugferd\ZugferdDocumentPdfMerger::setMetaInformationCallback', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::generateDocument', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::generateDocument', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::saveDocument', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::saveDocument', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::saveDocumentInline', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::saveDocumentInline', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::downloadString', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::downloadString', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setAdditionalCreatorTool', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setAdditionalCreatorTool', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setAttachmentRelationshipType', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setAttachmentRelationshipType', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setAttachmentRelationshipTypeToData', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setAttachmentRelationshipTypeToData', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setAttachmentRelationshipTypeToAlternative', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setAttachmentRelationshipTypeToAlternative', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setAttachmentRelationshipTypeToSource', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setAttachmentRelationshipTypeToSource', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::attachAdditionalFileByRealFile', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::attachAdditionalFileByRealFile', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::attachAdditionalFileByContent', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::attachAdditionalFileByContent', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setDeterministicModeEnabled', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setDeterministicModeEnabled', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setAuthorTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setAuthorTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setKeywordTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setKeywordTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setTitleTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setTitleTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setSubjectTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setSubjectTemplate', + \horstoeko\zugferd\ZugferdDocumentPdfBuilder::class . '::setMetaInformationCallback', + \horstoeko\zugferd\ZugferdDocumentPdfMerger::class . '::setMetaInformationCallback', ]); diff --git a/src/ZugferdDocumentBuilder.php b/src/ZugferdDocumentBuilder.php index 9ed2dca2..225d2686 100644 --- a/src/ZugferdDocumentBuilder.php +++ b/src/ZugferdDocumentBuilder.php @@ -271,6 +271,7 @@ public function setForeignCurrency(string $foreignCurrencyCode, float $foreignTa if ($this->getObjectHelper()->tryCallAndReturn($taxTotalAmount, "getCurrencyID") == $invoiceCurrencyCode) { $taxTotalAmountInvoice = $taxTotalAmount; } + if ($this->getObjectHelper()->tryCallAndReturn($taxTotalAmount, "getCurrencyID") == $foreignCurrencyCode) { $taxTotalAmountForeign = $taxTotalAmount; } @@ -2501,6 +2502,7 @@ public function setDocumentSummation(float $grandTotalAmount, float $duePayableA $invoiceCurrencyCode = $this->getObjectHelper()->tryCallByPathAndReturn($this->headerTradeSettlement, "getInvoiceCurrencyCode.value"); $this->getObjectHelper()->tryCall($taxTotalAmount[0], 'setCurrencyID', $invoiceCurrencyCode); } + return $this; } diff --git a/src/ZugferdDocumentPdfBuilderAbstract.php b/src/ZugferdDocumentPdfBuilderAbstract.php index 3ec919e6..a042ed8d 100644 --- a/src/ZugferdDocumentPdfBuilderAbstract.php +++ b/src/ZugferdDocumentPdfBuilderAbstract.php @@ -43,9 +43,13 @@ abstract class ZugferdDocumentPdfBuilderAbstract * 'Data', 'Alternative', 'Source', 'Supplement', 'Unspecified' */ public const AF_RELATIONSHIP_DATA = "Data"; + public const AF_RELATIONSHIP_ALTERNATIVE = "Alternative"; + public const AF_RELATIONSHIP_SOURCE = "Source"; + public const AF_RELATIONSHIP_SUPPLEMENT = "Supplement"; + public const AF_RELATIONSHIP_UNSPECIFIED = "Unspecified"; /** @@ -566,6 +570,7 @@ private function updatePdfMetadata(): void $descNodes->title->children('rdf', true)->Alt->li = $pdfMetadataInfos['title']; $descNodes->creator->children('rdf', true)->Seq->li = $pdfMetadataInfos['author']; $descNodes->description->children('rdf', true)->Alt->li = $pdfMetadataInfos['subject']; + $this->pdfWriter->addMetadataDescriptionNode($descDc->asXML()); $descAdobe = $descriptionNodes[4]; @@ -668,7 +673,7 @@ private function isFile($pdfData): bool { try { return @is_file($pdfData); - } catch (Throwable $ex) { + } catch (Throwable $throwable) { return false; } } diff --git a/src/ZugferdDocumentPdfMerger.php b/src/ZugferdDocumentPdfMerger.php index 2d524335..27978686 100644 --- a/src/ZugferdDocumentPdfMerger.php +++ b/src/ZugferdDocumentPdfMerger.php @@ -108,7 +108,7 @@ private function xmlDataIsFile(): bool { try { return @is_file($this->xmlDataOrFilename); - } catch (\TypeError $ex) { + } catch (\TypeError $typeError) { return false; } } diff --git a/src/ZugferdDocumentReader.php b/src/ZugferdDocumentReader.php index 6d09e5a3..fbdaa6fe 100644 --- a/src/ZugferdDocumentReader.php +++ b/src/ZugferdDocumentReader.php @@ -552,7 +552,9 @@ public function getDocumentSellerLegalOrganisation(?string &$legalOrgId, ?string public function firstDocumentSellerContact(): bool { $this->documentSellerContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getSellerTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentSellerContactPointer]); } @@ -565,7 +567,9 @@ public function firstDocumentSellerContact(): bool public function nextDocumentSellerContact(): bool { $this->documentSellerContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getSellerTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentSellerContactPointer]); } @@ -705,7 +709,9 @@ public function getDocumentBuyerLegalOrganisation(?string &$legalOrgId, ?string public function firstDocumentBuyerContact(): bool { $this->documentBuyerContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getBuyerTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentBuyerContactPointer]); } @@ -718,7 +724,9 @@ public function firstDocumentBuyerContact(): bool public function nextDocumentBuyerContact(): bool { $this->documentBuyerContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getBuyerTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentBuyerContactPointer]); } @@ -858,7 +866,9 @@ public function getDocumentSellerTaxRepresentativeLegalOrganisation(?string &$le public function firstDocumentSellerTaxRepresentativeContact(): bool { $this->documentSellerTaxRepresentativeContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getSellerTaxRepresentativeTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentSellerTaxRepresentativeContactPointer]); } @@ -871,7 +881,9 @@ public function firstDocumentSellerTaxRepresentativeContact(): bool public function nextDocumentSellerTaxRepresentativeContact(): bool { $this->documentSellerTaxRepresentativeContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getSellerTaxRepresentativeTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentSellerTaxRepresentativeContactPointer]); } @@ -997,7 +1009,9 @@ public function getDocumentProductEndUserLegalOrganisation(?string &$legalOrgId, public function firstDocumentProductEndUserContactContact(): bool { $this->documentProductEndUserContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getProductEndUserTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentProductEndUserContactPointer]); } @@ -1010,7 +1024,9 @@ public function firstDocumentProductEndUserContactContact(): bool public function nextDocumentProductEndUserContactContact(): bool { $this->documentProductEndUserContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getProductEndUserTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentProductEndUserContactPointer]); } @@ -1135,7 +1151,9 @@ public function getDocumentShipToLegalOrganisation(?string &$legalOrgid, ?string public function firstDocumentShipToContact(): bool { $this->documentShipToContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeDelivery.getShipToTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentShipToContactPointer]); } @@ -1148,7 +1166,9 @@ public function firstDocumentShipToContact(): bool public function nextDocumentShipToContact(): bool { $this->documentShipToContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeDelivery.getShipToTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentShipToContactPointer]); } @@ -1273,7 +1293,9 @@ public function getDocumentUltimateShipToLegalOrganisation(?string &$legalOrgId, public function firstDocumentUltimateShipToContact(): bool { $this->documentUltimateShipToContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeDelivery.getUltimateShipToTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentUltimateShipToContactPointer]); } @@ -1286,7 +1308,9 @@ public function firstDocumentUltimateShipToContact(): bool public function nextDocumentUltimateShipToContact(): bool { $this->documentUltimateShipToContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeDelivery.getUltimateShipToTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentUltimateShipToContactPointer]); } @@ -1412,7 +1436,9 @@ public function getDocumentShipFromLegalOrganisation(?string &$legalOrgId, ?stri public function firstDocumentShipFromContact(): bool { $this->documentShipFromContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeDelivery.getShipFromTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentShipFromContactPointer]); } @@ -1425,7 +1451,9 @@ public function firstDocumentShipFromContact(): bool public function nextDocumentShipFromContact(): bool { $this->documentShipFromContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeDelivery.getShipFromTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentShipFromContactPointer]); } @@ -1550,7 +1578,9 @@ public function getDocumentInvoicerLegalOrganisation(?string &$legalOrgId, ?stri public function firstDocumentInvoicerContact(): bool { $this->documentInvoicerContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getInvoicerTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentInvoicerContactPointer]); } @@ -1563,7 +1593,9 @@ public function firstDocumentInvoicerContact(): bool public function nextDocumentInvoicerContact(): bool { $this->documentInvoicerContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getInvoicerTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentInvoicerContactPointer]); } @@ -1689,7 +1721,9 @@ public function getDocumentInvoiceeLegalOrganisation(?string &$legalOrgId, ?stri public function firstDocumentInvoiceeContact(): bool { $this->documentInvoiceeContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getInvoiceeTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentInvoiceeContactPointer]); } @@ -1702,7 +1736,9 @@ public function firstDocumentInvoiceeContact(): bool public function nextDocumentInvoiceeContact(): bool { $this->documentInvoiceeContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getInvoiceeTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentInvoiceeContactPointer]); } @@ -1829,7 +1865,9 @@ public function getDocumentPayeeLegalOrganisation(?string &$legalOrgId, ?string public function firstDocumentPayeeContact(): bool { $this->documentPayeeContactPointer = 0; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getPayeeTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentPayeeContactPointer]); } @@ -1842,7 +1880,9 @@ public function firstDocumentPayeeContact(): bool public function nextDocumentPayeeContact(): bool { $this->documentPayeeContactPointer++; + $contacts = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getPayeeTradeParty.getDefinedTradeContact", [])); + return isset($contacts[$this->documentPayeeContactPointer]); } @@ -1963,7 +2003,9 @@ public function getDocumentContractReferencedDocument(?string &$issuerAssignedId public function firstDocumentAdditionalReferencedDocument(): bool { $this->documentAddRefDocPointer = 0; + $addRefDoc = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getAdditionalReferencedDocument", []); + return isset($addRefDoc[$this->documentAddRefDocPointer]); } @@ -1976,7 +2018,9 @@ public function firstDocumentAdditionalReferencedDocument(): bool public function nextDocumentAdditionalReferencedDocument(): bool { $this->documentAddRefDocPointer++; + $addRefDoc = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getAdditionalReferencedDocument", []); + return isset($addRefDoc[$this->documentAddRefDocPointer]); } @@ -2070,7 +2114,9 @@ public function getDocumentAdditionalReferencedDocuments(?array &$refDocs): Zugf public function firstDocumentInvoiceReferencedDocument(): bool { $this->documentInvRefDocPointer = 0; + $addRefDoc = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getInvoiceReferencedDocument", []); + return isset($addRefDoc[$this->documentInvRefDocPointer]); } @@ -2082,7 +2128,9 @@ public function firstDocumentInvoiceReferencedDocument(): bool public function nextDocumentInvoiceReferencedDocument(): bool { $this->documentInvRefDocPointer++; + $addRefDoc = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getInvoiceReferencedDocument", []); + return isset($addRefDoc[$this->documentInvRefDocPointer]); } @@ -2154,7 +2202,9 @@ public function getDocumentProcuringProject(?string &$id, ?string &$name): Zugfe public function firstDocumentUltimateCustomerOrderReferencedDocument(): bool { $this->documentUltimateCustomerOrderReferencedDocumentPointer = 0; + $addRefDoc = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getUltimateCustomerOrderReferencedDocument", []); + return isset($addRefDoc[$this->documentUltimateCustomerOrderReferencedDocumentPointer]); } @@ -2166,7 +2216,9 @@ public function firstDocumentUltimateCustomerOrderReferencedDocument(): bool public function nextDocumentUltimateCustomerOrderReferencedDocument(): bool { $this->documentUltimateCustomerOrderReferencedDocumentPointer++; + $addRefDoc = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeAgreement.getUltimateCustomerOrderReferencedDocument", []); + return isset($addRefDoc[$this->documentUltimateCustomerOrderReferencedDocumentPointer]); } @@ -2281,7 +2333,9 @@ public function getDocumentDeliveryNoteReferencedDocument(?string &$issuerAssign public function firstGetDocumentPaymentMeans(): bool { $this->documentPaymentMeansPointer = 0; + $paymentMeans = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementPaymentMeans", [])); + return isset($paymentMeans[$this->documentPaymentMeansPointer]); } @@ -2294,7 +2348,9 @@ public function firstGetDocumentPaymentMeans(): bool public function nextGetDocumentPaymentMeans(): bool { $this->documentPaymentMeansPointer++; + $paymentMeans = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementPaymentMeans", [])); + return isset($paymentMeans[$this->documentPaymentMeansPointer]); } @@ -2351,7 +2407,9 @@ public function getDocumentPaymentMeans(?string &$typeCode, ?string &$informatio public function firstDocumentTax(): bool { $this->documentTaxPointer = 0; + $taxes = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getApplicableTradeTax", [])); + return isset($taxes[$this->documentTaxPointer]); } @@ -2364,7 +2422,9 @@ public function firstDocumentTax(): bool public function nextDocumentTax(): bool { $this->documentTaxPointer++; + $taxes = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getApplicableTradeTax", [])); + return isset($taxes[$this->documentTaxPointer]); } @@ -2479,7 +2539,9 @@ public function getDocumentAllowanceCharges(?array &$allowanceCharge): ZugferdDo public function firstDocumentAllowanceCharge(): bool { $this->documentAllowanceChargePointer = 0; + $allowanceCharge = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeAllowanceCharge", []); + return isset($allowanceCharge[$this->documentAllowanceChargePointer]); } @@ -2492,7 +2554,9 @@ public function firstDocumentAllowanceCharge(): bool public function nextDocumentAllowanceCharge(): bool { $this->documentAllowanceChargePointer++; + $allowanceCharge = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeAllowanceCharge", []); + return isset($allowanceCharge[$this->documentAllowanceChargePointer]); } @@ -2544,6 +2608,7 @@ public function getDocumentAllowanceCharge(?float &$actualAmount, ?bool &$isChar public function firstDocumentLogisticsServiceCharge(): bool { $this->documentLogisticServiceChargePointer = 0; + $serviceCharge = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedLogisticsServiceCharge", []); return isset($serviceCharge[$this->documentLogisticServiceChargePointer]); @@ -2558,6 +2623,7 @@ public function firstDocumentLogisticsServiceCharge(): bool public function nextDocumentLogisticsServiceCharge(): bool { $this->documentLogisticServiceChargePointer++; + $serviceCharge = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedLogisticsServiceCharge", []); return isset($serviceCharge[$this->documentLogisticServiceChargePointer]); @@ -2639,7 +2705,9 @@ public function getDocumentPaymentTerms(?array &$paymentTerms): ZugferdDocumentR public function firstDocumentPaymentTerms(): bool { $this->documentPaymentTermsPointer = 0; + $paymentTerms = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradePaymentTerms", [])); + return isset($paymentTerms[$this->documentPaymentTermsPointer]); } @@ -2652,7 +2720,9 @@ public function firstDocumentPaymentTerms(): bool public function nextDocumentPaymentTerms(): bool { $this->documentPaymentTermsPointer++; + $paymentTerms = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradePaymentTerms", [])); + return isset($paymentTerms[$this->documentPaymentTermsPointer]); } @@ -2825,6 +2895,7 @@ public function getDocumentPositionNote(?string &$content, ?string &$contentCode { $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $tradeLineItemNote = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getAssociatedDocumentLineDocument.getIncludedNote", [])); $tradeLineItemNote = $tradeLineItemNote[$this->positionNotePointer]; @@ -2949,6 +3020,7 @@ public function getDocumentPositionProductCharacteristic(?string &$description, { $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $tradeLineItemProductCharacteristic = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getApplicableProductCharacteristic", [])); $tradeLineItemProductCharacteristic = $tradeLineItemProductCharacteristic[$this->positionProductCharacteristicPointer]; @@ -3010,6 +3082,7 @@ public function getDocumentPositionProductClassification(?string &$classCode, ?s { $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $tradeLineItemProductClassification = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getDesignatedProductClassification", [])); $tradeLineItemProductClassification = $tradeLineItemProductClassification[$this->positionProductClassificationPointer]; @@ -3074,6 +3147,7 @@ public function getDocumentPositionReferencedProduct(?string &$name, ?string &$d { $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $tradeLineItemReferencedProduct = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getIncludedReferencedProduct", [])); $tradeLineItemReferencedProduct = $tradeLineItemReferencedProduct[$this->positionReferencedProductPointer]; @@ -3193,6 +3267,7 @@ public function firstDocumentPositionAdditionalReferencedDocument(): bool $this->positionAddRefDocPointer = 0; $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $addRefDoc = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedLineTradeAgreement.getAdditionalReferencedDocument", [])); return isset($addRefDoc[$this->positionAddRefDocPointer]); } @@ -3206,9 +3281,12 @@ public function firstDocumentPositionAdditionalReferencedDocument(): bool public function nextDocumentPositionAdditionalReferencedDocument(): bool { $this->positionAddRefDocPointer++; + $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $addRefDoc = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedLineTradeAgreement.getAdditionalReferencedDocument", [])); + return isset($addRefDoc[$this->positionAddRefDocPointer]); } @@ -3288,6 +3366,7 @@ public function firstDocumentPositionGrossPriceAllowanceCharge(): bool $this->positionGrossPriceAllowanceChargePointer = 0; $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $allowanceCharge = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedLineTradeAgreement.getGrossPriceProductTradePrice.getAppliedTradeAllowanceCharge", [])); return isset($allowanceCharge[$this->positionGrossPriceAllowanceChargePointer]); } @@ -3301,9 +3380,12 @@ public function firstDocumentPositionGrossPriceAllowanceCharge(): bool public function nextDocumentPositionGrossPriceAllowanceCharge(): bool { $this->positionGrossPriceAllowanceChargePointer++; + $tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []); $tradeLineItem = $tradeLineItem[$this->positionPointer]; + $allowanceCharge = $this->getObjectHelper()->ensureArray($this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedLineTradeAgreement.getGrossPriceProductTradePrice.getAppliedTradeAllowanceCharge", [])); + return isset($allowanceCharge[$this->positionGrossPriceAllowanceChargePointer]); } diff --git a/src/ZugferdObjectHelper.php b/src/ZugferdObjectHelper.php index abc93417..db991128 100644 --- a/src/ZugferdObjectHelper.php +++ b/src/ZugferdObjectHelper.php @@ -593,6 +593,7 @@ public function getCrossIndustryInvoice() $crossIndustryInvoice->getExchangedDocumentContext()->setBusinessProcessSpecifiedDocumentContextParameter($this->createClassInstance('ram\DocumentContextParameterType')); $crossIndustryInvoice->getExchangedDocumentContext()->getBusinessProcessSpecifiedDocumentContextParameter()->setID($this->getIdType($this->profiledef['businessprocess'])); } + $crossIndustryInvoice->getSupplyChainTradeTransaction()->setApplicableHeaderTradeAgreement($this->createClassInstance('ram\HeaderTradeAgreementType')); $crossIndustryInvoice->getSupplyChainTradeTransaction()->setApplicableHeaderTradeDelivery($this->createClassInstance('ram\HeaderTradeDeliveryType')); $crossIndustryInvoice->getSupplyChainTradeTransaction()->setApplicableHeaderTradeSettlement($this->createClassInstance('ram\HeaderTradeSettlementType')); @@ -1227,6 +1228,7 @@ public function getSupplyChainTradeLineItemType(?string $lineId = null, ?string $this->tryCall($supplyChainTradeLineItemType, "setSpecifiedLineTradeAgreement", $lineTradeAgreementType); $this->tryCall($supplyChainTradeLineItemType, "setSpecifiedLineTradeDelivery", $lineTradeDeliveryType); } + $this->tryCall($supplyChainTradeLineItemType, "setSpecifiedLineTradeSettlement", $lineTradeSettlementType); return $supplyChainTradeLineItemType; @@ -1506,15 +1508,19 @@ public function tryCall($instance, string $method, $value): ZugferdObjectHelper if (!$instance) { return $this; } + if ($method === '') { return $this; } + if (self::isNullOrEmpty($value)) { return $this; } + if ($this->methodExists($instance, $method)) { $instance->$method($value); } + return $this; } @@ -1531,15 +1537,18 @@ public function tryCallAll($instance, array $methods, $value): ZugferdObjectHelp if (!$instance) { return $this; } + if (self::isNullOrEmpty($value)) { return $this; } + foreach ($methods as $method) { if ($this->methodExists($instance, $method)) { $instance->$method($value); return $this; } } + return $this; } @@ -1556,12 +1565,15 @@ public function tryCallAndReturn($instance, string $method) if (!$instance) { return null; } + if ($method === '') { return null; } + if ($this->methodExists($instance, $method)) { return $instance->$method(); } + return null; } @@ -1621,20 +1633,25 @@ public function tryCallIfMethodExists($instance, string $methodToLookFor, string if (!$instance) { return $this; } + if ($methodToLookFor === '') { return $this; } + if ($methodToCall === '') { return $this; } + if (!$this->methodExists($instance, $methodToCall)) { return $this; } + if ($this->methodExists($instance, $methodToLookFor)) { $instance->$methodToCall($value); } else { $instance->$methodToCall($value2); } + return $this; } @@ -1649,6 +1666,7 @@ public function ensureStringArray($input): array if (is_array($input)) { return $input; } + return [(string)$input]; } @@ -1664,8 +1682,10 @@ public function ensureArray($value): array if (!is_null($value)) { return [$value]; } + return []; } + return $value; } @@ -1680,6 +1700,7 @@ public static function isNullOrEmpty($value) if ($value === null) { return true; } + return !is_object($value) && (string)$value === ""; } @@ -1698,6 +1719,7 @@ public static function isAllNullOrEmpty(array $args): bool return false; } } + return true; } @@ -1718,6 +1740,7 @@ public static function isOneNullOrEmpty(array $args): bool return true; } } + return false; } @@ -1733,9 +1756,11 @@ public function methodExists($instance, $method): bool if ($instance == null) { return false; } + if (!is_object($instance) && !is_string($instance)) { return false; } + return method_exists($instance, $method); } } diff --git a/src/ZugferdPdfWriter.php b/src/ZugferdPdfWriter.php index ea79df43..5e4f1193 100644 --- a/src/ZugferdPdfWriter.php +++ b/src/ZugferdPdfWriter.php @@ -131,6 +131,7 @@ public function attach($file, $name = '', $desc = '', $relationship = 'Unspecifi if (false === $p) { $p = strrpos($file, '\\'); } + $name = false !== $p ? substr($file, $p + 1) : $file; } @@ -235,9 +236,11 @@ protected function putFileSpecification(array $file_info): void if ($file_info['relationship']) { $this->_put('/AFRelationship /' . $file_info['relationship']); } + if ($file_info['desc']) { $this->_put('/Desc ' . $this->_textstring($file_info['desc'])); } + $this->_put('/EF <<'); $this->_put('/F ' . ($this->n + 1) . ' 0 R'); $this->_put('/UF ' . ($this->n + 1) . ' 0 R'); @@ -259,6 +262,7 @@ protected function putFileStream(array $file_info): void if ($file_info['subtype']) { $this->_put('/Subtype /' . $file_info['subtype']); } + $this->_put('/Type /EmbeddedFile'); if (is_string($file_info['file']) && @is_file($file_info['file'])) { $fc = file_get_contents($file_info['file']); @@ -267,9 +271,11 @@ protected function putFileStream(array $file_info): void \fseek($stream, 0); $fc = stream_get_contents($stream); } + if (false === $fc) { $this->Error('Cannot open file: ' . $file_info['file']); } + if ($this->deterministicModeEnabled === true) { $md = @date('YmdHis', strtotime("2000-01-01 23:59:59")); } elseif (is_string($file_info['file'])) { @@ -277,9 +283,10 @@ protected function putFileStream(array $file_info): void } else { $md = @date('YmdHis'); } + $fc = gzcompress($fc); $this->_put('/Length ' . strlen($fc)); - $this->_put("/Params <>"); + $this->_put(sprintf('/Params <>', $md)); $this->_put('>>'); $this->_putstream($fc); $this->_put('endobj'); @@ -303,6 +310,7 @@ protected function putFileDictionary(): void foreach ($files as $info) { $s .= sprintf('%s %s 0 R ', $this->_textstring($info['name']), $info['file_index']); } + $this->_put(sprintf('/Names [%s]', $s)); $this->_put('>>'); $this->_put('endobj'); @@ -323,6 +331,7 @@ protected function putMetadataDescriptions(): void foreach ($this->metaDataDescriptions as $_ => $desc) { $s .= $desc . "\n"; } + $s .= '' . "\n"; $s .= '' . "\n"; $s .= ''; @@ -406,8 +415,10 @@ protected function _putcatalog(): void if ('' !== $files_ref_str) { $files_ref_str .= ' '; } + $files_ref_str .= sprintf('%s 0 R', $file['file_index']); } + $this->_put(sprintf('/AF [%s]', $files_ref_str)); } else { $this->_put(sprintf('/AF %s 0 R', $this->filesIndex)); diff --git a/src/ZugferdProfileResolver.php b/src/ZugferdProfileResolver.php index 69188de9..13b90ce5 100644 --- a/src/ZugferdProfileResolver.php +++ b/src/ZugferdProfileResolver.php @@ -46,7 +46,7 @@ public static function resolve(string $xmlContent): array if (libxml_get_last_error()) { throw new ZugferdUnknownXmlContentException(); } - } catch (Throwable $e) { + } catch (Throwable $throwable) { throw new ZugferdUnknownXmlContentException(); } finally { libxml_clear_errors(); @@ -61,6 +61,7 @@ public static function resolve(string $xmlContent): array if ($typeelement[0] == $profiledef["contextparameter"]) { return [$profile, $profiledef]; } + if (in_array($typeelement[0], $profiledef['alternativecontextparameters'])) { return [$profile, $profiledef]; } diff --git a/src/exception/ZugferdExceptionCodes.php b/src/exception/ZugferdExceptionCodes.php index 16df8b2b..8bc46bdb 100644 --- a/src/exception/ZugferdExceptionCodes.php +++ b/src/exception/ZugferdExceptionCodes.php @@ -21,16 +21,28 @@ class ZugferdExceptionCodes { public const CANNOTFINDPROFILESTRING = -1101; + public const UNKNOWNPROFILE = -1102; + public const MIMETYPENOTSUPPORTED = -1103; + public const UNKNOWNDATEFORMAT = -1104; + public const NOVALIDATTACHMENTFOUNDINPDF = -1105; + public const UNKNOWNPROFILEPARAMETER = -1106; + public const UNKNOWNSYNTAX = -1107; + public const UNKNOWNMIMETYPE = -1108; + public const UNSUPPORTEDMIMETYPE = -1109; + public const NOPDFATTACHMENTFOUND = -1110; + public const FILENOTFOUND = -2000; + public const FILENOTREADABLE = -2001; + public const INVALIDARGUMENT = -3000; } diff --git a/src/quick/ZugferdQuickDescriptor.php b/src/quick/ZugferdQuickDescriptor.php index 85fe49f3..d98404a0 100644 --- a/src/quick/ZugferdQuickDescriptor.php +++ b/src/quick/ZugferdQuickDescriptor.php @@ -34,14 +34,23 @@ class ZugferdQuickDescriptor extends ZugferdDocumentBuilder { private const VT_TAXCATEGORY = 0; + private const VT_TAXTYPE = 1; + private const VT_TAXPERCENT = 2; + private const VT_LINETOTALBASISAMOUNT = 3; + private const VT_ALLOWANCEAMOUNT = 4; + private const VT_CHARGEAMOUNT = 5; + private const VT_ALLOWANCECHARGEAMOUNT = 6; + private const VT_BASISAMOUNT = 7; + private const VT_CALCULATEDAMOUNT = 8; + private const VT_LOGSERVICECHARGE = 9; /** @@ -352,6 +361,7 @@ public function doSetBuyer(string $name, string $postcode, string $city, string if ($buyerReference != null) { $this->setDocumentBuyerReference($buyerReference); } + return $this; } diff --git a/tests/testcases/PdfBuilderEn16931Test.php b/tests/testcases/PdfBuilderEn16931Test.php index 74f0568a..8bea81d2 100644 --- a/tests/testcases/PdfBuilderEn16931Test.php +++ b/tests/testcases/PdfBuilderEn16931Test.php @@ -788,9 +788,11 @@ function ($which) use (&$whichArray) { if ($which === 'title') { return "DummyTitle"; } + if ($which === 'author') { return "DummyAuthor"; } + if ($which === 'subject') { return "DummySubject"; } @@ -854,9 +856,11 @@ function ($which) { if ($which === 'title') { return ""; } + if ($which === 'author') { return ""; } + if ($which === 'subject') { return ""; } diff --git a/tests/testcases/ProfileResolverTest.php b/tests/testcases/ProfileResolverTest.php index 30401001..ea4cc3ea 100644 --- a/tests/testcases/ProfileResolverTest.php +++ b/tests/testcases/ProfileResolverTest.php @@ -417,7 +417,7 @@ public function testResolveNotXml() try { libxml_clear_errors(); $xmldocument = new SimpleXMLElement($this->deliverStringWhichIsNotXml()); - } catch (Throwable $e) { + } catch (Throwable $throwable) { // Do nothing } finally { libxml_use_internal_errors($prevUseInternalErrors); diff --git a/tests/traits/HandlesXmlTests.php b/tests/traits/HandlesXmlTests.php index 7f404e66..d4c53237 100644 --- a/tests/traits/HandlesXmlTests.php +++ b/tests/traits/HandlesXmlTests.php @@ -51,6 +51,7 @@ protected function getXml(): \SimpleXMLElement if ($this->renderingOfXmlDisabled === false) { $this->latestXml = new \SimpleXMLElement((self::$document)->getContent()); } + return $this->latestXml; }