Skip to content

Commit 854c229

Browse files
committed
Initial fixes for PHP8 compat and postgres compat
1 parent 20fc683 commit 854c229

File tree

23 files changed

+65
-27
lines changed

23 files changed

+65
-27
lines changed

src/Common/Crud/Action/Object/CustomObjectActionHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function loadTypeHintsFromCallable(callable $handler)
4848
}
4949

5050
$parameters = $reflection->getParameters();
51-
$objectTypeHint = $parameters[0]->getClass();
51+
$objectTypeHint = @$parameters[0]->getClass();
5252

5353
if (!$objectTypeHint) {
5454
throw InvalidHandlerClassException::format(
@@ -58,7 +58,7 @@ protected function loadTypeHintsFromCallable(callable $handler)
5858
}
5959

6060
if (isset($parameters[1])) {
61-
$dataParameterTypeHint = $parameters[1]->getClass();
61+
$dataParameterTypeHint = @$parameters[1]->getClass();
6262

6363
if (!$dataParameterTypeHint) {
6464
throw InvalidHandlerClassException::format(

src/Common/Crud/Definition/Action/ObjectActionDefiner.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ private function wrapArrayParameterAsDto(callable $handler) : array
278278
$objectParameter = $reflectionParameters[0] ?? null;
279279
$dtoParameter = $reflectionParameters[1] ?? null;
280280

281-
if (!$objectParameter || !$objectParameter->getClass() || !$dtoParameter || !$dtoParameter->isArray()) {
281+
if (!$objectParameter || !@$objectParameter->getClass() || !$dtoParameter || !@$dtoParameter->isArray()) {
282282
return [$handler, null, null];
283283
}
284284

285285
$handler = function ($object, ArrayDataObject $array) use ($handler) {
286286
return $handler($object, $array->getArray());
287287
};
288288

289-
return [$handler, $objectParameter->getClass()->getName(), ArrayDataObject::class];
289+
return [$handler, @$objectParameter->getClass()->getName(), ArrayDataObject::class];
290290
}
291291
}

src/Form/Field/Processor/Validator/FilterValidator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class FilterValidator extends FieldValidator
2525
*/
2626
private $options;
2727

28-
public function __construct(IType $inputType, $filter, $options = null)
28+
public function __construct(IType $inputType, $filter, $options = [])
2929
{
3030
parent::__construct($inputType);
3131
$this->filter = $filter;

src/Model/Criteria/Condition/ConditionOperator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public static function makeOperatorCallable(callable $left, string $operator, ca
187187
$l = $left($arg);
188188
$r = $right($arg);
189189

190-
if ($l === null || $r === null) {
190+
if ($l === null || $r === null || $r === '') {
191191
return false;
192192
}
193193

src/Model/Object/AbstractProxyGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected static function getReturnType(\ReflectionMethod $method) : string
9999
protected static function getParameterTypeHint(\ReflectionParameter $parameter) : string
100100
{
101101
if ($parameter->hasType()) {
102-
return self::convertReflectedTypeToCode($parameter->getType(), $parameter->getClass());
102+
return self::convertReflectedTypeToCode($parameter->getType(), @$parameter->getClass());
103103
} else {
104104
return '';
105105
}

src/Module/Definition/ActionDefiner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private function wrapArrayParameterAsDto(callable $handler) : array
289289

290290
$parameter = $reflection->getParameters()[0] ?? null;
291291

292-
if (!$parameter || !$parameter->isArray()) {
292+
if (!$parameter || !@$parameter->isArray()) {
293293
return [$handler, null];
294294
}
295295

src/Module/Handler/ReflectionBasedActionHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final protected function getTypeFromParameter(
2727
);
2828
}
2929

30-
$typeHint = $parameters[0]->getClass();
30+
$typeHint = @$parameters[0]->getClass();
3131

3232
if (!$typeHint) {
3333
throw InvalidHandlerClassException::format(

src/Persistence/Db/Connection/Connection.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function upsert(Upsert $query)
122122
$rowsWithKeys = $query->getRowsWithPrimaryKeys();
123123
$rowsWithKeyArray = $rowsWithKeys->getRows();
124124
$rowsData = $this->platform->mapResultSetToDbFormat($rowsWithKeys, 'lock__');
125+
;
125126
if ($rowsData) {
126127
$lockingColumnNameParameterMap = [];
127128

@@ -164,12 +165,20 @@ public function upsert(Upsert $query)
164165
$rowArray = $rowsWithoutKeys->getRows();
165166
$rowsData = $this->platform->mapResultSetToDbFormat($rowsWithoutKeys);
166167
$defaultData = $table->getNullColumnData();
168+
$primaryKeyToRemove = !$this->platform->defaultPrimaryKeyToNull() && $table->hasPrimaryKeyColumn()
169+
? $table->getPrimaryKeyColumnName() : null;
167170

168171
if ($rowsData) {
169-
$insert = $this->prepare($this->platform->compilePreparedInsert($table));
172+
$insert = $this->prepare($this->platform->compilePreparedInsert($table, $this->platform->defaultPrimaryKeyToNull()));
170173

171174
foreach ($rowsData as $key => $row) {
172-
$insert->setParameters($row + $defaultData);
175+
$params = $row + $defaultData;
176+
177+
if ($primaryKeyToRemove) {
178+
unset($params[$primaryKeyToRemove]);
179+
}
180+
181+
$insert->setParameters($params);
173182
$insert->execute();
174183
$rowArray[$key]->firePrimaryKeyCallbacks($this->getLastInsertId());
175184
}

src/Persistence/Db/Doctrine/DoctrinePlatform.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Dms\Core\Persistence\Db\Schema\Table;
1919
use Doctrine\DBAL\Connection as DbalConnection;
2020
use Doctrine\DBAL\Platforms\AbstractPlatform as DoctrineAbstractPlatform;
21+
use Doctrine\DBAL\Platforms\MySqlPlatform;
2122
use Doctrine\DBAL\Query\QueryBuilder;
2223

2324
/**
@@ -81,11 +82,11 @@ public function getExpressionCompiler() : DoctrineExpressionCompiler
8182
/**
8283
* @inheritDoc
8384
*/
84-
public function compilePreparedInsert(Table $table) : string
85+
public function compilePreparedInsert(Table $table, bool $includePrimaryKey = true) : string
8586
{
8687
$queryBuilder = $this->doctrineConnection->createQueryBuilder();
8788

88-
$values = $this->createColumnParameterArray($queryBuilder, $table);
89+
$values = $this->createColumnParameterArray($queryBuilder, $table, $includePrimaryKey);
8990
$escapedIdentifierValues = [];
9091

9192
foreach ($values as $column => $parameter) {
@@ -123,14 +124,18 @@ public function compilePreparedUpdate(Table $table, array $updateColumns, array
123124
return $queryBuilder->getSQL();
124125
}
125126

126-
protected function createColumnParameterArray(QueryBuilder $queryBuilder, Table $table)
127+
protected function createColumnParameterArray(QueryBuilder $queryBuilder, Table $table, bool $includePrimaryKey)
127128
{
128129
$parameters = [];
129130

130131
foreach ($table->getColumns() as $name => $column) {
131132
$parameters[$name] = ':' . $name;
132133
}
133134

135+
if (!$includePrimaryKey && $table->hasPrimaryKeyColumn()) {
136+
unset($parameters[$table->getPrimaryKeyColumnName()]);
137+
}
138+
134139
return $parameters;
135140
}
136141

@@ -412,4 +417,9 @@ public function supportsForeignKeys(): bool
412417
{
413418
return $this->doctrinePlatform->supportsForeignKeyConstraints();
414419
}
420+
421+
public function defaultPrimaryKeyToNull(): bool
422+
{
423+
return ($this->doctrinePlatform instanceof MySqlPlatform);
424+
}
415425
}

src/Persistence/Db/Mapping/Definition/Relation/RelationMapping.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class RelationMapping
3232
*
3333
* @throws IncompatiblePropertyMappingException
3434
*/
35-
public function __construct(IAccessor $accessor, IRelation $relation, bool $ignoreNullabilityMismatch = false, bool $ignoreTypeMismatch)
35+
public function __construct(IAccessor $accessor, IRelation $relation, bool $ignoreNullabilityMismatch = false, bool $ignoreTypeMismatch = null)
3636
{
3737
$accessorType = $accessor->getCompatibleType();
3838
$relationType = $relation->getValueType();

src/Persistence/Db/Platform/IPlatform.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public function mapResultSetToDbFormat(RowSet $rows, string $lockingColumnDataPr
5252
*/
5353
public function mapResultSetToPhpForm(Table $table, array $rows) : RowSet;
5454

55+
/**
56+
* Whether to default primary key values to null
57+
*/
58+
public function defaultPrimaryKeyToNull(): bool;
59+
5560
/**
5661
* Quotes the supplied identifier.
5762
*
@@ -107,7 +112,7 @@ public function compileResequenceOrderIndexColumn(ResequenceOrderIndexColumn $qu
107112
*
108113
* @return string
109114
*/
110-
public function compilePreparedInsert(Table $table);
115+
public function compilePreparedInsert(Table $table, bool $includePrimaryKey = true);
111116

112117
/**
113118
* Compiles a prepared update query with the values as named parameters with their respective column.

src/Persistence/Db/Platform/Platform.php

-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ final public function mapResultSetToDbFormat(RowSet $rows, string $lockingColumn
129129
$rowData[$column] = isset($rowData[$column]) && $rowData[$column] instanceof \DateTimeInterface
130130
? $rowData[$column]->format($dateFormat)
131131
: null;
132-
133132
}
134133

135134
foreach ($row->getLockingColumnData() as $column => $value) {

src/Persistence/Db/Query/Query.php

+9
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ public function getOrderings() : array
298298
return $this->orderings;
299299
}
300300

301+
/**
302+
* @return static
303+
*/
304+
public function clearOrderings()
305+
{
306+
$this->orderings = [];
307+
return $this;
308+
}
309+
301310
/**
302311
* @param Ordering $ordering
303312
*

src/Persistence/DbRepositoryBase.php

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ protected function loadCount(Select $select) : int
192192
$offset = $select->getOffset();
193193

194194
$select->offset(0)->limit(null);
195+
$select->clearOrderings();
195196

196197
$rows = $this->connection->load(
197198
$select->setColumns(['count' => Expr::count()])

tests/Tests/Form/Field/Processor/FileMoverProcessorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function unprocessTests()
5757
];
5858
}
5959

60-
protected function mockUploadedFile($clientFileName, $expectedMoveToPath = null, $return, &$movePath = null)
60+
protected function mockUploadedFile($clientFileName, $expectedMoveToPath = null, $return = null, &$movePath = null)
6161
{
6262
$mock = $this->getMockForAbstractClass(IUploadedFile::class);
6363

tests/Tests/Helpers/Mock/MockingIocContainer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function get($id)
7272
if ($constructor) {
7373

7474
foreach ($constructor->getParameters() as $param) {
75-
if ($param->getClass()) {
76-
$params[] = $this->get($param->getClass()->getName());
75+
if (@$param->getClass()) {
76+
$params[] = $this->get(@$param->getClass()->getName());
7777
} elseif ($param->isDefaultValueAvailable()) {
7878
$params[] = $param->getDefaultValue();
7979
} else {

tests/Tests/Persistence/Db/Integration/Domains/Fixtures/Blog/TestAlias.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestAlias extends Entity
2323
/**
2424
* @inheritDoc
2525
*/
26-
public function __construct($id = null, $firstName, $lastName)
26+
public function __construct($id = null, $firstName = null, $lastName = null)
2727
{
2828
parent::__construct($id);
2929
$this->firstName = $firstName;

tests/Tests/Persistence/Db/Integration/Mapping/Fixtures/CustomLoader/CustomLoadedEntity.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CustomLoadedEntity extends Entity
1818
/**
1919
* @inheritDoc
2020
*/
21-
public function __construct($id = null, $integer)
21+
public function __construct($id = null, $integer = null)
2222
{
2323
parent::__construct($id);
2424
$this->integer = $integer;

tests/Tests/Persistence/Db/Integration/Mapping/Fixtures/PropertyConverters/ConvertedPropertyEntity.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ConvertedPropertyEntity extends Entity
1818
/**
1919
* @inheritDoc
2020
*/
21-
public function __construct($id = null, $integer)
21+
public function __construct($id = null, $integer = null)
2222
{
2323
parent::__construct($id);
2424
$this->integer = $integer;

tests/Tests/Persistence/Db/Integration/Mapping/Hook/Fixtures/GroupedOrderIndex/OrderedEntity.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class OrderedEntity extends Entity
2323
/**
2424
* @inheritDoc
2525
*/
26-
public function __construct($id = null, $group, $orderIndex = null)
26+
public function __construct($id = null, $group = null, $orderIndex = null)
2727
{
2828
parent::__construct($id);
2929
$this->group = $group;

tests/Tests/Persistence/Db/Integration/Mapping/ReadModel/Fixtures/Embedded/EntityWithTitle.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EntityWithTitle extends Entity
2020
/**
2121
* @inheritDoc
2222
*/
23-
public function __construct($id = null, $title)
23+
public function __construct($id = null, $title = null)
2424
{
2525
parent::__construct($id);
2626
$this->title = $title;

tests/Tests/Persistence/Db/Integration/Mapping/Relations/Fixtures/ManyToManyRelation/Polymorphic/AnotherEntitySubclass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AnotherEntitySubclass extends AnotherEntity
1515
*/
1616
public $data;
1717

18-
public function __construct($id = null, $val, $data = false)
18+
public function __construct($id = null, $val = null, $data = false)
1919
{
2020
parent::__construct($id, $val);
2121
$this->data = $data;

tests/Tests/Persistence/Db/Mock/MockPlatform.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function quoteIdentifier(string $value): string
6868
return '!!' . $value . '!!';
6969
}
7070

71-
public function compilePreparedInsert(Table $table)
71+
public function compilePreparedInsert(Table $table, bool $includePrimaryKey = true)
7272
{
7373
return new PhpPreparedCompiledQuery(function (MockDatabase $database, array $parameters) use ($table) {
7474
$table = $database->getTable($table->getName());
@@ -704,4 +704,9 @@ public function supportsForeignKeys(): bool
704704
{
705705
return false;
706706
}
707+
708+
public function defaultPrimaryKeyToNull(): bool
709+
{
710+
return true;
711+
}
707712
}

0 commit comments

Comments
 (0)