Skip to content

Commit feab79f

Browse files
authored
Merge pull request #40 from mringler/nulls
Mark nullable parameters as such in generated code
2 parents 7324057 + ad1c4af commit feab79f

File tree

9 files changed

+30
-25
lines changed

9 files changed

+30
-25
lines changed

src/Propel/Generator/Behavior/AggregateColumn/AggregateColumnRelationBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function objectFilter(string &$script, AbstractOMBuilder $builder): void
111111
$relationName = $this->getRelationName($builder);
112112
$aggregateName = $this->getParameter('aggregate_name');
113113
$relatedClass = $builder->getClassNameFromBuilder($builder->getNewStubObjectBuilder($this->getForeignTable()));
114-
$search = " public function set{$relationName}({$relatedClass} \$v = null)
114+
$search = " public function set{$relationName}(?{$relatedClass} \$v = null)
115115
{";
116116
$replace = $search . "
117117
// aggregate_column_relation behavior

src/Propel/Generator/Behavior/Delegate/DelegateBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public function queryMethods(QueryBuilder $builder): string
342342
*
343343
* @return \$this
344344
*/
345-
public function filterBy(string \$column, \$value, string \$comparison = null)
345+
public function filterBy(string \$column, \$value, ?string \$comparison = null)
346346
{
347347
if (isset(\$this->delegatedFields[\$column])) {
348348
\$methodUse = \"use{\$this->delegatedFields[\$column]}Query\";

src/Propel/Generator/Behavior/NestedSet/NestedSetBehaviorObjectBuilderModifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ protected function addSetParent(string &$script): void
643643
* @param $objectClassName \$parent
644644
* @return \$this
645645
*/
646-
public function setParent($objectClassName \$parent = null)
646+
public function setParent(?$objectClassName \$parent = null)
647647
{
648648
\$this->aNestedSetParent = \$parent;
649649

src/Propel/Generator/Behavior/NestedSet/NestedSetBehaviorQueryBuilderModifier.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ protected function addFindRoot(string &$script): void
476476
*
477477
* @return {$this->objectClassName} The tree root object
478478
*/
479-
public function findRoot(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
479+
public function findRoot(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
480480
{
481481
return \$this
482482
->addUsingOperator(\$this->resolveLocalColumnByName('{$leftColumnName}'), 1, Criteria::EQUAL)";
@@ -536,7 +536,7 @@ protected function addFindTree(string &$script): void
536536
*
537537
* @return {$this->objectClassName}[]|ObjectCollection|mixed the list of results, formatted by the current formatter
538538
*/
539-
public function findTree(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
539+
public function findTree(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
540540
{
541541
return \$this";
542542
if ($useScope) {
@@ -605,7 +605,7 @@ protected function addRetrieveRoot(string &$script): void
605605
* @param ConnectionInterface \$con Connection to use.
606606
* @return {$this->objectClassName} Propel object for root node
607607
*/
608-
static public function retrieveRoot(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
608+
static public function retrieveRoot(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
609609
{
610610
\$c = new Criteria($tableMapClassName::DATABASE_NAME);
611611
\$c->addFilter($objectClassName::LEFT_COL, 1, Criteria::EQUAL);";
@@ -645,7 +645,7 @@ protected function addRetrieveTree(string &$script): void
645645
* @param ConnectionInterface \$con Connection to use.
646646
* @return {$this->objectClassName}[]|ObjectCollection|mixed the list of results, formatted by the current formatter
647647
*/
648-
static public function retrieveTree(" . ($useScope ? '$scope = null, ' : '') . "Criteria \$criteria = null, ?ConnectionInterface \$con = null)
648+
static public function retrieveTree(" . ($useScope ? '$scope = null, ' : '') . "?Criteria \$criteria = null, ?ConnectionInterface \$con = null)
649649
{
650650
if (null === \$criteria) {
651651
\$criteria = new Criteria($tableMapClassName::DATABASE_NAME);
@@ -678,7 +678,7 @@ protected function addIsValid(string &$script): void
678678
* @param $objectClassName \$node Propel object for src node
679679
* @return bool
680680
*/
681-
static public function isValid($objectClassName \$node = null)
681+
static public function isValid(?$objectClassName \$node = null)
682682
{
683683
if (is_object(\$node) && \$node->getRightValue() > \$node->getLeftValue()) {
684684
return true;
@@ -713,7 +713,7 @@ protected function addDeleteTree(string &$script): void
713713
*
714714
* @return int The number of deleted nodes
715715
*/
716-
static public function deleteTree(" . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
716+
static public function deleteTree(" . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
717717
{";
718718
if ($useScope) {
719719
$script .= "

src/Propel/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ protected function addGetMaxRankArray(string &$script): void
442442
*
443443
* @return int|null Highest position
444444
*/
445-
public function getMaxRankArray(" . ($useScope ? '$scope, ' : '') . "ConnectionInterface \$con = null): ?int
445+
public function getMaxRankArray(" . ($useScope ? '$scope, ' : '') . "?ConnectionInterface \$con = null): ?int
446446
{
447447
if (\$con === null) {
448448
\$con = Propel::getConnection({$this->tableMapClassName}::DATABASE_NAME);
@@ -528,7 +528,7 @@ protected function addRetrieveByRank(string &$script): void
528528
*
529529
* @return {$this->objectClassName}
530530
*/
531-
static public function retrieveByRank(\$rank, " . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
531+
static public function retrieveByRank(\$rank, " . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
532532
{
533533
if (null === \$con) {
534534
\$con = Propel::getServiceContainer()->getReadConnection({$this->tableMapClassName}::DATABASE_NAME);
@@ -692,7 +692,7 @@ protected function addShiftRank(string &$script): void
692692
$script .= "
693693
* @param ConnectionInterface \$con Connection to use.
694694
*/
695-
static public function sortableShiftRank(\$delta, \$first, \$last = null, " . ($useScope ? '$scope = null, ' : '') . "ConnectionInterface \$con = null)
695+
static public function sortableShiftRank(\$delta, \$first, \$last = null, " . ($useScope ? '$scope = null, ' : '') . "?ConnectionInterface \$con = null)
696696
{
697697
if (null === \$con) {
698698
\$con = Propel::getServiceContainer()->getWriteConnection({$this->tableMapClassName}::DATABASE_NAME);

src/Propel/Generator/Builder/Om/AbstractOMBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,11 @@ protected function getCrossFKAddMethodInformation(CrossForeignKeys $crossFKs, $c
805805
if ($crossFK instanceof ForeignKey) {
806806
$crossObjectName = '$' . lcfirst($this->getFKPhpNameAffix($crossFK));
807807
$crossObjectClassName = $this->getClassNameFromTable($crossFK->getForeignTableOrFail());
808-
$signature[] = "$crossObjectClassName $crossObjectName" . ($crossFK->isAtLeastOneLocalColumnRequired() ? '' : ' = null');
808+
if ($crossFK->isAtLeastOneLocalColumnRequired()) {
809+
$signature[] = "$crossObjectClassName $crossObjectName";
810+
} else {
811+
$signature[] = "?$crossObjectClassName $crossObjectName = null";
812+
}
809813
$shortSignature[] = $crossObjectName;
810814
$normalizedShortSignature[] = $crossObjectName;
811815
$phpDoc[] = "

src/Propel/Generator/Builder/Om/ObjectBuilder.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ public function addJsonAccessorOpen(string &$script, Column $column): void
11611161
$script .= "
11621162
" . $visibility . " function get$cfc(\$asArray = true";
11631163
if ($column->isLazyLoad()) {
1164-
$script .= ', ConnectionInterface $con = null';
1164+
$script .= ', ?ConnectionInterface $con = null';
11651165
}
11661166

11671167
$script .= ")
@@ -1279,7 +1279,7 @@ public function addBooleanAccessorOpen(string &$script, Column $column): void
12791279
$script .= "
12801280
" . $visibility . " function $name(";
12811281
if ($column->isLazyLoad()) {
1282-
$script .= 'ConnectionInterface $con = null';
1282+
$script .= '?ConnectionInterface $con = null';
12831283
}
12841284

12851285
$script .= ")
@@ -1484,7 +1484,7 @@ protected function addHasArrayElement(string &$script, Column $column): void
14841484
*/
14851485
$visibility function has$singularPhpName(\$value";
14861486
if ($column->isLazyLoad()) {
1487-
$script .= ', ConnectionInterface $con = null';
1487+
$script .= ', ?ConnectionInterface $con = null';
14881488
}
14891489

14901490
$script .= "): bool
@@ -1558,7 +1558,7 @@ public function addDefaultAccessorOpen(string &$script, Column $column): void
15581558
$script .= "
15591559
" . $visibility . " function get$cfc(";
15601560
if ($column->isLazyLoad()) {
1561-
$script .= 'ConnectionInterface $con = null';
1561+
$script .= '?ConnectionInterface $con = null';
15621562
}
15631563

15641564
$script .= ")
@@ -1855,6 +1855,7 @@ public function addMutatorOpenOpen(string &$script, Column $column): void
18551855
$typeHint .= ' ';
18561856

18571857
if (!$column->isNotNull()) {
1858+
$typeHint = '?' . $typeHint;
18581859
$null = ' = null';
18591860
}
18601861
}
@@ -2209,7 +2210,7 @@ protected function addAddArrayElement(string &$script, Column $col): void
22092210
*/
22102211
$visibility function add$singularPhpName(\$value";
22112212
if ($col->isLazyLoad()) {
2212-
$script .= ', ConnectionInterface $con = null';
2213+
$script .= ', ?ConnectionInterface $con = null';
22132214
}
22142215

22152216
$script .= ")
@@ -2257,7 +2258,7 @@ protected function addRemoveArrayElement(string &$script, Column $col): void
22572258
*/
22582259
$visibility function remove$singularPhpName(\$value";
22592260
if ($col->isLazyLoad()) {
2260-
$script .= ', ConnectionInterface $con = null';
2261+
$script .= ', ?ConnectionInterface $con = null';
22612262
}
22622263
// we want to reindex the array, so array_ functions are not the best choice
22632264
$script .= ")
@@ -4033,7 +4034,7 @@ protected function addFKMutator(string &$script, ForeignKey $fk): void
40334034
* @return \$this The current object (for fluent API support)
40344035
* @throws \Propel\Runtime\Exception\PropelException
40354036
*/
4036-
public function set" . $this->getFKPhpNameAffix($fk, false) . "($className \$v = null)
4037+
public function set" . $this->getFKPhpNameAffix($fk, false) . "(?$className \$v = null)
40374038
{";
40384039

40394040
foreach ($fk->getMapping() as $map) {
@@ -4850,11 +4851,11 @@ protected function addPKRefFKSet(string &$script, ForeignKey $refFK): void
48504851
/**
48514852
* Sets a single $className object as related to this object by a one-to-one relationship.
48524853
*
4853-
* @param $className \$v $className
4854+
* @param $className|null \$v $className
48544855
* @return \$this The current object (for fluent API support)
48554856
* @throws \Propel\Runtime\Exception\PropelException
48564857
*/
4857-
public function set" . $this->getRefFKPhpNameAffix($refFK, false) . "($className \$v = null)
4858+
public function set" . $this->getRefFKPhpNameAffix($refFK, false) . "(?$className \$v = null)
48584859
{
48594860
\$this->$varName = \$v;
48604861

src/Propel/Generator/Builder/Om/QueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ protected function addWithRelatedQuery(string &$script, Table $fkTable, string $
17121712
*/
17131713
public function with{$relationName}Query(
17141714
callable \$callable,
1715-
string \$relationAlias = null,
1715+
?string \$relationAlias = null,
17161716
?string \$joinType = {$joinType}
17171717
) {
17181718
\$relatedQuery = \$this->use{$relationName}Query(
@@ -1754,7 +1754,7 @@ protected function addFilterByCrossFK(string &$script, CrossForeignKeys $crossFK
17541754
*
17551755
* @return \$this
17561756
*/
1757-
public function filterBy{$relName}($objectName, string \$comparison = null)
1757+
public function filterBy{$relName}($objectName, ?string \$comparison = null)
17581758
{
17591759
\$this
17601760
->use{$relationName}Query()

templates/Behavior/Validate/objectValidate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @param ValidatorInterface|null $validator A Validator class instance
77
* @return bool Whether all objects pass validation.
88
*/
9-
public function validate(ValidatorInterface $validator = null)
9+
public function validate(?ValidatorInterface $validator = null)
1010
{
1111
if (null === $validator) {
1212
$validator = new RecursiveValidator(

0 commit comments

Comments
 (0)