Skip to content

Commit

Permalink
Merge pull request #47 from crealoz/dev
Browse files Browse the repository at this point in the history
consolidate results array
  • Loading branch information
ChristopheFerreboeuf authored Jan 30, 2025
2 parents 50ee282 + 20af818 commit 2f42e0e
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 397 deletions.
8 changes: 6 additions & 2 deletions Model/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ public function getByRequestId($requestId)
return $collection->getItems();
}

/**
* @inheritdoc
*/
public function hasFiles($requestId): bool
{
$searchCriteria = $this->searchCriteriaBuilder->addFilter('request_id', $requestId)->create();
$collection = $this->getList($searchCriteria);
return $collection->getTotalCount() > 0;
$collection = $this->collectionFactory->create();
$this->collectionProcessor->process($searchCriteria, $collection);
return $collection->getSize() > 0;
}
}
12 changes: 12 additions & 0 deletions Processor/Files/AbstractAuditProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ abstract class AbstractAuditProcessor implements AuditProcessorInterface
{
public const ORDER = 0;

const TAG = 'abstract';

protected array $results = [];

protected array $erroneousFiles = [];
Expand All @@ -20,6 +22,11 @@ public function __construct(
{
}

public function getProcessorName(): string
{
return static::TAG;
}

public function hasErrors(): bool
{
return array_key_exists('hasErrors', $this->results) && $this->results['hasErrors'];
Expand Down Expand Up @@ -77,4 +84,9 @@ public function getOrder(): int
{
return static::ORDER;
}

public function getProcessorTag(): string
{
return static::TAG;
}
}
7 changes: 2 additions & 5 deletions Processor/Files/Code/BlockViewModelRatio.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class BlockViewModelRatio extends AbstractArrayProcessor implements ArrayProcess
{
public const ORDER = 40;

public const TAG = 'BlockVsViewModelRatio';

public function getProcessorName(): string
{
return __('Block vs ViewModel Ratio');
Expand Down Expand Up @@ -97,9 +99,4 @@ private function isFileInBlockFolder(string $file): bool
$pathParts = explode(DIRECTORY_SEPARATOR, $file);
return $pathParts[4] === 'Block';
}

public function getProcessorTag(): string
{
return __('BlockVsViewModelRatio');
}
}
7 changes: 2 additions & 5 deletions Processor/Files/Code/HardWrittenSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class HardWrittenSQL extends AbstractFileProcessor implements FileProcessorInter
{
public const ORDER = 30;

public const TAG = 'hardWrittenSQL';

public function getProcessorName(): string
{
return __('Hard Written SQL');
Expand Down Expand Up @@ -168,9 +170,4 @@ public function run(): void
}
}
}

public function getProcessorTag(): string
{
return 'hardWrittenSQL';
}
}
7 changes: 2 additions & 5 deletions Processor/Files/Code/SpecificClassInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class SpecificClassInjection extends AbstractFileProcessor implements FileProces
{
public const ORDER = 20;

public const TAG = 'specificClassInjection';

private array $ignoredClass = [
'Magento\Framework\Escaper',
'Magento\Framework\Data\Collection\AbstractDb',
Expand Down Expand Up @@ -220,9 +222,4 @@ private function isClassRepository($argumentName): bool
{
return str_contains((string) $argumentName, 'Repository');
}

public function getProcessorTag(): string
{
return 'specificClassInjection';
}
}
7 changes: 2 additions & 5 deletions Processor/Files/Code/UseOfRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class UseOfRegistry extends AbstractFileProcessor implements FileProcessorInterf
{
public const ORDER = 10;

public const TAG = 'useOfRegistry';

public function __construct(
AuditStorage $auditStorage,
private readonly ClassNameGetter $classNameGetter,
Expand Down Expand Up @@ -96,9 +98,4 @@ public function run(): void
}

}

public function getProcessorTag(): string
{
return 'useOfRegistry';
}
}
7 changes: 2 additions & 5 deletions Processor/Files/Di/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Plugins extends AbstractXmlProcessor implements FileProcessorInterface
{
public const ORDER = 10;

public const TAG = 'plugins';

public function __construct(
AuditStorage $auditStorage,
private readonly AroundToAfter $aroundToAfter,
Expand Down Expand Up @@ -281,9 +283,4 @@ private function isCheckoutConfigProviderPlugin(string $pluggedInClass, string $
$this->logger->error($e->getMessage());
}
}

public function getProcessorTag(): string
{
return 'plugins';
}
}
7 changes: 2 additions & 5 deletions Processor/Files/Logic/UnusedModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class UnusedModules extends AbstractArrayProcessor implements ArrayProcessorInte
{
public const ORDER = 10;

public const TAG = 'unusedModules';

public function getAuditSection(): string
{
return __('Logic');
Expand Down Expand Up @@ -68,9 +70,4 @@ public function run(): void
}
}
}

public function getProcessorTag(): string
{
return 'unusedModules';
}
}
7 changes: 2 additions & 5 deletions Processor/Files/View/Cacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Cacheable extends AbstractXmlProcessor implements FileProcessorInterface
{
public const ORDER = 10;

public const TAG = 'cacheable';

protected array $allowedAreas = ['sales', 'customer', 'gift', 'message'];

public function getProcessorName(): string
Expand Down Expand Up @@ -61,9 +63,4 @@ public function run(): void
}
}
}

public function getProcessorTag(): string
{
return 'cacheable';
}
}
1 change: 1 addition & 0 deletions Processor/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ protected function manageResults(array $processors) : void
/** @var AuditProcessorInterface $processor */
foreach ($processors as $processor) {
$results = $processor->getResults();
$results['processorTag'] = $processor->getProcessorTag();
$results['title'] = $processor->getProcessorName();
$this->results[$processor->getAuditSection()][$processor->getOrder()] = $results;
foreach ($processor->getErroneousFiles() as $file => $score) {
Expand Down
2 changes: 1 addition & 1 deletion Test/Integration/Model/FileRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testHasFiles()
$this->searchCriteriaBuilder->method('addFilter')->with('request_id', 1)->willReturnSelf();
$this->searchCriteriaBuilder->method('create')->willReturn($searchCriteria);
$this->searchResultFactory->method('create')->willReturn($searchResults);
$collection->method('getItems')->willReturn(['file1', 'file2']);
$collection->method('getSize')->willReturn(2);
$this->collectionFactory->method('create')->willReturn($collection);

$this->assertTrue($this->fileRepository->hasFiles(1));
Expand Down
Loading

0 comments on commit 2f42e0e

Please sign in to comment.