Salut,
Je m'essaye depuis quelque temps à la poo... Et c'est pas simple, donc, je me suis dit, ok, pourquoi ne pas trouver des scripts simples et essayer de comprendre leur fonctionnement...
Source de mon interrogation : https://github.com/Chovanec/elo-rating/blob/master/src/Rating/Rating.php
Extrait des 2 fonctions qui m’interpellent...
Pourquoi ne pas faire la fonction setNewSettings ainsi :
Et pourquoi ne pas l'intégrer directement dans la fonction de construction ainsi :
Merci pour vos explications.
 
      
      
    Je m'essaye depuis quelque temps à la poo... Et c'est pas simple, donc, je me suis dit, ok, pourquoi ne pas trouver des scripts simples et essayer de comprendre leur fonctionnement...
Source de mon interrogation : https://github.com/Chovanec/elo-rating/blob/master/src/Rating/Rating.php
Extrait des 2 fonctions qui m’interpellent...
public function  __construct($ratingA,$ratingB,$scoreA,$scoreB)
    {
        $this->setNewSettings($ratingA, $ratingB, $scoreA, $scoreB);
    }
public function setNewSettings($ratingA,$ratingB,$scoreA,$scoreB)
    {
        $this -> _ratingA = $ratingA;
        $this -> _ratingB = $ratingB;
        $this -> _scoreA = $scoreA;
        $this -> _scoreB = $scoreB;
        $expectedScores = $this -> _getExpectedScores($this -> _ratingA,$this -> _ratingB);
        $this -> _expectedA = $expectedScores['a'];
        $this -> _expectedB = $expectedScores['b'];
        $newRatings = $this ->_getNewRatings($this -> _ratingA, $this -> _ratingB, $this -> _expectedA, $this -> _expectedB, $this -> _scoreA, $this -> _scoreB);
        $this -> _newRatingA = $newRatings['a'];
        $this -> _newRatingB = $newRatings['b'];
        return $this;
    }
Pourquoi ne pas faire la fonction setNewSettings ainsi :
public function setNewSettings($ratingA,$ratingB,$scoreA,$scoreB)
    {
	$expectedScores = $this -> _getExpectedScores($ratingA,$ratingB);
	$newRatings = $this ->_getNewRatings($ratingA, $ratingB, $expectedScores['a'], $expectedScores['b'], $scoreA, $scoreB);
	$this -> _newRatingA = $newRatings['a'];
	$this -> _newRatingB = $newRatings['b'];
	return $this;
    }
Et pourquoi ne pas l'intégrer directement dans la fonction de construction ainsi :
public function  __construct($ratingA,$ratingB,$scoreA,$scoreB)
	{
		$expectedScores = $this -> _getExpectedScores($ratingA,$ratingB);
		$newRatings = $this ->_getNewRatings($ratingA, $ratingB, $expectedScores['a'], $expectedScores['b'], $scoreA, $scoreB);
		$this -> _newRatingA = $newRatings['a'];
		$this -> _newRatingB = $newRatings['b'];
		return $this;
	}
Merci pour vos explications.