microsoftgraph / microsoftgraph/msgraph-sdk-php

Model inheritance issues

Abierto
#848 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement
Lenguaje dominante
PHP
Estrellas
669
Forks
150
Merge medio
15 h 21 min
PR fusionados (30 d)
3

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza revisando los métodos de los modelos Message, OutlookItem y Entity descritos en el issue y, después, reproduce las llamadas encadenadas con PHPStan. Define el alcance del cambio de herencia y confirma que el encadenamiento conserva el tipo concreto del modelo sin los errores de PHPStan indicados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
php
Área
backend-api-design
Tipo de issue
Refactorización
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.