Skip to content

Commit

Permalink
PHP 8.4: fix deprecation notice
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Dec 11, 2024
1 parent bbb64a8 commit 0bc844f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function objectFilter(string &$script, AbstractOMBuilder $builder): void
$relationName = $this->getRelationName($builder);
$aggregateName = $this->getParameter('aggregate_name');
$relatedClass = $builder->getClassNameFromBuilder($builder->getNewStubObjectBuilder($this->getForeignTable()));
$search = " public function set{$relationName}({$relatedClass} \$v = null)
$search = " public function set{$relationName}(?{$relatedClass} \$v = null)
{";
$replace = $search . "
// aggregate_column_relation behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function queryMethods(QueryBuilder $builder): string
*
* @return \$this The current object, for fluid interface
*/
public function filterBy(string \$column, \$value, string \$comparison = null)
public function filterBy(string \$column, \$value, ?string \$comparison = null)
{
if (isset(\$this->delegatedFields[\$column])) {
\$methodUse = \"use{\$this->delegatedFields[\$column]}Query\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ protected function addSetParent(string &$script): void
* @param $objectClassName \$parent
* @return \$this The current object, for fluid interface
*/
public function setParent($objectClassName \$parent = null)
public function setParent(?$objectClassName \$parent = null)
{
\$this->aNestedSetParent = \$parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ protected function addFindRoot(string &$script): void
*
* @return {$this->objectClassName} The tree root object
*/
public function findRoot(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
public function findRoot(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
{
return \$this
->addUsingAlias({$this->objectClassName}::LEFT_COL, 1, Criteria::EQUAL)";
Expand Down Expand Up @@ -524,7 +524,7 @@ protected function addFindTree(string &$script): void
*
* @return {$this->objectClassName}[]|ObjectCollection|mixed the list of results, formatted by the current formatter
*/
public function findTree(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
public function findTree(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
{
return \$this";
if ($useScope) {
Expand Down Expand Up @@ -593,7 +593,7 @@ protected function addRetrieveRoot(string &$script): void
* @param ConnectionInterface \$con Connection to use.
* @return {$this->objectClassName} Propel object for root node
*/
static public function retrieveRoot(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
static public function retrieveRoot(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
{
\$c = new Criteria($tableMapClassName::DATABASE_NAME);
\$c->add($objectClassName::LEFT_COL, 1, Criteria::EQUAL);";
Expand Down Expand Up @@ -633,7 +633,7 @@ protected function addRetrieveTree(string &$script): void
* @param ConnectionInterface \$con Connection to use.
* @return {$this->objectClassName}[]|ObjectCollection|mixed the list of results, formatted by the current formatter
*/
static public function retrieveTree(" . ($useScope ? '$scope = null, ' : '') . "Criteria \$criteria = null, ?ConnectionInterface \$con = null)
static public function retrieveTree(" . ($useScope ? '$scope = null, ' : '') . "?Criteria \$criteria = null, ?ConnectionInterface \$con = null)
{
if (null === \$criteria) {
\$criteria = new Criteria($tableMapClassName::DATABASE_NAME);
Expand Down Expand Up @@ -666,7 +666,7 @@ protected function addIsValid(string &$script): void
* @param $objectClassName \$node Propel object for src node
* @return bool
*/
static public function isValid($objectClassName \$node = null)
static public function isValid(?$objectClassName \$node = null)
{
if (is_object(\$node) && \$node->getRightValue() > \$node->getLeftValue()) {
return true;
Expand Down Expand Up @@ -701,7 +701,7 @@ protected function addDeleteTree(string &$script): void
*
* @return int The number of deleted nodes
*/
static public function deleteTree(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
static public function deleteTree(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
{";
if ($useScope) {
$script .= "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ protected function addGetMaxRankArray(string &$script): void
*
* @return int|null Highest position
*/
public function getMaxRankArray(" . ($useScope ? '$scope, ' : '') . "ConnectionInterface \$con = null): ?int
public function getMaxRankArray(" . ($useScope ? '$scope, ' : '') . "?ConnectionInterface \$con = null): ?int
{
if (\$con === null) {
\$con = Propel::getConnection({$this->tableMapClassName}::DATABASE_NAME);
Expand Down Expand Up @@ -529,7 +529,7 @@ protected function addRetrieveByRank(string &$script): void
*
* @return {$this->objectClassName}
*/
static public function retrieveByRank(\$rank, " . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
static public function retrieveByRank(\$rank, " . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
{
if (null === \$con) {
\$con = Propel::getServiceContainer()->getReadConnection({$this->tableMapClassName}::DATABASE_NAME);
Expand Down Expand Up @@ -693,7 +693,7 @@ protected function addShiftRank(string &$script): void
$script .= "
* @param ConnectionInterface \$con Connection to use.
*/
static public function sortableShiftRank(\$delta, \$first, \$last = null, " . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
static public function sortableShiftRank(\$delta, \$first, \$last = null, " . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
{
if (null === \$con) {
\$con = Propel::getServiceContainer()->getWriteConnection({$this->tableMapClassName}::DATABASE_NAME);
Expand Down
6 changes: 5 additions & 1 deletion src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,11 @@ protected function getCrossFKAddMethodInformation(CrossForeignKeys $crossFKs, $c
if ($crossFK instanceof ForeignKey) {
$crossObjectName = '$' . lcfirst($this->getFKPhpNameAffix($crossFK));
$crossObjectClassName = $this->getClassNameFromTable($crossFK->getForeignTableOrFail());
$signature[] = "$crossObjectClassName $crossObjectName" . ($crossFK->isAtLeastOneLocalColumnRequired() ? '' : ' = null');
if ($crossFK->isAtLeastOneLocalColumnRequired()) {
$signature[] = "$crossObjectClassName $crossObjectName";
} else {
$signature[] = "?$crossObjectClassName $crossObjectName = null";
}
$shortSignature[] = $crossObjectName;
$normalizedShortSignature[] = $crossObjectName;
$phpDoc[] = "
Expand Down
19 changes: 10 additions & 9 deletions src/Propel/Generator/Builder/Om/ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ public function addJsonAccessorOpen(string &$script, Column $column): void
$script .= "
" . $visibility . " function get$cfc(\$asArray = true";
if ($column->isLazyLoad()) {
$script .= ', ConnectionInterface $con = null';
$script .= ', ?ConnectionInterface $con = null';
}

$script .= ")
Expand Down Expand Up @@ -1278,7 +1278,7 @@ public function addBooleanAccessorOpen(string &$script, Column $column): void
$script .= "
" . $visibility . " function $name(";
if ($column->isLazyLoad()) {
$script .= 'ConnectionInterface $con = null';
$script .= '?ConnectionInterface $con = null';
}

$script .= ")
Expand Down Expand Up @@ -1483,7 +1483,7 @@ protected function addHasArrayElement(string &$script, Column $column): void
*/
$visibility function has$singularPhpName(\$value";
if ($column->isLazyLoad()) {
$script .= ', ConnectionInterface $con = null';
$script .= ', ?ConnectionInterface $con = null';
}

$script .= "): bool
Expand Down Expand Up @@ -1557,7 +1557,7 @@ public function addDefaultAccessorOpen(string &$script, Column $column): void
$script .= "
" . $visibility . " function get$cfc(";
if ($column->isLazyLoad()) {
$script .= 'ConnectionInterface $con = null';
$script .= '?ConnectionInterface $con = null';
}

$script .= ")
Expand Down Expand Up @@ -1852,6 +1852,7 @@ public function addMutatorOpenOpen(string &$script, Column $column): void
$typeHint .= ' ';

if (!$column->isNotNull()) {
$typeHint = '?' . $typeHint;
$null = ' = null';
}
}
Expand Down Expand Up @@ -2206,7 +2207,7 @@ protected function addAddArrayElement(string &$script, Column $col): void
*/
$visibility function add$singularPhpName(\$value";
if ($col->isLazyLoad()) {
$script .= ', ConnectionInterface $con = null';
$script .= ', ?ConnectionInterface $con = null';
}

$script .= ")
Expand Down Expand Up @@ -2254,7 +2255,7 @@ protected function addRemoveArrayElement(string &$script, Column $col): void
*/
$visibility function remove$singularPhpName(\$value";
if ($col->isLazyLoad()) {
$script .= ', ConnectionInterface $con = null';
$script .= ', ?ConnectionInterface $con = null';
}
// we want to reindex the array, so array_ functions are not the best choice
$script .= ")
Expand Down Expand Up @@ -4141,7 +4142,7 @@ protected function addFKMutator(string &$script, ForeignKey $fk): void
* @return \$this The current object (for fluent API support)
* @throws \Propel\Runtime\Exception\PropelException
*/
public function set" . $this->getFKPhpNameAffix($fk, false) . "($className \$v = null)
public function set" . $this->getFKPhpNameAffix($fk, false) . "(?$className \$v = null)
{";

foreach ($fk->getMapping() as $map) {
Expand Down Expand Up @@ -4958,11 +4959,11 @@ protected function addPKRefFKSet(string &$script, ForeignKey $refFK): void
/**
* Sets a single $className object as related to this object by a one-to-one relationship.
*
* @param $className \$v $className
* @param $className|null \$v $className
* @return \$this The current object (for fluent API support)
* @throws \Propel\Runtime\Exception\PropelException
*/
public function set" . $this->getRefFKPhpNameAffix($refFK, false) . "($className \$v = null)
public function set" . $this->getRefFKPhpNameAffix($refFK, false) . "(?$className \$v = null)
{
\$this->$varName = \$v;
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Builder/Om/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ protected function addWithRelatedQuery(string &$script, Table $fkTable, string $
*/
public function with{$relationName}Query(
callable \$callable,
string \$relationAlias = null,
?string \$relationAlias = null,
?string \$joinType = {$joinType}
) {
\$relatedQuery = \$this->use{$relationName}Query(
Expand Down Expand Up @@ -1714,7 +1714,7 @@ protected function addFilterByCrossFK(string &$script, CrossForeignKeys $crossFK
*
* @return \$this The current query, for fluid interface
*/
public function filterBy{$relName}($objectName, string \$comparison = null)
public function filterBy{$relName}($objectName, ?string \$comparison = null)
{
\$this
->use{$relationName}Query()
Expand Down
2 changes: 1 addition & 1 deletion templates/Behavior/Validate/objectValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param ValidatorInterface|null $validator A Validator class instance
* @return bool Whether all objects pass validation.
*/
public function validate(ValidatorInterface $validator = null)
public function validate(?ValidatorInterface $validator = null)
{
if (null === $validator) {
$validator = new RecursiveValidator(
Expand Down

0 comments on commit 0bc844f

Please sign in to comment.