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 larastan on level 2 #547

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Fix larastan on level 2 #547

wants to merge 10 commits into from

Conversation

alaincodes24
Copy link
Contributor

@alaincodes24 alaincodes24 commented Mar 9, 2025

This PR addresses the listed errors of composer run larastan

closes #411

Please confirm you have completed any of the necessary steps below.

  • Meaningful Pull Request title and description
  • Changes tested as described above
  • Added appropriate documentation for the change.
  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@alaincodes24 alaincodes24 requested a review from musayann March 9, 2025 21:36
@alaincodes24 alaincodes24 self-assigned this Mar 9, 2025
@alaincodes24 alaincodes24 marked this pull request as ready for review March 11, 2025 20:20
Copy link
Member

@dmohns dmohns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @alaincodes24

Thank you very much, looks really good. I have left a few comments in the code.

I have a more general request (which is a little hard to explain, but let me try):
In this PR I would like us to not change any of the application logic. In particular, I see you are adding few relations here and there. I assume this is required because some pieces of the code are seemingly using these relations.

However, could we instead change the pieces of code that are using wrong references instead? I understand that some relations are waaaay to complicated (for example the whole Address<>GeographicalInformation block). If you notice some of these which could be improved, could you document your finding by creating an improvement ticket on Github?

So, in short, could you try to make it run on Larastan Level 2 without adding any relations?

->allOnConnection('redis')
->onQueue(config('services.queues.payment'));
} else {
// TODO: LOG ERROR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a ToDo for this PR or later?

@@ -86,4 +87,8 @@ public function findBySerialNumber(string $meterSerialNumber): ?self {
public function getId(): int {
return $this->id;
}

public function geo(): MorphOne {
return $this->morphOne(GeographicalInformation::class, 'owner');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Meter is directly related to GeoGraphicalInformation. Instead it's Address<>Device<>Meter

@@ -125,4 +126,8 @@ public function livingInClusterQuery(int $clusterId) {
public function getId(): int {
return $this->id;
}

public function meters() {
return $this->hasMany(Meter::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relation here is Person<>Device<>Meter

@@ -145,4 +153,8 @@ public function originalCash(): BelongsToMorph {
public function originalWaveMoney(): BelongsToMorph {
return BelongsToMorph::build($this, WaveMoneyTransaction::class, 'originalTransaction');
}

public function meter() {
return $this->belongsTo(Meter::class, 'message', 'serial_number');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relation here is Transaction<>Device<>Meter

Comment on lines 61 to 76
public function manufacturer(): BelongsTo {
return $this->belongsTo(Manufacturer::class);
}

public function getManufacturerAttribute() {
return $this->manufacturer->name ?? 'Unknown Manufacturer'; // Adjust as needed
}

public function connectionType(): BelongsTo {
return $this->belongsTo(ConnectionType::class);
}

public function connectionGroup(): BelongsTo {
return $this->belongsTo(ConnectionGroup::class);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these seem like relations that should be in the underlying device implementation. For example connectionType only makes sense for Meter but not for SHS. So, it shouldn't be on Device.

@alaincodes24 alaincodes24 requested a review from dmohns March 14, 2025 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix larastan on level 2
2 participants