Skip to content

Commit 472ea91

Browse files
authored
standardize multiline ternaries (#55056)
if either the truthy or falsy expression is on a newline, make them both on a new line, and indent exactly once. I don't think we have to go so far as to say ALL ternaries need to be multi-line, but I would say if one expression is, they both should be. will make for easy readability and better diffs. unable to found an automation rule for this yet, but will keep looking.
1 parent 2416981 commit 472ea91

File tree

14 files changed

+36
-19
lines changed

14 files changed

+36
-19
lines changed

src/Illuminate/Broadcasting/BroadcastEvent.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public function __construct($event)
7575
public function handle(BroadcastingFactory $manager)
7676
{
7777
$name = method_exists($this->event, 'broadcastAs')
78-
? $this->event->broadcastAs() : get_class($this->event);
78+
? $this->event->broadcastAs()
79+
: get_class($this->event);
7980

8081
$channels = Arr::wrap($this->event->broadcastOn());
8182

src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,9 @@ public function joiningTable($related, $instance = null)
821821
// sorted alphabetically and concatenated with an underscore, so we can
822822
// just sort the models and join them together to get the table name.
823823
$segments = [
824-
$instance ? $instance->joiningTableSegment()
825-
: Str::snake(class_basename($related)),
824+
$instance
825+
? $instance->joiningTableSegment()
826+
: Str::snake(class_basename($related)),
826827
$this->joiningTableSegment(),
827828
];
828829

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,8 @@ public function push()
10951095
// us to recurse into all of these nested relations for the model instance.
10961096
foreach ($this->relations as $models) {
10971097
$models = $models instanceof Collection
1098-
? $models->all() : [$models];
1098+
? $models->all()
1099+
: [$models];
10991100

11001101
foreach (array_filter($models) as $model) {
11011102
if (! $model->push()) {

src/Illuminate/Database/Eloquent/Relations/MorphToMany.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ public function newPivot(array $attributes = [], $exists = false)
157157

158158
$attributes = array_merge([$this->morphType => $this->morphClass], $attributes);
159159

160-
$pivot = $using ? $using::fromRawAttributes($this->parent, $attributes, $this->table, $exists)
161-
: MorphPivot::fromAttributes($this->parent, $attributes, $this->table, $exists);
160+
$pivot = $using
161+
? $using::fromRawAttributes($this->parent, $attributes, $this->table, $exists)
162+
: MorphPivot::fromAttributes($this->parent, $attributes, $this->table, $exists);
162163

163164
$pivot->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey)
164165
->setRelatedModel($this->related)

src/Illuminate/Database/Query/Builder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,8 @@ protected function withoutSelectAliases(array $columns)
33063306
{
33073307
return array_map(function ($column) {
33083308
return is_string($column) && ($aliasPosition = stripos($column, ' as ')) !== false
3309-
? substr($column, 0, $aliasPosition) : $column;
3309+
? substr($column, 0, $aliasPosition)
3310+
: $column;
33103311
}, $columns);
33113312
}
33123313

@@ -3634,7 +3635,8 @@ public function numericAggregate($function, $columns = ['*'])
36343635
// cast it to one. When it does we will cast it to a float since it needs to be
36353636
// cast to the expected data type for the developers out of pure convenience.
36363637
return ! str_contains((string) $result, '.')
3637-
? (int) $result : (float) $result;
3638+
? (int) $result
3639+
: (float) $result;
36383640
}
36393641

36403642
/**

src/Illuminate/Database/Schema/BlueprintState.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ public function __construct(Blueprint $blueprint, Connection $connection)
7777
'collation' => $column['collation'],
7878
'comment' => $column['comment'],
7979
'virtualAs' => ! is_null($column['generation']) && $column['generation']['type'] === 'virtual'
80-
? $column['generation']['expression'] : null,
80+
? $column['generation']['expression']
81+
: null,
8182
'storedAs' => ! is_null($column['generation']) && $column['generation']['type'] === 'stored'
82-
? $column['generation']['expression'] : null,
83+
? $column['generation']['expression']
84+
: null,
8385
]))->all();
8486

8587
[$primary, $indexes] = (new Collection($schema->getIndexes($table)))->map(fn ($index) => new IndexDefinition([

src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,11 @@ protected function compileLegacyRenameColumn(Blueprint $blueprint, Fluent $comma
381381
'collation' => $column['collation'],
382382
'comment' => $column['comment'],
383383
'virtualAs' => ! is_null($column['generation']) && $column['generation']['type'] === 'virtual'
384-
? $column['generation']['expression'] : null,
384+
? $column['generation']['expression']
385+
: null,
385386
'storedAs' => ! is_null($column['generation']) && $column['generation']['type'] === 'stored'
386-
? $column['generation']['expression'] : null,
387+
? $column['generation']['expression']
388+
: null,
387389
]));
388390

389391
return sprintf('alter table %s change %s %s %s',

src/Illuminate/Events/Dispatcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ protected function shouldBroadcast(array $payload)
344344
protected function broadcastWhen($event)
345345
{
346346
return method_exists($event, 'broadcastWhen')
347-
? $event->broadcastWhen() : true;
347+
? $event->broadcastWhen()
348+
: true;
348349
}
349350

350351
/**

src/Illuminate/Foundation/Testing/DatabaseTruncation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ protected function tableExistsIn(array $table, array $tables): bool
141141
protected function connectionsToTruncate(): array
142142
{
143143
return property_exists($this, 'connectionsToTruncate')
144-
? $this->connectionsToTruncate : [null];
144+
? $this->connectionsToTruncate
145+
: [null];
145146
}
146147

147148
/**

src/Illuminate/Routing/Route.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ public function domain($domain = null)
792792
public function getDomain()
793793
{
794794
return isset($this->action['domain'])
795-
? str_replace(['http://', 'https://'], '', $this->action['domain']) : null;
795+
? str_replace(['http://', 'https://'], '', $this->action['domain'])
796+
: null;
796797
}
797798

798799
/**

0 commit comments

Comments
 (0)