Skip to content

Commit

Permalink
Fix CS (#11782)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Jan 7, 2025
1 parent 327418a commit 0d2cb6a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/Mapping/ManyToManyOwningSideMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static function fromMappingArrayAndNamingStrategy(array $mappingArray, Na
if (empty($joinColumn['referencedColumnName'])) {
$mappingArray['joinTable']['joinColumns'][$key]['referencedColumnName'] = $namingStrategy->referenceColumnName();
}

if (empty($joinColumn['name'])) {
$mappingArray['joinTable']['joinColumns'][$key]['name'] = $namingStrategy->joinKeyColumnName(
$mappingArray['sourceEntity'],
Expand All @@ -78,6 +79,7 @@ public static function fromMappingArrayAndNamingStrategy(array $mappingArray, Na
if (empty($joinColumn['referencedColumnName'])) {
$mappingArray['joinTable']['inverseJoinColumns'][$key]['referencedColumnName'] = $namingStrategy->referenceColumnName();
}

if (empty($joinColumn['name'])) {
$mappingArray['joinTable']['inverseJoinColumns'][$key]['name'] = $namingStrategy->joinKeyColumnName(
$mappingArray['targetEntity'],
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/ToOneOwningSideMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public static function fromMappingArrayAndName(
if (empty($joinColumn['name'])) {
$mappingArray['joinColumns'][$index]['name'] = $namingStrategy->joinColumnName($mappingArray['fieldName'], $name);
}

if (empty($joinColumn['referencedColumnName'])) {
$mappingArray['joinColumns'][$index]['referencedColumnName'] = $namingStrategy->referenceColumnName();
}
Expand Down
20 changes: 11 additions & 9 deletions tests/Tests/ORM/Mapping/MappingDriverTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public function testEnumType(): void

public function testCustomNamingStrategyIsRespected(): void
{
$ns = new CustomPascalNamingStrategy();
$ns = new CustomPascalNamingStrategy();
$metadata = $this->createClassMetadata(BlogPostComment::class, $ns);

self::assertEquals('id', $metadata->fieldNames['Id']);
Expand Down Expand Up @@ -1565,17 +1565,22 @@ class GH10288EnumTypeBoss extends GH10288EnumTypePerson
#[Entity]
class BlogPost
{
#[Id, Column, GeneratedValue(strategy: 'NONE')]
#[Id]
#[Column]
#[GeneratedValue(strategy: 'NONE')]
public int $id;
}

#[Entity]
class BlogPostComment
{
#[Id, Column, GeneratedValue(strategy: 'AUTO')]
#[Id]
#[Column]
#[GeneratedValue(strategy: 'AUTO')]
public int $id;

#[ORM\ManyToOne, ORM\JoinColumn(nullable: false)]
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
public BlogPost $blogPost;

public static function loadMetadata(ClassMetadata $metadata): void
Expand All @@ -1595,12 +1600,9 @@ public static function loadMetadata(ClassMetadata $metadata): void
'targetEntity' => BlogPost::class,
'joinColumns' =>
[
0 =>
[
'nullable' => false,
],
0 => ['nullable' => false],
],
]
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
namespace Doctrine\Tests\ORM\Mapping\NamingStrategy;

use Doctrine\ORM\Mapping\NamingStrategy;
use LogicException;

use function sprintf;
use function str_contains;
use function strrpos;
use function strtolower;
use function substr;
use function ucfirst;

/**
* Fully customized naming strategy changing all namings to a PascalCase model. Included to test some behaviours
Expand All @@ -16,6 +24,7 @@ class CustomPascalNamingStrategy implements NamingStrategy
* Returns a table name for an entity class.
*
* @param string $className The fully-qualified class name
*
* @return string A table name
*/
public function classToTableName(string $className): string
Expand All @@ -30,14 +39,14 @@ public function classToTableName(string $className): string
/**
* Returns a column name for a property.
*
* @param string $propertyName A property name
* @param string $propertyName A property name
* @param string|null $className The fully-qualified class name
*
* @return string A column name
*/
public function propertyToColumnName(string $propertyName, ?string $className = null): string
public function propertyToColumnName(string $propertyName, string|null $className = null): string
{
if (null !== $className && strtolower($propertyName) == strtolower($this->classToTableName($className)) . 'id') {
if ($className !== null && strtolower($propertyName) === strtolower($this->classToTableName($className)) . 'id') {
return 'Id';
}

Expand All @@ -47,9 +56,9 @@ public function propertyToColumnName(string $propertyName, ?string $className =
/**
* Returns a column name for an embedded property.
*/
public function embeddedFieldToColumnName(string $propertyName, string $embeddedColumnName, ?string $className = null, $embeddedClassName = null): string
public function embeddedFieldToColumnName(string $propertyName, string $embeddedColumnName, string|null $className = null, $embeddedClassName = null): string
{
throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__));
throw new LogicException(sprintf('Method %s is not implemented', __METHOD__));
}

/**
Expand All @@ -75,13 +84,13 @@ public function joinColumnName(string $propertyName, string $className): string
/**
* Returns a join table name.
*
* @param string $sourceEntity The source entity
* @param string $targetEntity The target entity
* @param string $sourceEntity The source entity
* @param string $targetEntity The target entity
* @param string|null $propertyName A property name
*
* @return string A join table name
*/
public function joinTableName(string $sourceEntity, string $targetEntity, ?string $propertyName = null): string
public function joinTableName(string $sourceEntity, string $targetEntity, string|null $propertyName = null): string
{
return $this->classToTableName($sourceEntity) . $this->classToTableName($targetEntity);
}
Expand All @@ -94,7 +103,7 @@ public function joinTableName(string $sourceEntity, string $targetEntity, ?strin
*
* @return string A join column name
*/
public function joinKeyColumnName(string $entityName, ?string $referencedColumnName = null): string
public function joinKeyColumnName(string $entityName, string|null $referencedColumnName = null): string
{
return $this->classToTableName($entityName) . ($referencedColumnName ?: $this->referenceColumnName());
}
Expand Down

0 comments on commit 0d2cb6a

Please sign in to comment.