diff --git a/Api/Processor/Audit/ArrayProcessorInterface.php b/Api/Processor/Audit/ArrayProcessorInterface.php new file mode 100644 index 0000000..e9bd489 --- /dev/null +++ b/Api/Processor/Audit/ArrayProcessorInterface.php @@ -0,0 +1,12 @@ + */ -interface ProcessorInterface +interface AuditProcessorInterface { /** * @param $input */ - public function run($input); + public function run(): void; /** * @return string diff --git a/Processor/Results/ResultProcessorInterface.php b/Api/Processor/ResultProcessorInterface.php similarity index 83% rename from Processor/Results/ResultProcessorInterface.php rename to Api/Processor/ResultProcessorInterface.php index bc66459..2dcb362 100644 --- a/Processor/Results/ResultProcessorInterface.php +++ b/Api/Processor/ResultProcessorInterface.php @@ -1,6 +1,6 @@ array = $array; + } + + public function getArray(): array + { + return $this->array; + } +} \ No newline at end of file diff --git a/Processor/Files/AbstractProcessor.php b/Processor/Files/AbstractAuditProcessor.php similarity index 89% rename from Processor/Files/AbstractProcessor.php rename to Processor/Files/AbstractAuditProcessor.php index 7f38012..e5eee69 100644 --- a/Processor/Files/AbstractProcessor.php +++ b/Processor/Files/AbstractAuditProcessor.php @@ -2,9 +2,10 @@ namespace Crealoz\EasyAudit\Processor\Files; +use Crealoz\EasyAudit\Api\Processor\AuditProcessorInterface; use Crealoz\EasyAudit\Exception\Processor\GeneralAuditException; -abstract class AbstractProcessor implements ProcessorInterface +abstract class AbstractAuditProcessor implements AuditProcessorInterface { protected array $results = []; @@ -16,7 +17,7 @@ public function hasErrors(): bool return array_key_exists('hasErrors', $this->results) && $this->results['hasErrors']; } - abstract public function run($input); + abstract public function run(): void; public function prepopulateResults(): void { $this->erroneousFiles = []; diff --git a/Processor/Files/AbstractFileProcessor.php b/Processor/Files/AbstractFileProcessor.php new file mode 100644 index 0000000..8b34a7b --- /dev/null +++ b/Processor/Files/AbstractFileProcessor.php @@ -0,0 +1,21 @@ +file = $file; + } + + public function getFile(): string + { + return $this->file; + } +} \ No newline at end of file diff --git a/Processor/Files/AbstractXmlProcessor.php b/Processor/Files/AbstractXmlProcessor.php new file mode 100644 index 0000000..ae3e475 --- /dev/null +++ b/Processor/Files/AbstractXmlProcessor.php @@ -0,0 +1,14 @@ +getFile()); + } +} \ No newline at end of file diff --git a/Processor/Files/Code/BlockViewModelRatio.php b/Processor/Files/Code/BlockViewModelRatio.php index 1971ff5..e6e2309 100644 --- a/Processor/Files/Code/BlockViewModelRatio.php +++ b/Processor/Files/Code/BlockViewModelRatio.php @@ -2,10 +2,11 @@ namespace Crealoz\EasyAudit\Processor\Files\Code; -use Crealoz\EasyAudit\Processor\Files\AbstractProcessor; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\Audit\ArrayProcessorInterface; +use Crealoz\EasyAudit\Processor\Files\AbstractArrayProcessor; +use Crealoz\EasyAudit\Processor\Files\AbstractAuditProcessor; -class BlockViewModelRatio extends AbstractProcessor implements ProcessorInterface +class BlockViewModelRatio extends AbstractArrayProcessor implements ArrayProcessorInterface { public function getProcessorName(): string @@ -44,12 +45,9 @@ private function getBVMWarningEntry(): array ]; } - public function run($input) + public function run(): void { - if (!is_array($input)) { - throw new \InvalidArgumentException('Input must be an array'); - } - $files = $this->segregateFilesByModule($input); + $files = $this->segregateFilesByModule($this->getArray()); foreach ($files as $module => $moduleFiles) { $blockViewModelRatio = $this->getBlockViewModelRatio($moduleFiles); if ($blockViewModelRatio > 0.5) { diff --git a/Processor/Files/Code/HardWrittenSQL.php b/Processor/Files/Code/HardWrittenSQL.php index ba0089b..2bca428 100644 --- a/Processor/Files/Code/HardWrittenSQL.php +++ b/Processor/Files/Code/HardWrittenSQL.php @@ -2,13 +2,13 @@ namespace Crealoz\EasyAudit\Processor\Files\Code; -use Crealoz\EasyAudit\Processor\Files\AbstractProcessor; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\Audit\FileProcessorInterface; +use Crealoz\EasyAudit\Processor\Files\AbstractFileProcessor; use Crealoz\EasyAudit\Service\Audit; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\DriverInterface; -class HardWrittenSQL extends AbstractProcessor implements ProcessorInterface +class HardWrittenSQL extends AbstractFileProcessor implements FileProcessorInterface { public function getProcessorName(): string @@ -104,8 +104,9 @@ private function getHardWrittenSQLJoinEntry(): array /** * @throws FileSystemException */ - public function run($input) + public function run(): void { + $input = $this->getFile(); $code = $this->driver->fileGetContents($input); if (str_contains($code, 'SELECT')) { /** diff --git a/Processor/Files/Code/SpecificClassInjection.php b/Processor/Files/Code/SpecificClassInjection.php index 212a134..a9d486e 100644 --- a/Processor/Files/Code/SpecificClassInjection.php +++ b/Processor/Files/Code/SpecificClassInjection.php @@ -2,9 +2,11 @@ namespace Crealoz\EasyAudit\Processor\Files\Code; +use Crealoz\EasyAudit\Api\Processor\Audit\FileProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\AuditProcessorInterface; use Crealoz\EasyAudit\Exception\Processor\Getters\NotAClassException; -use Crealoz\EasyAudit\Processor\Files\AbstractProcessor; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Processor\Files\AbstractAuditProcessor; +use Crealoz\EasyAudit\Processor\Files\AbstractFileProcessor; use Crealoz\EasyAudit\Service\Audit; use Crealoz\EasyAudit\Service\Classes\ArgumentTypeChecker; use Crealoz\EasyAudit\Service\Classes\ConstructorService; @@ -16,7 +18,7 @@ * A class must not be injected in controller as a specific class. In all the cases, a factory or an interface should be used. * @author Christophe Ferreboeuf */ -class SpecificClassInjection extends AbstractProcessor implements ProcessorInterface +class SpecificClassInjection extends AbstractFileProcessor implements FileProcessorInterface { private array $ignoredClass = [ 'Magento\Framework\Escaper', @@ -118,11 +120,11 @@ public function getAuditSection(): string { return __('PHP'); } - public function run($input) + public function run(): void { // First we get class name from the input that represents the file's path try { - $className = $this->classNameGetter->getClassFullNameFromFile($input); + $className = $this->classNameGetter->getClassFullNameFromFile($this->getFile()); } catch (NotAClassException|FileSystemException $e) { return; } @@ -141,7 +143,7 @@ public function run($input) } $fileErrorLevel = 0; foreach ($arguments as $argument) { - if ($argument === null || !is_array($argument) || count($argument) < 2 || !is_string($argument[1])) { + if (!is_array($argument) || count($argument) < 2 || !is_string($argument[1])) { continue; } $argumentName = $argument[1]; diff --git a/Processor/Files/Code/UseOfRegistry.php b/Processor/Files/Code/UseOfRegistry.php index b8216d4..2f59808 100644 --- a/Processor/Files/Code/UseOfRegistry.php +++ b/Processor/Files/Code/UseOfRegistry.php @@ -2,20 +2,21 @@ namespace Crealoz\EasyAudit\Processor\Files\Code; +use Crealoz\EasyAudit\Api\Processor\Audit\FileProcessorInterface; use Crealoz\EasyAudit\Exception\Processor\Getters\NotAClassException; -use Crealoz\EasyAudit\Processor\Files\AbstractProcessor; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Processor\Files\AbstractFileProcessor; use Crealoz\EasyAudit\Service\Classes\ConstructorService; use Crealoz\EasyAudit\Service\FileSystem\ClassNameGetter; use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\ObjectManager\DefinitionInterface; -class UseOfRegistry extends AbstractProcessor implements ProcessorInterface +class UseOfRegistry extends AbstractFileProcessor implements FileProcessorInterface { public function __construct( private readonly ClassNameGetter $classNameGetter, - private readonly \Magento\Framework\ObjectManager\DefinitionInterface $definitions, + private readonly DefinitionInterface $definitions, private readonly ConstructorService $constructorService ) { @@ -55,10 +56,10 @@ public function getAuditSection(): string return __('PHP'); } - public function run($input): void + public function run(): void { try { - $className = $this->classNameGetter->getClassFullNameFromFile($input); + $className = $this->classNameGetter->getClassFullNameFromFile($this->getFile()); } catch (NotAClassException|FileSystemException $e) { return; } diff --git a/Processor/Files/Di/Plugins.php b/Processor/Files/Di/Plugins.php index 577e44d..51e0c03 100644 --- a/Processor/Files/Di/Plugins.php +++ b/Processor/Files/Di/Plugins.php @@ -2,22 +2,22 @@ namespace Crealoz\EasyAudit\Processor\Files\Di; +use Crealoz\EasyAudit\Api\Processor\Audit\FileProcessorInterface; use Crealoz\EasyAudit\Exception\Processor\Plugins\AroundToAfterPluginException; use Crealoz\EasyAudit\Exception\Processor\Plugins\AroundToBeforePluginException; use Crealoz\EasyAudit\Exception\Processor\Plugins\ConfigProviderPluginException; use Crealoz\EasyAudit\Exception\Processor\Plugins\MagentoFrameworkPluginExtension; use Crealoz\EasyAudit\Exception\Processor\Plugins\SameModulePluginException; -use Crealoz\EasyAudit\Processor\Files\AbstractProcessor; +use Crealoz\EasyAudit\Processor\Files\AbstractXmlProcessor; use Crealoz\EasyAudit\Processor\Files\Di\Plugins\AroundToAfter; use Crealoz\EasyAudit\Processor\Files\Di\Plugins\AroundToBefore; use Crealoz\EasyAudit\Processor\Files\Di\Plugins\CheckConfigProvider; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; use Crealoz\EasyAudit\Service\Audit; use Magento\Framework\App\Utility\Files; use Magento\Framework\Exception\FileSystemException; use Psr\Log\LoggerInterface; -class Plugins extends AbstractProcessor implements ProcessorInterface +class Plugins extends AbstractXmlProcessor implements FileProcessorInterface { public function getProcessorName(): string @@ -123,31 +123,22 @@ private function getAroundToAfterPluginEntry(): array ]; } - public function run($input) + public function run(): void { - if (!($input instanceof \SimpleXMLElement)) { - throw new \InvalidArgumentException("Input must be an instance of SimpleXMLElement"); - } - - $typeNodes = $input->xpath('//type[plugin]'); - try { - foreach ($typeNodes as $typeNode) { - $pluginNodes = $typeNode->xpath('plugin'); - $pluggedClassName = (string)$typeNode['name']; + $typeNodes = $this->getContent()->xpath('//type[plugin]'); + foreach ($typeNodes as $typeNode) { + $pluginNodes = $typeNode->xpath('plugin'); + $pluggedClassName = (string)$typeNode['name']; - foreach ($pluginNodes as $pluginNode) { - $pluggingClassName = (string)$pluginNode['type']; - $pluginDisabled = (string)$pluginNode['disabled'] ?? 'false'; - if ($pluginDisabled === 'true') { - continue; - } - $this->processPlugin($pluggingClassName, $pluggedClassName); + foreach ($pluginNodes as $pluginNode) { + $pluggingClassName = (string)$pluginNode['type']; + $pluginDisabled = (string)$pluginNode['disabled'] ?? 'false'; + if ($pluginDisabled === 'true') { + continue; } + $this->processPlugin($pluggingClassName, $pluggedClassName); } - } catch (FileSystemException $e) { - $this->results['warnings']['insufficientPermissions']['files'][] = $e->getMessage(); - $this->addErroneousFile($input, Audit::PRIORITY_HIGH); } } diff --git a/Processor/Files/Logic/Modules/GetModuleConfig.php b/Processor/Files/Logic/Modules/GetModuleConfig.php index eb9daa8..45e292f 100644 --- a/Processor/Files/Logic/Modules/GetModuleConfig.php +++ b/Processor/Files/Logic/Modules/GetModuleConfig.php @@ -2,6 +2,7 @@ namespace Crealoz\EasyAudit\Processor\Files\Logic\Modules; +use Crealoz\EasyAudit\Service\FileSystem\ModulePaths; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\DriverInterface; use Magento\Framework\Module\FullModuleList; @@ -18,7 +19,8 @@ class GetModuleConfig public function __construct( protected readonly DriverInterface $driver, private readonly FullModuleList $fullModuleList, - private readonly ModuleList $moduleList + private readonly ModuleList $moduleList, + private readonly ModulePaths $modulePath ) { } @@ -55,6 +57,15 @@ public function getModuleName(string $input): string return (string)$xml->module['name']; } + /** + * @throws FileSystemException + */ + public function getModuleNameByAnyFile(string $filePath, bool $isVendor = false): string + { + $input = $this->modulePath->getDeclarationXml($filePath, $isVendor); + return $this->getModuleName($input); + } + /** * Returns all modules * diff --git a/Processor/Files/Logic/UnusedModules.php b/Processor/Files/Logic/UnusedModules.php index 1a879d1..7f0adfa 100644 --- a/Processor/Files/Logic/UnusedModules.php +++ b/Processor/Files/Logic/UnusedModules.php @@ -2,12 +2,12 @@ namespace Crealoz\EasyAudit\Processor\Files\Logic; -use Crealoz\EasyAudit\Processor\Files\AbstractProcessor; +use Crealoz\EasyAudit\Api\Processor\Audit\ArrayProcessorInterface; +use Crealoz\EasyAudit\Processor\Files\AbstractArrayProcessor; use Crealoz\EasyAudit\Processor\Files\Logic\Modules\GetModuleConfig; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; use Magento\Framework\Exception\FileSystemException; -class UnusedModules extends AbstractProcessor implements ProcessorInterface +class UnusedModules extends AbstractArrayProcessor implements ArrayProcessorInterface { public function getAuditSection(): string { @@ -53,9 +53,9 @@ private function getUnusedModulesEntry(): array /** * @throws FileSystemException */ - public function run($input) + public function run(): void { - $unusedModules = $this->getModuleConfig->process($input); + $unusedModules = $this->getModuleConfig->process($this->getArray()); if (!empty($unusedModules)) { foreach ($unusedModules as $module) { $this->results['hasErrors'] = true; diff --git a/Processor/Files/View/Cacheable.php b/Processor/Files/View/Cacheable.php index 44f21b9..eb5fc50 100644 --- a/Processor/Files/View/Cacheable.php +++ b/Processor/Files/View/Cacheable.php @@ -2,10 +2,10 @@ namespace Crealoz\EasyAudit\Processor\Files\View; -use Crealoz\EasyAudit\Processor\Files\AbstractProcessor; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\Audit\FileProcessorInterface; +use Crealoz\EasyAudit\Processor\Files\AbstractXmlProcessor; -class Cacheable extends AbstractProcessor implements ProcessorInterface +class Cacheable extends AbstractXmlProcessor implements FileProcessorInterface { protected array $allowedAreas = ['sales', 'customer', 'gift', 'message']; @@ -43,13 +43,9 @@ private function getUseCacheableEntry(): array ]; } - public function run($input) + public function run(): void { - if (!$input instanceof \SimpleXMLElement) { - throw new \InvalidArgumentException('Input is not an instance of SimpleXMLElement'); - } - - $blocksNotCached = $input->xpath('//block[@cacheable="false"]'); + $blocksNotCached = $this->getXml()->xpath('//block[@cacheable="false"]'); if (count($blocksNotCached) > 0) { $this->results['hasErrors'] = true; foreach ($blocksNotCached as $block) { diff --git a/Processor/Results/ErroneousFiles.php b/Processor/Results/ErroneousFiles.php index 89513a0..5cd4249 100644 --- a/Processor/Results/ErroneousFiles.php +++ b/Processor/Results/ErroneousFiles.php @@ -2,7 +2,7 @@ namespace Crealoz\EasyAudit\Processor\Results; -class ErroneousFiles implements \Crealoz\EasyAudit\Processor\Results\ResultProcessorInterface +class ErroneousFiles implements \Crealoz\EasyAudit\Api\Processor\ResultProcessorInterface { /** * Checks results for erroneous files entries where score is superior to 5 then gets the ones where score is diff --git a/Processor/Type/AbstractType.php b/Processor/Type/AbstractType.php index eba3e03..17bbc95 100644 --- a/Processor/Type/AbstractType.php +++ b/Processor/Type/AbstractType.php @@ -50,7 +50,7 @@ public function process(array $subTypes, string $type, OutputInterface $output = if ($output) { $output->writeln("\r\nProcessing $subType files..."); /** if we are in command line, we display a bar */ - $progressBar = new ProgressBar($output, count($files)); + $progressBar = new ProgressBar($output, $this->getProgressBarCount($processors, $files)); $progressBar->start(); } $errors = $this->doProcess($processors, $files, $progressBar); @@ -66,6 +66,8 @@ public function process(array $subTypes, string $type, OutputInterface $output = return $this->results; } + abstract protected function getProgressBarCount(array $processors, array $files): int; + /** * Initializes the results array to avoid malformed results. * diff --git a/Processor/Type/Logic.php b/Processor/Type/Logic.php index 4bee083..b964020 100644 --- a/Processor/Type/Logic.php +++ b/Processor/Type/Logic.php @@ -2,7 +2,8 @@ namespace Crealoz\EasyAudit\Processor\Type; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\Audit\ArrayProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\AuditProcessorInterface; use Symfony\Component\Console\Helper\ProgressBar; class Logic extends AbstractType implements TypeInterface @@ -16,14 +17,22 @@ protected function doProcess(array $processors, array $files, ProgressBar $progr $hasErrors = false; foreach ($processors as $processor) { $progressBar?->advance(); - if (!$processor instanceof ProcessorInterface) { + if (!$processor instanceof AuditProcessorInterface) { throw new \InvalidArgumentException('Processor must implement ProcessorInterface'); } - $processor->run($files); + if ($processor instanceof ArrayProcessorInterface) { + $processor->setArray($files); + } + $processor->run(); if ($hasErrors === false && $processor->hasErrors()) { $hasErrors = true; } } return $hasErrors; } + + protected function getProgressBarCount(array $processors, array $files): int + { + return count($processors); + } } \ No newline at end of file diff --git a/Processor/Type/PHPCode.php b/Processor/Type/PHPCode.php index 4b0e411..7e4a16d 100644 --- a/Processor/Type/PHPCode.php +++ b/Processor/Type/PHPCode.php @@ -2,7 +2,8 @@ namespace Crealoz\EasyAudit\Processor\Type; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\Audit\FileProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\AuditProcessorInterface; use Symfony\Component\Console\Helper\ProgressBar; class PHPCode extends AbstractType implements TypeInterface @@ -14,12 +15,15 @@ protected function doProcess(array $processors, array $files, ProgressBar $progr { $hasErrors = false; foreach ($files as $codeFile) { - $progressBar?->advance(); foreach ($processors as $processor) { - if (!$processor instanceof ProcessorInterface) { + if (!$processor instanceof AuditProcessorInterface) { throw new \InvalidArgumentException('Processor must implement ProcessorInterface'); } - $processor->run($codeFile); + if ($processor instanceof FileProcessorInterface) { + $processor->setFile($codeFile); + } + $processor->run(); + $progressBar?->advance(); if ($hasErrors === false && $processor->hasErrors()) { $hasErrors = true; } @@ -27,4 +31,9 @@ protected function doProcess(array $processors, array $files, ProgressBar $progr } return $hasErrors; } + + protected function getProgressBarCount(array $processors, array $files): int + { + return count($processors) * count($files); + } } \ No newline at end of file diff --git a/Processor/Type/Xml.php b/Processor/Type/Xml.php index 5c25e52..1b97e39 100644 --- a/Processor/Type/Xml.php +++ b/Processor/Type/Xml.php @@ -2,7 +2,8 @@ namespace Crealoz\EasyAudit\Processor\Type; -use Crealoz\EasyAudit\Processor\Files\ProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\Audit\FileProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\AuditProcessorInterface; use Symfony\Component\Console\Helper\ProgressBar; class Xml extends AbstractType implements TypeInterface @@ -15,17 +16,15 @@ protected function doProcess(array $processors, array $files, ProgressBar $progr { $hasErrors = false; foreach ($files as $xmlFile) { - $xml = simplexml_load_file($xmlFile); - $progressBar?->advance(); - if ($xml === false) { - $this->logger->error("Failed to load XML file: $xmlFile"); - continue; - } foreach ($processors as $processor) { - if (!$processor instanceof ProcessorInterface) { + if (!$processor instanceof AuditProcessorInterface) { throw new \InvalidArgumentException('Processor must implement ProcessorInterface'); } - $processor->run($xml); + if ($processor instanceof FileProcessorInterface) { + $processor->setFile($xmlFile); + } + $processor->run(); + $progressBar?->advance(); if ($hasErrors === false && $processor->hasErrors()) { $hasErrors = true; } @@ -33,4 +32,9 @@ protected function doProcess(array $processors, array $files, ProgressBar $progr } return $hasErrors; } + + protected function getProgressBarCount(array $processors, array $files): int + { + return count($processors) * count($files); + } } \ No newline at end of file diff --git a/Service/Audit.php b/Service/Audit.php index a689223..3e432b8 100644 --- a/Service/Audit.php +++ b/Service/Audit.php @@ -2,7 +2,7 @@ namespace Crealoz\EasyAudit\Service; -use Crealoz\EasyAudit\Processor\Results\ResultProcessorInterface; +use Crealoz\EasyAudit\Api\Processor\ResultProcessorInterface; use Crealoz\EasyAudit\Processor\Type\TypeFactory; use Magento\Framework\Exception\FileSystemException; use Psr\Log\LoggerInterface; diff --git a/Service/FileSystem/ClassNameGetter.php b/Service/FileSystem/ClassNameGetter.php index 2d769b3..b2a3f1a 100644 --- a/Service/FileSystem/ClassNameGetter.php +++ b/Service/FileSystem/ClassNameGetter.php @@ -15,7 +15,7 @@ public function __construct( protected readonly DriverInterface $driver, protected readonly File $io, private readonly GetModuleConfig $getModuleConfig, - private readonly ModuleXmlPath $moduleXmlPath + private readonly ModulePaths $modulePaths ) { } @@ -68,7 +68,7 @@ public function getClassFullNameFromFile($filePathName): string private function getNamespaceForVendorModule(string $filePath): string { $parts = explode('/', $filePath); - $moduleXmlPath = $this->moduleXmlPath->getDeclarationXml($filePath, true); + $moduleXmlPath = $this->modulePaths->getDeclarationXml($filePath, true); $moduleName = $this->getModuleConfig->getModuleName($moduleXmlPath); $namespaceParts = explode('_', $moduleName); $namespace = $namespaceParts[0] . DIRECTORY_SEPARATOR . $namespaceParts[1]; diff --git a/Service/FileSystem/ModuleXmlPath.php b/Service/FileSystem/ModulePaths.php similarity index 75% rename from Service/FileSystem/ModuleXmlPath.php rename to Service/FileSystem/ModulePaths.php index 90e6fb2..a387bb4 100644 --- a/Service/FileSystem/ModuleXmlPath.php +++ b/Service/FileSystem/ModulePaths.php @@ -4,7 +4,7 @@ use Magento\Framework\Filesystem; -class ModuleXmlPath +class ModulePaths { public function __construct( private readonly Filesystem $filesystem, @@ -12,7 +12,7 @@ public function __construct( { } - public function getDeclarationXml(string $filePath, bool $isVendor): string + public function getDeclarationXml(string $filePath, bool $isVendor = false): string { $parts = explode('/', $filePath); $moduleXmlPath = $parts[0] . DIRECTORY_SEPARATOR . $parts[1] . DIRECTORY_SEPARATOR . $parts[2] . DIRECTORY_SEPARATOR . $parts[3] . DIRECTORY_SEPARATOR . 'etc/module.xml'; @@ -22,13 +22,9 @@ public function getDeclarationXml(string $filePath, bool $isVendor): string return $moduleXmlPath; } - public function getDiXml(string $filePath, bool $isVendor): array + public function getDiXml(string $filePath, bool $isVendor = false): array { - $parts = explode('/', $filePath); - $baseDir = $parts[0] . DIRECTORY_SEPARATOR . $parts[1] . DIRECTORY_SEPARATOR . $parts[2] . DIRECTORY_SEPARATOR . $parts[3]; - if ($isVendor) { - $baseDir = $parts[0] . DIRECTORY_SEPARATOR . $parts[1] . DIRECTORY_SEPARATOR . $parts[2]; - } + $baseDir = $this->getModuleBaseDir($filePath, $isVendor); $diXmlPath = []; if ($this->filesystem->getDirectoryReadByPath($baseDir . DIRECTORY_SEPARATOR . 'etc')->isExist('di.xml')) { $diXmlPath['general'] = $baseDir . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'di.xml'; @@ -41,4 +37,24 @@ public function getDiXml(string $filePath, bool $isVendor): array } return $diXmlPath; } + + /** + * @param string $filePath + * @param bool $isVendor + * @return string + */ + public function getFrontendPath(string $filePath, bool $isVendor = false): string + { + return $this->getModuleBaseDir($filePath, $isVendor) . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'frontend'; + } + + public function getModuleBaseDir(string $filePath, bool $isVendor = false): string + { + $parts = explode('/', $filePath); + $baseDir = $parts[0] . DIRECTORY_SEPARATOR . $parts[1] . DIRECTORY_SEPARATOR . $parts[2] . DIRECTORY_SEPARATOR . $parts[3]; + if ($isVendor) { + $baseDir = $parts[0] . DIRECTORY_SEPARATOR . $parts[1] . DIRECTORY_SEPARATOR . $parts[2]; + } + return $baseDir; + } } \ No newline at end of file diff --git a/Service/PDFWriter/SizeCalculation.php b/Service/PDFWriter/SizeCalculation.php index e30b31c..2d9292a 100644 --- a/Service/PDFWriter/SizeCalculation.php +++ b/Service/PDFWriter/SizeCalculation.php @@ -42,6 +42,11 @@ public function calculateSectionIntroSize($subsection): int private function calculateNumberOfLines($text, $columnCount = 1): int { + if (!is_string($text)) { + debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + dd($text); + + } return ceil(strlen($text) / (130 / $columnCount)); } diff --git a/etc/di.xml b/etc/di.xml index 6b5b923..dcd825d 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -151,6 +151,7 @@ Magento\Framework\Filesystem\Driver\File\Proxy + Crealoz\EasyAudit\Service\FileSystem\ModulePath\Proxy