Skip to content

Use shipmonk/coding-standard #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2025
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^10.5",
"psr/log": "^3",
"shipmonk/coding-standard": "^0.1.3",
"shipmonk/composer-dependency-analyser": "^1.7",
"shipmonk/name-collision-detector": "^2.1.1",
"shipmonk/phpstan-rules": "^4.0",
"slevomat/coding-standard": "^8.15.0",
"symfony/cache": "^6 || ^7"
},
"autoload": {
Expand Down
396 changes: 1 addition & 395 deletions phpcs.xml.dist

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/EntityPreloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __construct(
* @param positive-int|null $batchSize
* @param non-negative-int|null $maxFetchJoinSameFieldCount
* @return list<E>
*
* @template S of E
*/
public function preload(
Expand Down Expand Up @@ -75,6 +76,7 @@ public function preload(
/**
* @param list<S> $entities
* @return class-string<S>|null
*
* @template S of E
*/
private function getCommonAncestor(array $entities): ?string
Expand Down Expand Up @@ -108,6 +110,7 @@ private function getCommonAncestor(array $entities): ?string
* @param positive-int $batchSize
* @param non-negative-int $maxFetchJoinSameFieldCount
* @return list<T>
*
* @template T of E
*/
private function loadProxies(
Expand Down Expand Up @@ -151,6 +154,7 @@ private function loadProxies(
* @param positive-int|null $batchSize
* @param non-negative-int $maxFetchJoinSameFieldCount
* @return list<T>
*
* @template S of E
* @template T of E
*/
Expand Down Expand Up @@ -239,6 +243,7 @@ private function preloadToMany(
* @param array<string, PersistentCollection<int, T>> $uninitializedCollections
* @param non-negative-int $maxFetchJoinSameFieldCount
* @return array<string, T>
*
* @template S of E
* @template T of E
*/
Expand Down Expand Up @@ -290,6 +295,7 @@ private function preloadOneToManyInner(
* @param array<string, PersistentCollection<int, T>> $uninitializedCollections
* @param non-negative-int $maxFetchJoinSameFieldCount
* @return array<string, T>
*
* @template S of E
* @template T of E
*/
Expand Down Expand Up @@ -360,6 +366,7 @@ private function preloadManyToManyInner(
* @param positive-int|null $batchSize
* @param non-negative-int $maxFetchJoinSameFieldCount
* @return list<T>
*
* @template S of E
* @template T of E
*/
Expand Down Expand Up @@ -400,6 +407,7 @@ private function preloadToOne(
* @param non-negative-int $maxFetchJoinSameFieldCount
* @param array<string, 'asc'|'desc'> $orderBy
* @return list<T>
*
* @template T of E
*/
private function loadEntitiesBy(
Expand Down Expand Up @@ -434,6 +442,7 @@ private function loadEntitiesBy(
/**
* @param ClassMetadata<S> $sourceClassMetadata
* @param array<string, array<string, int>> $alreadyPreloadedJoins
*
* @template S of E
*/
private function addFetchJoinsToPreventFetchDuringHydration(
Expand Down
8 changes: 6 additions & 2 deletions tests/EntityPreloadBlogOneHasManyDeepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testOneHasManyDeepWithWithManualPreloadUsingPartial(): void
->getQuery()
->getResult();

$subCategories = array_merge(...array_map(static fn(Category $category) => $category->getChildren()->toArray(), $rootCategories));
$subCategories = array_merge(...array_map(static fn (Category $category) => $category->getChildren()->toArray(), $rootCategories));
$this->getEntityManager()->createQueryBuilder()
->select('PARTIAL subCategory.{id}', 'subSubCategory')
->from(Category::class, 'subCategory')
Expand Down Expand Up @@ -134,7 +134,11 @@ public function testOneHasManyDeepWithPreload(): void
]);
}

private function createCategoryTree(int $depth, int $branchingFactor, ?Category $parent = null): void
private function createCategoryTree(
int $depth,
int $branchingFactor,
?Category $parent = null,
): void
{
for ($i = 0; $i < $branchingFactor; $i++) {
$category = new Category("Category $depth-$i", $parent);
Expand Down
12 changes: 6 additions & 6 deletions tests/EntityPreloadSyntheticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ private function givenEntityWithNoRelations(): EntityWithNoRelations
}

private function givenEntityWithManyToOneEntityWithNoRelations(
EntityWithNoRelations $entityWithNoRelations
EntityWithNoRelations $entityWithNoRelations,
): EntityWithManyToOneEntityWithNoRelations
{
$entityWithManyToOneEntityWithNoRelations = new EntityWithManyToOneEntityWithNoRelations($entityWithNoRelations);
Expand All @@ -920,7 +920,7 @@ private function givenChildEntityWithNoRelationsA(): ChildEntityWithNoRelationsA
}

private function givenEntityWithManyToOneAbstractEntityWithNoRelations(
AbstractEntityWithNoRelations $abstractEntityWithNoRelations
AbstractEntityWithNoRelations $abstractEntityWithNoRelations,
): EntityWithManyToOneAbstractEntityWithNoRelations
{
$entityWithManyToOneAbstractEntityWithNoRelations = new EntityWithManyToOneAbstractEntityWithNoRelations($abstractEntityWithNoRelations);
Expand All @@ -930,7 +930,7 @@ private function givenEntityWithManyToOneAbstractEntityWithNoRelations(
}

private function givenEntityWithManyToOneOfManyToOneAbstractEntities(
EntityWithManyToOneAbstractEntityWithNoRelations $entityWithManyToOneAbstractEntityWithNoRelations
EntityWithManyToOneAbstractEntityWithNoRelations $entityWithManyToOneAbstractEntityWithNoRelations,
): EntityWithManyToOneOfManyToOneAbstractEntities
{
$entityWithManyToOneOfManyToOneAbstractEntities = new EntityWithManyToOneOfManyToOneAbstractEntities($entityWithManyToOneAbstractEntityWithNoRelations);
Expand Down Expand Up @@ -969,7 +969,7 @@ private function thenExpectedQueriesArePerformed(array $expectedQueries): void
}

private function givenConcreteEntityWithOptionalManyToOneItselfRelation(
?ConcreteStiEntityWithOptionalManyToOneOfItselfRelation $parent
?ConcreteStiEntityWithOptionalManyToOneOfItselfRelation $parent,
): ConcreteStiEntityWithOptionalManyToOneOfItselfRelation
{
$entity = new ConcreteStiEntityWithOptionalManyToOneOfItselfRelation($parent);
Expand All @@ -980,7 +980,7 @@ private function givenConcreteEntityWithOptionalManyToOneItselfRelation(
}

private function givenWithManyToOneOfManyToOneItselfRelation(
ConcreteStiEntityWithOptionalManyToOneOfItselfRelation $currentEntityWithRelationToItself
ConcreteStiEntityWithOptionalManyToOneOfItselfRelation $currentEntityWithRelationToItself,
): EntityWithManyToOneOfManyToOneItselfStiRelation
{
$entityWithManyToOneOfManyToOneItselfRelation = new EntityWithManyToOneOfManyToOneItselfStiRelation($currentEntityWithRelationToItself);
Expand All @@ -991,7 +991,7 @@ private function givenWithManyToOneOfManyToOneItselfRelation(
}

private function givenWithManyToOneOfManyToOneOfManyToOneItselfRelation(
EntityWithManyToOneOfManyToOneItselfStiRelation $entityWithManyToOneOfManyToOneItselfRelation
EntityWithManyToOneOfManyToOneItselfStiRelation $entityWithManyToOneOfManyToOneItselfRelation,
): EntityWithManyToOneOfManyToOneOfManyToOneItselfRelation
{
$entityWithManyToOneOfManyToOneOfManyToOneItselfRelation = new EntityWithManyToOneOfManyToOneOfManyToOneItselfRelation($entityWithManyToOneOfManyToOneItselfRelation);
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/Blog/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class Article
#[OrderBy(['id' => 'DESC'])]
private Collection $comments;

public function __construct(string $title, string $content, ?Category $category = null)
public function __construct(
string $title,
string $content,
?Category $category = null,
)
{
$this->title = $title;
$this->content = $content;
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/Blog/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class Bot extends Contributor
#[Column]
private string $apiKeyHash;

public function __construct(string $name, string $apiKey, string $prompt)
public function __construct(
string $name,
string $apiKey,
string $prompt,
)
{
parent::__construct($name);
$this->activePrompt = new BotPromptVersion($prompt);
Expand Down
9 changes: 6 additions & 3 deletions tests/Fixtures/Blog/BotPromptVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class BotPromptVersion
#[OneToOne(mappedBy: 'prevVersion')]
private ?BotPromptVersion $nextVersion;

public function __construct(string $prompt, ?self $prevScript = null)
public function __construct(
string $prompt,
?self $prevScript = null,
)
{
$this->version = ($prevScript->version ?? 0) + 1;
$this->prompt = $prompt;
Expand All @@ -56,12 +59,12 @@ public function getPrompt(): string
return $this->prompt;
}

public function getPrevVersion(): ?BotPromptVersion
public function getPrevVersion(): ?self
{
return $this->prevVersion;
}

public function getNextVersion(): ?BotPromptVersion
public function getNextVersion(): ?self
{
return $this->nextVersion;
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Fixtures/Blog/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class Category
#[OneToMany(targetEntity: Article::class, mappedBy: 'category')]
private Collection $articles;

public function __construct(string $name, ?self $parent = null)
public function __construct(
string $name,
?self $parent = null,
)
{
$this->name = $name;
$this->parent = $parent;
Expand Down Expand Up @@ -83,7 +86,7 @@ public function getArticles(): ReadableCollection
/**
* @internal
*/
public function addChild(Category $category): void
public function addChild(self $category): void
{
if (!$this->children->contains($category)) {
$this->children->add($category);
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/Blog/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class Comment
#[Column]
private string $content;

public function __construct(Article $article, Contributor $author, string $content)
public function __construct(
Article $article,
Contributor $author,
string $content,
)
{
$this->article = $article;
$this->author = $author;
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/Blog/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class User extends Contributor
#[Column]
private string $passwordHash;

public function __construct(string $name, string $email, string $password)
public function __construct(
string $name,
string $email,
string $password,
)
{
parent::__construct($name);
$this->email = $email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class EntityWithManyToOneOfManyToOneItselfCtiRelation extends TestEntityWithId
private AbstractCtiEntityWithOptionalManyToOneItselfRelation $abstractEntityWithOptionalManyToOneItselfRelation;

public function __construct(
AbstractCtiEntityWithOptionalManyToOneItselfRelation $abstractEntityWithOptionalManyToOneItselfRelation
AbstractCtiEntityWithOptionalManyToOneItselfRelation $abstractEntityWithOptionalManyToOneItselfRelation,
)
{
$this->abstractEntityWithOptionalManyToOneItselfRelation = $abstractEntityWithOptionalManyToOneItselfRelation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EntityWithManyToOneOfManyToOneAbstractEntities extends TestEntityWithId
private EntityWithManyToOneAbstractEntityWithNoRelations $entityWithManyToOneAbstractEntityWithNoRelations;

public function __construct(
EntityWithManyToOneAbstractEntityWithNoRelations $entityWithManyToOneAbstractEntityWithNoRelations
EntityWithManyToOneAbstractEntityWithNoRelations $entityWithManyToOneAbstractEntityWithNoRelations,
)
{
$this->entityWithManyToOneAbstractEntityWithNoRelations = $entityWithManyToOneAbstractEntityWithNoRelations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EntityWithManyToOneOfManyToOneOfManyToOneItselfRelation extends TestEntity
private EntityWithManyToOneOfManyToOneItselfStiRelation $entityWithManyToOneOfManyToOneItselfRelation;

public function __construct(
EntityWithManyToOneOfManyToOneItselfStiRelation $entityWithManyToOneOfManyToOneItselfRelation
EntityWithManyToOneOfManyToOneItselfStiRelation $entityWithManyToOneOfManyToOneItselfRelation,
)
{
$this->entityWithManyToOneOfManyToOneItselfRelation = $entityWithManyToOneOfManyToOneItselfRelation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class EntityWithManyToOneOfManyToOneItselfStiRelation extends TestEntityWithId
private AbstractStiEntityWithOptionalManyToOneItselfRelation $abstractEntityWithOptionalManyToOneItselfRelation;

public function __construct(
AbstractStiEntityWithOptionalManyToOneItselfRelation $abstractEntityWithOptionalManyToOneItselfRelation
AbstractStiEntityWithOptionalManyToOneItselfRelation $abstractEntityWithOptionalManyToOneItselfRelation,
)
{
$this->abstractEntityWithOptionalManyToOneItselfRelation = $abstractEntityWithOptionalManyToOneItselfRelation;
Expand Down
6 changes: 5 additions & 1 deletion tests/Lib/QueryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class QueryLogger extends AbstractLogger
/**
* @param array<mixed> $context
*/
public function log(mixed $level, Stringable|string $message, array $context = []): void
public function log(
mixed $level,
Stringable|string $message,
array $context = [],
): void
{
if (isset($context['sql'])) {
$this->queries[] = $context['sql'];
Expand Down
17 changes: 14 additions & 3 deletions tests/Lib/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ protected function setUp(): void
}

/**
* @template T of Throwable
* @param class-string<T> $type
* @param callable(): mixed $cb
*
* @template T of Throwable
*
* @param-immediately-invoked-callable $cb
*/
protected static function assertException(string $type, ?string $message, callable $cb): void
protected static function assertException(
string $type,
?string $message,
callable $cb,
): void
{
try {
$cb();
Expand Down Expand Up @@ -145,6 +151,7 @@ protected function createDummyBlogData(
/**
* @param T $entity
* @return T|null
*
* @template T of object
*/
protected function refreshEntity(object $entity): ?object
Expand All @@ -163,6 +170,7 @@ protected function refreshEntity(object $entity): ?object
/**
* @param T $entity
* @return T
*
* @template T of object
*/
protected function refreshExistingEntity(object $entity): object
Expand Down Expand Up @@ -209,7 +217,10 @@ private function createQueryLogger(): QueryLogger
return new QueryLogger();
}

private function createEntityManager(LoggerInterface $logger, bool $inMemory = true): EntityManagerInterface
private function createEntityManager(
LoggerInterface $logger,
bool $inMemory = true,
): EntityManagerInterface
{
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/../Fixtures'], isDevMode: true, proxyDir: __DIR__ . '/../../cache/proxies');
$config->setNamingStrategy(new UnderscoreNamingStrategy());
Expand Down