Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
README.md
ejemplo.txt
halstead.php
operadores.txt
operadores_php.txt

README.md

Desafío Enero 2013: Las métricas de Halstead - Actualizado Jueves 14 de Febrero

Este programa en PHP calcula las métricas de Halstead, dados un código fuente y sus operadores. Más información sobre el problema en el siguiente link:

Desafío Enero 2013: Las métricas de Halstead

Actualización: se modificó la lista de operadores y también el código en función de los nuevos detalles entregados sobre el problema.

Resultados

Código de ejemplo provisto en el problema:

$ php halstead.php operadores.txt ejemplo.txt

 n1 = 4 (if, <=, then, else)
 N1 = 4 (if, <=, then, else)
 n2 = 7 ("ingrese un valor:", "ganaste", "perdiste", input, a, 100, print)
 N2 = 9 ("ingrese un valor:", "ganaste", "perdiste", input, a, a, 100, print, print)

 N = 13
 n = 11
 V = 44.972611042285
 L = 0.38888888888889
 D = 2.5714285714286
 E = 115.64385696588
 T = 6.4246587203264

Este mismo código:

$ php halstead.php operadores.txt halstead.php

 n1 = 6 (=, +, *, <, $, /)
 N1 = 50 (=, =, =, =, =, =, +, =, *, =, =, +, =, *, =, *, =, <, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, /, $, /, $, /, $, /, $, $, $, $, $)
 n2 = 51 ('/\\S+/', '$matches', 'global $arrN2, $arrn2; $matches[0] = $arrN2[] = $matches[0]; $arrn2[$matches[0]] = $matches[0]; return " ";', '/[\<\=\>\+\*\-\~\^\&\|\!\@\#\$\%\/]/', 'global $arrN1, $arrn1; $arrN1[] = trim($matches[0]); $arrn1[trim($matches[0])] = trim($matches[0]); return " ";', '(\s', '\s|\s', 'preg_quote', '\s)', '/[\.\,\:\;\(\)\[\]\{\}]/', 'return " ";', '/([^"\\\\])("([^"\\\\]|\\\\.)*")|([^\'\\\\])(\'([^\'\\\\]|\\\\.)*\')/', 'global $arrN2, $arrn2; $matches = array_values(array_filter($matches)); $arrN2[] = $matches[2]; $arrn2[$matches[2]] = $matches[2]; return $matches[1];', ' ', " n1 = $n1 (", ', ', ")\n N1 = $N1 (", ")\n n2 = $n2 (", ")\n N2 = $N2 (", ")\n\n N = $N\n n = $n\n V = $V\n L = $L\n D = $D\n E = $E\n T = $T\n", ?php, op, file, argv, 1, FILE_IGNORE_NEW_LINES, arsort, preg_replace_callback, create_function, implode, array_map, 2, T, E, V, N, N1, sizeof, arrN1, N2, arrN2, log, n, n1, arrn1, n2, arrn2, D, 18, L, echo)
 N2 = 90 ('/\\S+/', '$matches', 'global $arrN2, $arrn2; $matches[0] = $arrN2[] = $matches[0]; $arrn2[$matches[0]] = $matches[0]; return " ";', '/[\<\=\>\+\*\-\~\^\&\|\!\@\#\$\%\/]/', '$matches', 'global $arrN1, $arrn1; $arrN1[] = trim($matches[0]); $arrn1[trim($matches[0])] = trim($matches[0]); return " ";', '(\s', '\s|\s', 'preg_quote', '\s)', '$matches', 'global $arrN1, $arrn1; $arrN1[] = trim($matches[0]); $arrn1[trim($matches[0])] = trim($matches[0]); return " ";', '/[\.\,\:\;\(\)\[\]\{\}]/', '$matches', 'return " ";', '/([^"\\\\])("([^"\\\\]|\\\\.)*")|([^\'\\\\])(\'([^\'\\\\]|\\\\.)*\')/', '$matches', 'global $arrN2, $arrn2; $matches = array_values(array_filter($matches)); $arrN2[] = $matches[2]; $arrn2[$matches[2]] = $matches[2]; return $matches[1];', ' ', " n1 = $n1 (", ', ', ")\n N1 = $N1 (", ', ', ")\n n2 = $n2 (", ', ', ")\n N2 = $N2 (", ', ', ")\n\n N = $N\n n = $n\n V = $V\n L = $L\n D = $D\n E = $E\n T = $T\n", ?php, op, file, argv, 1, FILE_IGNORE_NEW_LINES, arsort, op, preg_replace_callback, create_function, preg_replace_callback, create_function, preg_replace_callback, implode, array_map, op, create_function, preg_replace_callback, create_function, preg_replace_callback, create_function, implode, file, argv, 2, T, E, V, N, N1, sizeof, arrN1, N2, sizeof, arrN2, log, n, n1, sizeof, arrn1, n2, sizeof, arrn2, 2, D, n1, 2, N2, n2, 18, L, 1, D, echo, implode, arrn1, implode, arrN1, implode, arrn2, implode, arrN2)

 N = 140
 n = 57
 V = 816.60460198306
 L = 0.18888888888889
 D = 5.2941176470588
 E = 4323.200834028
 T = 240.17782411267