vendredi 13 novembre 2020

How to put my functions outside a class to get organized, Design pattern

I'm using Symfony 4, I have a class named Fiche, it contains the attributes and by default the getters and setters functions of course.

Inside this Class, I have created over than 107 others functions to make calculations an then create the lines (over 40) of the pay slip of an employee and to get gross salary and net salary.

The Fiche class becomes very big and it's no more organized, so how can I put each collection of functions in others classes and when I render the Fiche object inside twig I can access to those function ?

This is part of my class :

class Fiche
{

 // attributes 
 // ............

 public function calculTotalSalaireBrut()

 final public function netAPayer()

 public function calculPrimesDiverses()

 public function statutSalarie()

 final public function calculTauxSalaireMensuel()

 final public function calculTauxSalHeuresSupp()

 final public function calculMontantSalHeuresSupp()

 // over than 100 others functions 

}

In the controller:

/**
 * @Route("/voir/{token}", name="front_fiche_voir")
 * @Security("has_role('ROLE_ENTREPRISE')")
 */
public function show(Fiche $fiche)
{
    $this->denyAccessUnlessGranted('VIEW', $fiche);

    return $this->render('front/fiche/show.html.twig', array(
        'fiche' => $fiche,
    ));
}

a part of code inside twig template :

 <td class="td-right"></td>
 <td class="td-right"></td>
 <td class="td-right"></td>

How can I organize my class ? How tcan I put each collection of functions in others classes and have the possibility to access to them via the Object, either in PHP or in twig

Aucun commentaire:

Enregistrer un commentaire