frank
Goto Top

Wieviel Zeilen Quellcode hat mein PHP-Projekt?

Hallo Entwickler,

wer hat sich nicht schon oft gefragt, wieviele Zeilen Quellecode sein eigenes PHP-Projekt eigentlich hat? Ich wollte das für die Administrator-Seite einmal genau wissen und haben nach einem Programm gesucht, dass diese Aufgabe für mich bequem erledigt. Gefunden habe ich das PHP-Tool phploc von Sebastian Bergmann. Das Tool liest die Quellcode-Dateien ein und zählt die Zeilen. Dabei unterscheidet es sogar zwischen Kommentaren und richtigem Code, zählt Interfaces, Klassen, nicht- und statische Methoden und die Funktionen.

Man installiert das Tool phploc über den PEAR-Installer.
pear channel-discover pear.phpunit.de.
pear install phpunit/phploc.
Dabei ist zu beachten, das die PHP Erweiterung "tokenizer" im PHP-Binary vorhanden ist.

Update 17.04.2015: Die Installation über den PEAR-Installer funktioniert nicht mehr!

Stattdessen sollte man folgenden Weg gehen (hier die Installation als root-User):
wget https://phar.phpunit.de/phploc.phar
chmod +x phploc.phar
mv phploc.phar /usr/local/bin/phploc
Danach kann man das Tool mit folgendem Befehl aufrufen:
phploc VERZEICHNIS

Als Beispiel habe ich mal: "phploc /var/www/administrator/" aufgerufen (dort liegt mein Quellcode).
# phploc /var/www/administrator/

Directories:                                         52
Files:                                              482

Lines of Code (LOC):                              76590
Comment Lines of Code (CLOC):                     20543
Non-Comment Lines of Code (NCLOC):                56047

etc..

Die Administrator-Seiten bestehen also aktuell aus 76.590 Zeilen, wovon 56.047 Zeilen Quellcode und 20.543 Zeilen Kommentare sind (habs wohl ganz gut dokumentiert).
Fein face-wink

Gruß
Frank

Content-Key: 134042

Url: https://administrator.de/contentid/134042

Printed on: May 5, 2024 at 03:05 o'clock

Member: dog
dog Jan 21, 2010 at 13:49:59 (UTC)
Goto Top
Viel lustiger ist aber noch sloccount, das produziert auch gleich noch absurd hohe Entwicklungskosten face-wink

Und wer ganz faul ist benutzt:
wc -l *.php
Member: Frank
Frank Jan 21, 2010 at 14:26:08 (UTC)
Goto Top
Hi,

und noch ein kleines Tool zum Thema von Sebastian Bergmann: phpcpd.
Es findet sehr schnell doppelte Zeilen (z.b. per Copy&Paste eingefügt) im PHP-Quellcode.

Installation:
pear install phpunit/phpcpd
Aufruf:
phpcpd VERZEICHNIS

Gruß
Frank
Member: Frank
Frank Apr 17, 2015 updated at 13:18:28 (UTC)
Goto Top
Update: Die Installation über den PEAR-Installer funktioniert nicht mehr! Stattdessen sollte man folgenden Weg gehen (hier die Installation als root-User):

wget https://phar.phpunit.de/phploc.phar
chmod +x phploc.phar
mv phploc.phar /usr/local/bin/phploc

Danach kann man es einfach per "phploc Verzeichnisname" aufrufen:
# phploc
phploc 2.1.1 by Sebastian Bergmann.

Usage:
 phploc [--names="..."] [--names-exclude="..."] [--count-tests] [--git-repository="..."] [--exclude="..."] [--log-c
sv="..."] [--log-xml="..."] [--progress] [values1] ... [valuesN]

Arguments:
 values

Options:
 --names               A comma-separated list of file names to check (default: ["*.php"])
 --names-exclude       A comma-separated list of file names to exclude
 --count-tests         Count PHPUnit test case classes and test methods
 --git-repository      Collect metrics over the history of a Git repository
 --exclude             Exclude a directory from code analysis (multiple values allowed)
 --log-csv             Write result in CSV format to file
 --log-xml             Write result in XML format to file
 --progress            Show progress bar
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for
 debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question

Alle weiteren Informationen dazu erhaltet ihr auf der Seite von Sebastian Bergmann

Anbei ein Update unserer Codezeilen vom 17.04.2015:

Lines of Code (LOC)                            82101
Comment Lines of Code (CLOC)                   15375 (18.73%)
Non-Comment Lines of Code (NCLOC)              66726 (81.27%)