PHP - Refactorizar código

 
Vista:

Refactorizar código

Publicado por Diego Forero (27 intervenciones) el 06/12/2019 22:22:29
Hola amigos de php, alguno me podria indicar una forma de optimizar este codigo..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
if($horasMain_en == '07'){
    if($minutosMain_en >= '30' && $minutosMain_en <= '59' ){
        if($horasMain_off1 == '11' && $minutosMain_off1 < '55') {
          $totalh = '3';
          $hod = '3';
          $hedo = '0';
          //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
          $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
          array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '11' && $minutosMain_off1 >= '55') {
            $totalh = '4';
            $hod = '3';
            $hedo = '1';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif($horasMain_off1 == '12' && $minutosMain_off < '55' ){
            $totalh = '4';
            $hod = '3';
            $hedo = '1';
            //echo 'HORARIO B y ADMIN EL TRABAJADOR '.$nombre.' | '.$cedula.' | EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIRUNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '12' && $minutosMain_off1 >= '55') {
            $totalh = '5';
            $hod = '3';
            $hedo = '2';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '13' && $minutosMain_off1 < '55') {
            $totalh = '5';
            $hod = '3';
            $hedo = '2';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '13' && $minutosMain_off1 >= '55') {
            $totalh = '6';
            $hod = '3';
            $hedo = '3';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '14' && $minutosMain_off1 < '55') {
            $totalh = '6';
            $hod = '3';
            $hedo = '3';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '14' && $minutosMain_off1 >= '55') {
            $totalh = '7';
            $hod = '3';
            $hedo = '4';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '15' && $minutosMain_off1 < '55') {
            $totalh = '7';
            $hod = '3';
            $hedo = '4';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '15' && $minutosMain_off1 >= '55') {
            $totalh = '8';
            $hod = '3';
            $hedo = '5';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '17' && $minutosMain_off1 < '55') {
            $totalh = '9';
            $hod = '8';
            $hedo = '0';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '17' && $minutosMain_off1 >= '55') {
            $totalh = '10';
            $hod = '8';
            $hedo = '1';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '18' && $minutosMain_off1 < '55') {
            $totalh = '10';
            $hod = '8';
            $hedo = '1';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '18' && $minutosMain_off1 >= '55') {
            $totalh = '11';
            $hod = '8';
            $hedo = '1';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '19' && $minutosMain_off1 < '55') {
            $totalh = '11';
            $hod = '8';
            $hedo = '2';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR '.$nombre.' | '.$cedula.' | EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '19' && $minutosMain_off1 >= '55') {
            $totalh = '12';
            $hod = '8';
            $hedo = '2';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR '.$nombre.' | '.$cedula.' | EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '20' && $minutosMain_off1 < '55') {
            $totalh = '12';
            $hod = '8';
            $hedo = '3';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR '.$nombre.' | '.$cedula.' | EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br>';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '20' && $minutosMain_off1 >= '55') {
            $totalh = '13';
            $hod = '8';
            $hedo = '3';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR '.$nombre.' | '.$cedula.' | EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br> ';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '21' && $minutosMain_off1 < '55') {
            $totalh = '13';
            $hod = '8';
            $hedo = '4';
            //echo 'HORARIO B Y ADMIN EL TRABAJADOR '.$nombre.' | '.$cedula.' | EL '.$dia.' ' .$solofecha. ' LABORO '. $hod. ' HORAS ORDINARIAS Y '.$hedo.' HORAS EXTRAS DIURNAS <br> ';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, '0', $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '21' && $minutosMain_off1 >= '55') {
            $totalh = '14';
            $hod = '8';
            $hedo = '3';
            $heno ='1';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo,$heno, $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '22' && $minutosMain_off1 < '55') {
            $totalh = '14';
            $hod = '8';
            $hedo = '3';
            $heno = '1';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, $heno, $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '22' && $minutosMain_off1 >= '55') {
            $totalh = '15';
            $hod = '8';
            $hedo = '3';
            $heno = '2';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, $heno, $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '23' && $minutosMain_off1 < '55') {
            $totalh = '15';
            $hod = '8';
            $hedo = '3';
            $heno = '2';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, $heno, $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '23' && $minutosMain_off1 >= '55') {
            $totalh = '16';
            $hod = '8';
            $hedo = '3';
            $heno = '3';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, $heno, $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }elseif ($horasMain_off1 == '24' && $minutosMain_off1 <= '59') {
            $totalh = '16';
            $hod = '8';
            $hedo = '3';
            $heno = '3';
            $respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, $heno, $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
            array_push($arrayususuariosfinal,$respon);
        }
    }
 
}

corresponde a una hora dependiente de la hora de ingreso y salida crea unas varibales de horas extras, pero tengo muchos if como esos para cada hora de ingreso, alguno me podria indicar una forma de optimizar ese código..

de antemano muchas gracias..

Cordialmente,

Diego Forero
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro
Val: 1.634
Plata
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Refactorizar código

Publicado por Alejandro (840 intervenciones) el 07/12/2019 16:28:03
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Pues así, sin entender como se deciden esos valores, puede ser algo como esto:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$configuraciones = array(
	11 => {
		'menor' => {'totalh'=> '3', 'hod'=>'3', 'hedo'=>'0', 'heno'=>'0'},
		'mayor' => {'totalh'=> '4', 'hod'=>'3', 'hedo'=>'1', 'heno'=>'0'}
	},
	12 => {
		'menor' => {'totalh'=> '4', 'hod'=>'3', 'hedo'=>'1', 'heno'=>'0'},
		'mayor' => {'totalh'=> '5', 'hod'=>'3', 'hedo'=>'2', 'heno'=>'0'}
	},
	13 => {
		'menor' => {'totalh'=> '5', 'hod'=>'3', 'hedo'=>'2', 'heno'=>'0'},
		'mayor' => {'totalh'=> '6', 'hod'=>'3', 'hedo'=>'3', 'heno'=>'0'}
	},
	14 => {
		'menor' => {'totalh'=> '6', 'hod'=>'3', 'hedo'=>'3', 'heno'=>'0'},
		'mayor' => {'totalh'=> '7', 'hod'=>'3', 'hedo'=>'4', 'heno'=>'0'}
	},
	15 => {
		'menor' => {'totalh'=> '7', 'hod'=>'3', 'hedo'=>'4', 'heno'=>'0'},
		'mayor' => {'totalh'=> '8', 'hod'=>'3', 'hedo'=>'5', 'heno'=>'0'}
	},
	16 => {
		'menor' => {'totalh'=>  '', 'hod'=> '', 'hedo'=> '', 'heno'=> ''},
		'mayor' => {'totalh'=>  '', 'hod'=> '', 'hedo'=> '', 'heno'=> ''}
	},
	17 => {
		'menor' => {'totalh'=> '9', 'hod'=>'8', 'hedo'=>'0', 'heno'=>'0'},
		'mayor' => {'totalh'=>'10', 'hod'=>'8', 'hedo'=>'1', 'heno'=>'0'}
	},
	18 => {
		'menor' => {'totalh'=>'10', 'hod'=>'8', 'hedo'=>'1', 'heno'=>'0'},
		'mayor' => {'totalh'=>'11', 'hod'=>'8', 'hedo'=>'1', 'heno'=>'0'}
	},
	19 => {
		'menor' => {'totalh'=>'11', 'hod'=>'8', 'hedo'=>'2', 'heno'=>'0'},
		'mayor' => {'totalh'=>'12', 'hod'=>'8', 'hedo'=>'2', 'heno'=>'0'}
	},
	20 => {
		'menor' => {'totalh'=>'12', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'0'},
		'mayor' => {'totalh'=>'13', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'0'}
	},
	21 => {
		'menor' => {'totalh'=>'13', 'hod'=>'8', 'hedo'=>'4', 'heno'=>'0'},
		'mayor' => {'totalh'=>'14', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'1'}
	},
	22 => {
		'menor' => {'totalh'=>'14', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'1'},
		'mayor' => {'totalh'=>'15', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'2'}
	},
	23 = >{
		'menor' => {'totalh'=>'15', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'2'},
		'mayor' => {'totalh'=>'16', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'3'}
	},
	24 = >{
		'menor' => {'totalh'=>'16', 'hod'=>'8', 'hedo'=>'3', 'heno'=>'3'},
		'mayor' => {'totalh'=>  '', 'hod'=> '', 'hedo'=> '', 'heno'=> ''}
	},
);
if($horasMain_en == '07'){
	if($minutosMain_en >= '30' && $minutosMain_en <= '59' ){
		if ($horasMain_off1=='24') {
			$rango = ($minutosMain_off1<='59')?'menor':'mayor';
		} else {
			$rango = ($minutosMain_off1<'55')?'menor':'mayor';
		}
		$configuracion = $configuraciones[$horasMain_off1][$rango];
		$totalh = $configuracion['totalh'];
		$hod    = $configuracion['hod'];
		$hedo   = $configuracion['hedo'];
		$heno   = $configuracion['heno'];
 
		$respon = ArrayUsersFinal($nombre, $cedula, $hod, $hedo, $heno, $solofecha, $dia, $festivo, $horasMain_entry, $horasMain_off, $exitlunch, $enterlunch, $tienda, $totalh);
		array_push($arrayususuariosfinal,$respon);
	}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar