Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null union types code style #242

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ disabled:
- phpdoc_no_package
- logical_not_operators_with_successor_space
- laravel_phpdoc_alignment
- union_type_without_spaces
12 changes: 6 additions & 6 deletions contracts/Reactant/Facades/Reactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public function getReactionCounterOfType(
public function getReactionTotal(): ReactionTotal;

public function isReactedBy(
?Reacterable $reacterable = null,
?string $reactionTypeName = null,
?float $rate = null,
Reacterable | null $reacterable = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool;

public function isNotReactedBy(
?Reacterable $reacterable = null,
?string $reactionTypeName = null,
?float $rate = null,
Reacterable | null $reacterable = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool;
}
8 changes: 4 additions & 4 deletions contracts/Reactant/Models/Reactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public function getReactionTotal(): ReactionTotal;

public function isReactedBy(
Reacter $reacter,
?ReactionType $reactionType = null,
?float $rate = null,
ReactionType | null $reactionType = null,
float | null $rate = null,
): bool;

public function isNotReactedBy(
Reacter $reacter,
?ReactionType $reactionType = null,
?float $rate = null,
ReactionType | null $reactionType = null,
float | null $rate = null,
): bool;

public function isEqualTo(
Expand Down
10 changes: 5 additions & 5 deletions contracts/Reacter/Facades/Reacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getReactions(): iterable;
public function reactTo(
Reactable $reactable,
string $reactionTypeName,
?float $rate = null,
float | null $rate = null,
): void;

public function unreactTo(
Expand All @@ -32,13 +32,13 @@ public function unreactTo(

public function hasReactedTo(
Reactable $reactable,
?string $reactionTypeName = null,
?float $rate = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool;

public function hasNotReactedTo(
Reactable $reactable,
?string $reactionTypeName = null,
?float $rate = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool;
}
10 changes: 5 additions & 5 deletions contracts/Reacter/Models/Reacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getReactions(): iterable;
public function reactTo(
Reactant $reactant,
ReactionType $reactionType,
?float $rate = null,
float | null $rate = null,
): void;

public function unreactTo(
Expand All @@ -41,14 +41,14 @@ public function unreactTo(

public function hasReactedTo(
Reactant $reactant,
?ReactionType $reactionType = null,
?float $rate = null,
ReactionType | null $reactionType = null,
float | null $rate = null,
): bool;

public function hasNotReactedTo(
Reactant $reactant,
?ReactionType $reactionType = null,
?float $rate = null,
ReactionType | null $reactionType = null,
float | null $rate = null,
): bool;

public function isEqualTo(
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/Recount.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function findModelTypeInMorphMap(
* @return \Cog\Contracts\Love\Reactant\Models\Reactant[]|\Illuminate\Database\Eloquent\Collection
*/
private function collectReactants(
?string $reactableType = null,
string | null $reactableType = null,
): iterable {
$reactantsQuery = Reactant::query();

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/UpgradeV7ToV8.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function getDbQuery(): ConnectionInterface
return DB::connection($this->getDatabaseConnection());
}

private function getDatabaseConnection(): ?string
private function getDatabaseConnection(): string | null
{
return Config::get('love.storage.database.connection');
}
Expand Down
8 changes: 4 additions & 4 deletions src/Reactable/ReactableEloquentBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait ReactableEloquentBuilderTrait
{
public function whereReactedBy(
ReacterableInterface $reacterable,
?string $reactionTypeName = null,
string | null $reactionTypeName = null,
): Builder {
return $this->whereHas(
'loveReactant.reactions',
Expand All @@ -53,7 +53,7 @@ function (Builder $reactionsQuery) use (

public function whereNotReactedBy(
ReacterableInterface $reacterable,
?string $reactionTypeName = null,
string | null $reactionTypeName = null,
): Builder {
return $this->whereDoesntHave(
'loveReactant.reactions',
Expand All @@ -78,7 +78,7 @@ function (Builder $reactionsQuery) use (

public function joinReactionCounterOfType(
string $reactionTypeName,
?string $alias = null,
string | null $alias = null,
): Builder {
$reactionType = ReactionType::fromName($reactionTypeName);
$alias = $alias === null
Expand Down Expand Up @@ -111,7 +111,7 @@ function (JoinClause $join) use (
}

public function joinReactionTotal(
?string $alias = null,
string | null $alias = null,
): Builder {
$alias = $alias === null
? 'reaction_total'
Expand Down
12 changes: 6 additions & 6 deletions src/Reactant/Facades/Reactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function getReactionTotal(): ReactionTotalInterface
}

public function isReactedBy(
?ReacterableInterface $reacterable = null,
?string $reactionTypeName = null,
?float $rate = null,
ReacterableInterface | null $reacterable = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool {
if ($reacterable === null) {
return false;
Expand All @@ -79,9 +79,9 @@ public function isReactedBy(
}

public function isNotReactedBy(
?ReacterableInterface $reacterable = null,
?string $reactionTypeName = null,
?float $rate = null,
ReacterableInterface | null $reacterable = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool {
if ($reacterable === null) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Reactant/Jobs/RebuildReactionAggregatesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ final class RebuildReactionAggregatesJob implements

private ReactantInterface $reactant;

private ?ReactionTypeInterface $reactionType;
private ReactionTypeInterface | null $reactionType;

public function __construct(
ReactantInterface $reactant,
?ReactionTypeInterface $reactionType = null,
ReactionTypeInterface | null $reactionType = null,
) {
$this->reactant = $reactant;
$this->reactionType = $reactionType;
Expand Down
8 changes: 4 additions & 4 deletions src/Reactant/Models/NullReactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public function getReactionTotal(): ReactionTotalInterface

public function isReactedBy(
ReacterInterface $reacter,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
return false;
}

public function isNotReactedBy(
ReacterInterface $reacter,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Reactant/Models/Reactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public function getReactionTotal(): ReactionTotalInterface

public function isReactedBy(
ReacterInterface $reacter,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
if ($reacter->isNull()) {
return false;
Expand Down Expand Up @@ -169,8 +169,8 @@ public function isReactedBy(

public function isNotReactedBy(
ReacterInterface $reacter,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
return !$this->isReactedBy($reacter, $reactionType, $rate);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Reacter/Facades/Reacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getReactions(): iterable
public function reactTo(
ReactableInterface $reactable,
string $reactionTypeName,
?float $rate = null,
float | null $rate = null,
): void {
$this->reacter->reactTo(
$reactable->getLoveReactant(),
Expand All @@ -61,8 +61,8 @@ public function unreactTo(

public function hasReactedTo(
ReactableInterface $reactable,
?string $reactionTypeName = null,
?float $rate = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool {
$reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);

Expand All @@ -75,8 +75,8 @@ public function hasReactedTo(

public function hasNotReactedTo(
ReactableInterface $reactable,
?string $reactionTypeName = null,
?float $rate = null,
string | null $reactionTypeName = null,
float | null $rate = null,
): bool {
$reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);

Expand Down
10 changes: 5 additions & 5 deletions src/Reacter/Models/NullReacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getReactions(): iterable
public function reactTo(
ReactantInterface $reactant,
ReactionTypeInterface $reactionType,
?float $rate = null,
float | null $rate = null,
): void {
throw ReacterInvalid::notExists();
}
Expand All @@ -64,16 +64,16 @@ public function unreactTo(

public function hasReactedTo(
ReactantInterface $reactant,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
return false;
}

public function hasNotReactedTo(
ReactantInterface $reactant,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Reacter/Models/Reacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getReactions(): iterable
public function reactTo(
ReactantInterface $reactant,
ReactionTypeInterface $reactionType,
?float $rate = null,
float | null $rate = null,
): void {
if ($reactant->isNull()) {
throw ReactantInvalid::notExists();
Expand Down Expand Up @@ -123,8 +123,8 @@ public function unreactTo(

public function hasReactedTo(
ReactantInterface $reactant,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
if ($reactant->isNull()) {
return false;
Expand All @@ -135,8 +135,8 @@ public function hasReactedTo(

public function hasNotReactedTo(
ReactantInterface $reactant,
?ReactionTypeInterface $reactionType = null,
?float $rate = null,
ReactionTypeInterface | null $reactionType = null,
float | null $rate = null,
): bool {
return $reactant->isNotReactedBy($this, $reactionType, $rate);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public function isNotNull(): bool
private function createReaction(
ReactantInterface $reactant,
ReactionTypeInterface $reactionType,
?float $rate = null,
float | null $rate = null,
): void {
$this->reactions()->create([
'reaction_type_id' => $reactionType->getId(),
Expand All @@ -184,7 +184,7 @@ private function createReaction(
private function findReaction(
ReactantInterface $reactant,
ReactionTypeInterface $reactionType,
): ?ReactionInterface {
): ReactionInterface | null {
return $this
->reactions()
->where('reactant_id', $reactant->getId())
Expand Down
6 changes: 3 additions & 3 deletions src/Reacterable/ReacterableEloquentBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait ReacterableEloquentBuilderTrait
{
public function whereReactedTo(
ReactableInterface $reactable,
?string $reactionTypeName = null,
string | null $reactionTypeName = null,
): Builder {
return $this->whereHas(
'loveReacter.reactions',
Expand All @@ -51,7 +51,7 @@ function (Builder $reactionsQuery) use (

public function whereNotReactedTo(
ReactableInterface $reactable,
?string $reactionTypeName = null,
string | null $reactionTypeName = null,
): Builder {
return $this->whereDoesntHave(
'loveReacter.reactions',
Expand All @@ -78,7 +78,7 @@ public function whereReactedToBetween(
ReactableInterface $reactable,
DateTimeInterface $reactedAtFrom,
DateTimeInterface $reactedAtTo,
?string $reactionTypeName = null,
string | null $reactionTypeName = null,
): Builder {
return $this->whereHas(
'loveReacter.reactions',
Expand Down
2 changes: 1 addition & 1 deletion src/Reaction/Models/Reaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getWeight(): float
}

public function setRateAttribute(
?float $rate,
float | null $rate,
): void {
if ($rate !== null && ($rate < self::RATE_MIN || $rate > self::RATE_MAX)) {
throw RateOutOfRange::withValueBetween($rate, self::RATE_MIN, self::RATE_MAX);
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class Model extends IlluminateModel
/**
* Get the current connection name for the model.
*/
public function getConnectionName(): ?string
public function getConnectionName(): string | null
{
return Config::get('love.storage.database.connection');
}
Expand Down
Loading