Conditions | 12 |
Paths | 18 |
Total Lines | 69 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
54 | public function getCheckModuleVersion() { |
||
55 | $dbc = App::getDb(); |
||
56 | $today = date("Y-m-d"); |
||
57 | $today_o = new \DateTime($today); |
||
58 | |||
59 | $query = $dbc->query("SELECT next_check_version, version, url_telechargement, mettre_jour, delete_old_version, ID_module FROM module"); |
||
60 | |||
61 | if ((is_array($query)) && (count($query) > 0)) { |
||
62 | foreach ($query as $obj) { |
||
63 | if ($obj->next_check_version == null) { |
||
64 | //si pas de version a checker, cela veut dire qu'on vient d'installer le module |
||
65 | //du coup on met le next_check aa la semaine pro |
||
66 | $set_next = true; |
||
67 | } |
||
68 | else if (($obj->next_check_version <= $today) && ($obj->mettre_jour != 1)) { |
||
69 | //avant tout on regarde si on doit delete une vieille version |
||
70 | if ($obj->delete_old_version == 1) { |
||
71 | $import = new ImportModule(); |
||
72 | $import->setSupprimerOldModule($obj->ID_module); |
||
73 | } |
||
74 | |||
75 | //on recupere le nom du dossier + extention |
||
76 | $explode = explode(".", $obj->url_telechargement); |
||
77 | array_pop($explode); |
||
78 | |||
79 | $version_txt = implode(".", $explode)."_version.txt"; |
||
80 | |||
81 | if (file_get_contents($version_txt) !== "") { |
||
82 | |||
83 | //online pour bdd |
||
84 | $version_online_txt = file_get_contents($version_txt); |
||
85 | |||
86 | $version_online = floatval($version_online_txt); |
||
87 | $version_site = floatval($obj->version); |
||
88 | |||
89 | //la version sur le serveur de telechargement est plus récente, on va donc proposer |
||
90 | //en passant la valeur update a 1 dans la table module pour ce module |
||
91 | // au client de mettre a jour sa version sinon on met la next check a la semaine pro |
||
92 | if ($version_online > $version_site) { |
||
93 | $value = [ |
||
94 | "update" => 1, |
||
95 | "online_version" => $version_online_txt, |
||
96 | "id_module" => $obj->ID_module |
||
97 | ]; |
||
98 | |||
99 | //on met la notification admin à 1 |
||
100 | $dbc->query("UPDATE notification SET admin=1 WHERE ID_notification=1"); |
||
101 | |||
102 | $dbc->prepare("UPDATE module SET mettre_jour=:update, online_version=:online_version WHERE ID_module=:id_module", $value); |
||
103 | |||
104 | $set_next = true; |
||
105 | } |
||
106 | else { |
||
107 | $set_next = true; |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | if ((isset($set_next)) && ($set_next === true)) { |
||
113 | $value = [ |
||
114 | "next_check" => $today_o->add(new \DateInterval("P1W"))->format("Y-m-d"), |
||
115 | "id_module" => $obj->ID_module |
||
116 | ]; |
||
117 | |||
118 | $dbc->prepare("UPDATE module SET next_check_version=:next_check WHERE ID_module=:id_module", $value); |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
132 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: