microsoftgraph / microsoftgraph/msgraph-sdk-php

Model inheritance issues

Offen
#848 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

enhancement
Vorherrschende Sprache
PHP
Sterne
669
Forks
150
Ø Merge
15 Std. 21 Min.
Gemergte PRs (30 T.)
3

Beschreibung

There is a problem when using using method chaining on models that is caused by using class inheritance. The methods of each classes 'set' methods return $this which is great for chaining if the class in question is a final class, however for inherited classes $this relates to to the class the method exists in and not the actual class instantiated.

If you take the Message model for example, this inherits from OutlookItem, which in turn inherits from Entity. Calling getId() on a Message object returns an Entity object because that's where the getId() method is defined. If you create a chained process like this:

$message = (new Message()) ->setId($id) ->setCategories('fred') ->setBody('1234');
While this will actually work when run, if you use PHPStan you will get errors. In this instance you can't call setCategories() on an Entity object which is what is returned by the setId() method.

I would like to propose the use of traits to define the methods of each model that is currently inheritable. The model classes would then be a none inherited object but use the traits, which define the methods for that model, instead of inheritance. This would create model objects that truly expose each method of every trait providing the methods return 'self'.

Currently you can overcome the PHPStan issues by careful arrangement of chained methods making sure that you call the final class methods first, then each child in turn. This is not ideal but it is a work around until something is changed to improve coding standards.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die im Issue beschriebenen Methoden der Modelle Message, OutlookItem und Entity zu überprüfen, und reproduziere anschließend die verketteten Aufrufe mit PHPStan. Lege den Umfang der Vererbungsänderung fest und bestätige, dass die Verkettung den konkreten Modelltyp ohne die gemeldeten PHPStan-Fehler beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
backend-api-design
Issue-Typ
Refactoring
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.