Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Sniffs/Structure/ServiceStructureSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ private function assertCompanionClassAllowed(
string $className,
string $normalizedPath,
): void {
if (str_ends_with($className, 'Helper') || str_ends_with($className, 'Factory')) {
return;
}

$directory = dirname($normalizedPath);
$serviceFiles = $this->findServiceClassesInDirectory($directory);

Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,16 @@
'errors' => [],
'warnings' => [],
],
// ServiceStructureSniff — Helper class in Service/ directory — valid per convention
[
'file' => __DIR__ . '/fixtures/src/Module/Example/Infrastructure/Service/Source/ParamsGetter/Helper/RutubeHelper.inc',
'errors' => [],
'warnings' => [],
],
// ServiceStructureSniff — Factory class in Service/ directory — valid per convention
[
'file' => __DIR__ . '/fixtures/src/Module/Example/Application/Service/SomeService/PaymentDtoFactory.inc',
'errors' => [],
'warnings' => [],
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

// Factory class inside Service/ directory — should pass per convention
namespace App\Module\Example\Application\Service\SomeService;

final readonly class PaymentDtoFactory
{
public function create(int $amount): object
{
return new \stdClass();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

// Helper class in Service/ directory — should pass per convention
namespace App\Module\Example\Infrastructure\Service\Source\ParamsGetter\Helper;

final class RutubeHelper
{
public static function getVideoId(string $uri): string
{
return $uri;
}
}
Loading