Skip to content

Commit 3183617

Browse files
fix codestyle
1 parent a52a5a8 commit 3183617

1 file changed

Lines changed: 36 additions & 19 deletions

File tree

library/Notifications/Common/EntityManager.php

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function delete(Model $model): void
101101
}
102102

103103
$this->db->delete($model->getTableName(), $scope);
104-
foreach ((array) $model->getKeyName() as $k) {
104+
foreach ((array)$model->getKeyName() as $k) {
105105
unset($model->$k);
106106
}
107107

@@ -228,7 +228,7 @@ protected function persist(Model $model, Resolver $resolver): void
228228
// Single auto-increment key that wasn't assigned by the application
229229
$id = $this->db->lastInsertId();
230230
if ($id !== false) {
231-
$model->$keyName = $behaviors->retrieveProperty((int) $id, $keyName);
231+
$model->$keyName = $behaviors->retrieveProperty((int)$id, $keyName);
232232
}
233233
}
234234

@@ -248,10 +248,12 @@ protected function persist(Model $model, Resolver $resolver): void
248248

249249
$scope = $this->keyScope($model, $behaviors);
250250
if ($scope === null) {
251-
throw new RuntimeException(sprintf(
252-
'Cannot update %s without a primary key value',
253-
get_class($model)
254-
));
251+
throw new RuntimeException(
252+
sprintf(
253+
'Cannot update %s without a primary key value',
254+
get_class($model)
255+
)
256+
);
255257
}
256258

257259
// Stamp only now that we know an UPDATE will actually go out. The stamp adds
@@ -339,7 +341,7 @@ protected function keyScope(Model $model, Behaviors $behaviors): ?array
339341
{
340342
$scope = [];
341343

342-
foreach ((array) $model->getKeyName() as $key) {
344+
foreach ((array)$model->getKeyName() as $key) {
343345
if (! $model->hasProperty($key)) {
344346
return null;
345347
}
@@ -401,7 +403,7 @@ protected function saveLinks(BelongsToMany $relation, Model $source, array $targ
401403
foreach ($targets as $target) {
402404
$targetBehaviors = $this->resolverFor($target)->getBehaviors($target);
403405
$value = $targetBehaviors->persistProperty($target->$targetColumn, $targetColumn);
404-
$desired[(string) $value] = $value;
406+
$desired[(string)$value] = $value;
405407
}
406408

407409
if (in_array('deleted', $junction->getColumns(), true)) {
@@ -415,7 +417,10 @@ protected function saveLinks(BelongsToMany $relation, Model $source, array $targ
415417

416418
foreach ($stored as $identity => $value) {
417419
if (! isset($desired[$identity])) {
418-
$this->db->delete($table, $this->equalityScope(array_merge($sourceColumns, [$junctionColumn => $value])));
420+
$this->db->delete(
421+
$table,
422+
$this->equalityScope(array_merge($sourceColumns, [$junctionColumn => $value]))
423+
);
419424
}
420425
}
421426

@@ -448,7 +453,7 @@ private function fetchLinks(string $table, array $sourceColumns, string $junctio
448453
$stored = [];
449454
foreach ($this->db->select($select)->fetchAll(PDO::FETCH_ASSOC) as $row) {
450455
$value = $row[$junctionColumn];
451-
$stored[(string) $value] = $value;
456+
$stored[(string)$value] = $value;
452457
}
453458

454459
return $stored;
@@ -473,10 +478,14 @@ private function fetchLinks(string $table, array $sourceColumns, string $junctio
473478
*
474479
* @return void
475480
*/
476-
private function reconcileSoftLinks(Model $junction, array $sourceColumns, string $junctionColumn, array $desired): void
477-
{
481+
private function reconcileSoftLinks(
482+
Model $junction,
483+
array $sourceColumns,
484+
string $junctionColumn,
485+
array $desired
486+
): void {
478487
$table = $junction->getTableName();
479-
$changedAt = (int) ($this->now()->format('U.u') * 1000.0);
488+
$changedAt = (int)($this->now()->format('U.u') * 1000.0);
480489

481490
$select = (new Select())
482491
->from($table)
@@ -485,27 +494,35 @@ private function reconcileSoftLinks(Model $junction, array $sourceColumns, strin
485494

486495
$stored = [];
487496
foreach ($this->db->select($select)->fetchAll(PDO::FETCH_ASSOC) as $row) {
488-
$stored[(string) $row[$junctionColumn]] = [
489-
'value' => $row[$junctionColumn],
497+
$stored[(string)$row[$junctionColumn]] = [
498+
'value' => $row[$junctionColumn],
490499
'deleted' => $row['deleted'] === 'y',
491500
];
492501
}
493502

494503
// Soft-delete links that are no longer desired but still active.
495504
foreach ($stored as $identity => $link) {
496505
if (! isset($desired[$identity]) && ! $link['deleted']) {
497-
$this->markLink($table, array_merge($sourceColumns, [$junctionColumn => $link['value']]), 'y', $changedAt);
506+
$this->markLink(
507+
$table,
508+
array_merge($sourceColumns, [$junctionColumn => $link['value']]),
509+
'y',
510+
$changedAt
511+
);
498512
}
499513
}
500514

501515
// Revive desired links that are soft-deleted; collect those not stored at all for insert.
502516
$missing = [];
503517
foreach ($desired as $identity => $value) {
504518
if (! isset($stored[$identity])) {
505-
$missing[] = array_merge($sourceColumns, [$junctionColumn => $value, 'deleted' => 'n', 'changed_at' => $changedAt]);
519+
$missing[] = array_merge(
520+
$sourceColumns,
521+
[$junctionColumn => $value, 'deleted' => 'n', 'changed_at' => $changedAt]
522+
);
506523
} elseif ($stored[$identity]['deleted']) {
507524
$this->markLink($table, array_merge($sourceColumns, [$junctionColumn => $value]), 'n', $changedAt);
508-
}
525+
}
509526
}
510527

511528
$this->insertRows($table, $missing);
@@ -605,7 +622,7 @@ protected function writableColumns(Model $model): array
605622

606623
$columns = [];
607624

608-
foreach ((array) $model->getKeyName() as $key) {
625+
foreach ((array)$model->getKeyName() as $key) {
609626
$columns[$key] = $key;
610627
}
611628

0 commit comments

Comments
 (0)