Skip to content

Commit

Permalink
Merge pull request #9755 from greg0ire/mandatory-class-name-arg
Browse files Browse the repository at this point in the history
Require new argument to joinColumnName()
  • Loading branch information
greg0ire committed May 20, 2022
2 parents bb1fdcf + 5e536ed commit 9384ca8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
37 changes: 37 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Upgrade to 3.0

## BC BREAK: New argument to `NamingStrategy::joinColumnName()`

### Before

```php
<?php
class MyStrategy implements NamingStrategy
{
/**
* @param string $propertyName A property name.
*/
public function joinColumnName($propertyName): string
{
// …
}
}
```

### After

The `class-string` type for `$className` can be inherited from the signature of
the interface.

```php
<?php
class MyStrategy implements NamingStrategy
{
/**
* {@inheritdoc}
*/
public function joinColumnName(string $propertyName, string $className): string
{
// …
}
}
```

## BC BREAK: Remove StaticPHPDriver

Use `Doctrine\Persistence\Mapping\Driver\StaticPHPDriver` from
Expand Down
7 changes: 1 addition & 6 deletions lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ public function referenceColumnName(): string
return 'id';
}

/**
* {@inheritdoc}
*
* @param class-string $className
*/
public function joinColumnName(string $propertyName, ?string $className = null): string
public function joinColumnName(string $propertyName, string $className): string
{
return $propertyName . '_' . $this->referenceColumnName();
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Mapping/NamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public function referenceColumnName(): string;

/**
* Returns a join column name for a property.
*
* @param class-string $className
*/
public function joinColumnName(string $propertyName/*, string $className */): string;
public function joinColumnName(string $propertyName, string $className): string;

/**
* Returns a join table name.
Expand Down
7 changes: 1 addition & 6 deletions lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ public function referenceColumnName(): string
return $this->case === CASE_UPPER ? 'ID' : 'id';
}

/**
* {@inheritdoc}
*
* @param class-string $className
*/
public function joinColumnName(string $propertyName, ?string $className = null): string
public function joinColumnName(string $propertyName, string $className): string
{
return $this->underscore($propertyName) . '_' . $this->referenceColumnName();
}
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Method Doctrine\\\\ORM\\\\Mapping\\\\NamingStrategy\\:\\:joinColumnName\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 2
path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
Expand Down
4 changes: 0 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@
<RedundantFunctionCall occurrences="1">
<code>array_values</code>
</RedundantFunctionCall>
<TooManyArguments occurrences="2">
<code>joinColumnName</code>
<code>joinColumnName</code>
</TooManyArguments>
</file>
<file src="lib/Doctrine/ORM/Mapping/ColumnResult.php">
<MissingConstructor occurrences="1">
Expand Down

0 comments on commit 9384ca8

Please sign in to comment.