Complex classes like DroitAcces often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DroitAcces, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
6 | class DroitAcces { |
||
7 | private $logged; |
||
8 | |||
9 | //pour la table identite |
||
10 | private $id_identite; |
||
11 | private $super_admin; |
||
12 | |||
13 | //pour la table liste_droit_acces |
||
14 | private $id_liste_droit_acces; |
||
15 | |||
16 | //pour des droits pour la gestion des contenus |
||
17 | private $modif_seo; |
||
18 | private $modif_contenu; |
||
19 | private $modif_navigation; |
||
20 | private $supprimer_page; |
||
21 | |||
22 | |||
23 | //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------// |
||
24 | public function __construct() { |
||
45 | //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------// |
||
46 | |||
47 | |||
48 | |||
49 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
50 | public function getLogged(){ |
||
71 | |||
72 | /** |
||
73 | * @return array |
||
74 | */ |
||
75 | private function getListeDroitAcces() { |
||
92 | |||
93 | //autres getter |
||
94 | /** |
||
95 | * pour savoir si en fonction des droits d'accès de l'utilisateur il peu ou non accéder à cete page |
||
96 | * on passe outre les test si on est super admin |
||
97 | * @param string $page |
||
98 | * @return bool |
||
99 | */ |
||
100 | public function getDroitAccesPage($page) { |
||
127 | |||
128 | /** |
||
129 | * fonction qui permet de gérer les droits d'accès sur les contenus : |
||
130 | * - creer une page |
||
131 | * - modifier du contenu (SEO, navigation, contenu) |
||
132 | * - supprimer une page |
||
133 | * si on est super admin on passe outre tous les tests |
||
134 | * @param $droit |
||
135 | * @param $id_page |
||
136 | * @return bool|null |
||
137 | */ |
||
138 | public function getDroitAccesContenu($droit, $id_page) { |
||
187 | |||
188 | /** |
||
189 | * pour savoir si un utilisateur à le droit de supprimer, modifier ou ajouter des trucs |
||
190 | * @param $droit_acces |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function getDroitAccesAction($droit_acces) { |
||
208 | //-------------------------- FIN GETTER ----------------------------------------------------------------------------// |
||
209 | |||
210 | |||
211 | |||
212 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
213 | |||
214 | //-------------------------- FIN SETTER ----------------------------------------------------------------------------// |
||
215 | } |