A tool for quickly measuring the size of a PHP project.

Related tags

Code Analysis phploc
Overview

PHPLOC

phploc is a tool for quickly measuring the size and analyzing the structure of a PHP project.

Installation

This tool is distributed as a PHP Archive (PHAR):

$ wget https://phar.phpunit.de/phploc.phar

$ php phploc.phar --version

Using Phive is the recommended way for managing the tool dependencies of your project:

$ phive install phploc

$ ./tools/phploc --version

It is not recommended to use Composer to download and install this tool.

Usage Examples

Analyse a directory and print the result

$ php phploc.phar src
phploc 7.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code (LOC)                             1882
  Comment Lines of Code (CLOC)                     255 (13.55%)
  Non-Comment Lines of Code (NCLOC)               1627 (86.45%)
  Logical Lines of Code (LLOC)                     377 (20.03%)
    Classes                                        351 (93.10%)
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 (0.00%)
      Average Function Length                        0
    Not in classes or functions                     26 (6.90%)

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 (0.00%)
    Global Variables                                 0 (0.00%)
    Super-Global Variables                           0 (0.00%)
  Attribute Accesses                                85
    Non-Static                                      85 (100.00%)
    Static                                           0 (0.00%)
  Method Calls                                     280
    Non-Static                                     276 (98.57%)
    Static                                           4 (1.43%)

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 (0.00%)
    Concrete Classes                                 9 (100.00%)
  Methods                                          130
    Scope
      Non-Static Methods                           130 (100.00%)
      Static Methods                                 0 (0.00%)
    Visibility
      Public Methods                               103 (79.23%)
      Non-Public Methods                            27 (20.77%)
  Functions                                          0
    Named Functions                                  0 (0.00%)
    Anonymous Functions                              0 (0.00%)
  Constants                                          0
    Global Constants                                 0 (0.00%)
    Class Constants                                  0 (0.00%)
Comments
  • Improve composer.json dependencies

    Improve composer.json dependencies

    Depending on a tagged version of zetacomponents/console-tools allows installing phploc with a default stability of stable Also depend on stable versions of symfony/finder >= 2.1

    opened by tommygnr 14
  • Undefined index: ccn in phar:///usr/local/bin/phploc/src/Analyser.php on line 507

    Undefined index: ccn in phar:///usr/local/bin/phploc/src/Analyser.php on line 507

    I did some Faker test dev stuff and got a Notice when calling the file with phploc

    $ phploc Foo.php
    phploc 3.0.0 by Sebastian Bergmann.
    
    Notice: Undefined index: ccn in phar:///usr/local/bin/phploc/src/Analyser.php on line 507
    
    Call Stack:
        0.0012     249512   1. {main}() /usr/local/bin/phploc:0
        0.0102    1202360   2. Symfony\Component\Console\Application->run() /usr/local/bin/phploc:182
        0.0120    1573184   3. SebastianBergmann\PHPLOC\CLI\Application->doRun() phar:///usr/local/bin/phploc/symfony/console/Application.php:117
        0.0133    1574584   4. Symfony\Component\Console\Application->doRun() phar:///usr/local/bin/phploc/src/CLI/Application.php:98
        0.0133    1575552   5. Symfony\Component\Console\Application->doRunCommand() phar:///usr/local/bin/phploc/symfony/console/Application.php:186
        0.0134    1576096   6. Symfony\Component\Console\Command\Command->run() phar:///usr/local/bin/phploc/symfony/console/Application.php:787
        0.0136    1580032   7. SebastianBergmann\PHPLOC\CLI\Command->execute() phar:///usr/local/bin/phploc/symfony/console/Command/Command.php:256
        0.0136    1580584   8. SebastianBergmann\PHPLOC\CLI\Command->executeSingle() phar:///usr/local/bin/phploc/src/CLI/Command.php:109
        0.0136    1580872   9. SebastianBergmann\PHPLOC\CLI\Command->count() phar:///usr/local/bin/phploc/src/CLI/Command.php:129
        0.0164    1892168  10. SebastianBergmann\PHPLOC\Analyser->countFiles() phar:///usr/local/bin/phploc/src/CLI/Command.php:236
        0.0164    1894640  11. SebastianBergmann\PHPLOC\Analyser->countFile() phar:///usr/local/bin/phploc/src/Analyser.php:161
    

    File: https://github.com/alabama/Test/blob/master/Foo.php

    opened by alabama 13
  • Average-metrics missing in xml/csv result

    Average-metrics missing in xml/csv result

    It seems as if at least some "average" metrics are missing in phploc xml- or csv-result.

    I am using phploc 2.1.1. I pasted console-output, xml-output and csv-output on pastebin.

    As far as I can see

    • "Average Function Length" (from console) is missing in xml output.
    • "Average Class Length" and "Average Method Length" (from console) is missing in csv output.
    • "Average Complexity per LLOC", "Average Complexity per Class" and "Average Complexity per Method" seem to be missing both in xml- and csv-output.
    opened by SchulteMarkus 12
  • I found this error : Undefined index: ccn

    I found this error : Undefined index: ccn

    Version : phploc 3.0.0 by Sebastian Bergmann Complete message : PHP Notice: Undefined index: ccn in phar:///usr/local/bin/phploc/src/Analyser.php on line 507

    Code who generate this error :

    opened by webmailcontatos 11
  • Uninitialized string offset: 1 in PHPLOC/Analyser.php on line 602

    Uninitialized string offset: 1 in PHPLOC/Analyser.php on line 602

    When I run phploc against the vendor/ folder of symfony2 ( in wich I do have bundle that are not part of the standard edition ), I get about 10 PHP notice:

    Uninitialized string offset: 1 in PHPLOC/Analyser.php on line 602

    I've edited the PHPLOC/Analyser.php file to help debug the issue:

    protected function getClassName($namespace, array $tokens, $i)
    {
        $i         += 2;
        $namespaced = FALSE;
        if(!isset($tokens[$i][1])){
                var_dump($namespace, $i, $tokens[$i]);
        }
        $className  = $tokens[$i][1];
    

    And the output is: bool(false) int(51) string(1) "{"

    I've also done a debug_print_backtrace: #0 PHPLOC_Analyser->getClassName() #1 PHPLOC_Analyser->countFile() called at [/usr/local/Cellar/php/5.3.8/lib/php/PHPLOC/Analyser.php:170] #2 PHPLOC_Analyser->countFiles() called at [/usr/local/Cellar/php/5.3.8/lib/php/PHPLOC/TextUI/Command.php:220] #3 PHPLOC_TextUI_Command::main() called at [/usr/local/Cellar/php/5.3.8/bin/phploc:51]

    opened by FMaz008 11
  • "declare", "namespace", and "use" are not handled correctly

    "LLOC not in classes or functions" is including these things:

    • declare( strict_types = 1 );
    • namespace declaration
    • import statements

    When phploc reported 2000+ LLOC under "not in classes or functions" I was somewhat WTF. Strictly speaking it is not wrong I suppose, though it is making the distinction in a way that I unsuspected to me, and makes the metric kinda useless.

    bug 
    opened by JeroenDeDauw 10
  • Adding composer

    Adding composer

    Adding composer definition and a binary which includes composer autoloader fixes #24

    I could not user zetacomponents/console-toosl version 1.8 as it does not have the correct composer.json. I didn't try any version in between. Tests are passing and it works with my projects, so I guess it's ok.

    opened by Sgoettschkes 10
  • Notices

    Notices

    The tool emits notices, probably some missing defensive coding somewhere

    PHP Notice: Undefined offset: 7 in phar:///.../project/phploc.phar/src/Analyser.php on line 509

    opened by dereuromark 8
  • test class and method count not working

    test class and method count not working

    phploc --count-tests src test

    prints

    Tests
      Classes                                            0
      Methods                                            0
    

    even though test/Example/CalculatorTest.php contains

    <?php
    namespace Example;
    
    use Exception;
    use PHPUnit_Framework_TestCase;
    
    class CalculatorTest extends PHPUnit_Framework_Testcase
    {
        public function testAddPositiveNumbers()
        {
            $calc = new Calculator();
            $result = $calc->add(1, 2);
            $this->assertEquals(3, $result);
        }
    }
    
    opened by FunTimeCoding 8
  • Count only a bunch of folders or exclude some folder.

    Count only a bunch of folders or exclude some folder.

    Hey together,

    I'm working currently on a Laravel Project and would like to count my lines of code. I've already installed the phploc library and it's working almost perfect. I just struggle with excluding more than one folder or just count a specific folder structure.

    I would like to Exclude:

    • ./vendor
    • ./storage
    • ./ressources/assets
    • ./public
    • ./node_modules
    • ./bootstrap
    • ./app/Console

    I've already tried something like the following example but always get an unrealistic code back. ( Lines of Code (LOC) 3'112'657) I found another Mac Programm that counts just the specific lines from .php files in folders and I got back something like 6000 lines of code. This would be more realistic but i don't have the further information the phploc provides.

    First Try: vendor/bin/phploc --exclude ./vendor . --exclude ./storage . --exclude ./node_modules . --exclude ./bootstrap . --exclude ./app/Console . --exclude ./storage . --exclude ./resources/assets .

    Second Try: ./vendor . ./storage . ./ressources/assets . ./public . ./node_modules . ./bootstrap . ./app/Console .

    I would like to count only the structure as you can see it on the attached image. Do you may have any suggestions?

    Best regards Sebastian

    phploc

    wontfix 
    opened by StanBarrows 7
  • PHP  Undefined indexes when running ci

    PHP Undefined indexes when running ci

    phploc-ci: [exec] phploc 2.1.1 by Sebastian Bergmann.

    PHP Notice: Undefined index: lloc in ~/.composer/vendor/phploc/phploc/src/Analyser.php on line 304

    PHP Notice: Undefined index: ccn in ~/.composer/vendor/phploc/phploc/src/Analyser.php on line 315

    opened by pfwd 7
  • "No files found to scan" should exit 0

    When no files are found to scan, I'd prefer phploc to exit 0 instead of 1. It used to exit 0, and exiting 1 is a breaking change in the 7.0 release that should have been included in the release notes (introduced by https://github.com/sebastianbergmann/phploc/commit/438fda0e2a761805de84b9ad4c682f53c80ad03f)

    This appears to be a regression, since there's a specific issue from even earlier requesting that it exit 0 when there are no files to scan: https://github.com/sebastianbergmann/phploc/pull/175 This was merged, and then seemingly reverted in the 7.0 release.

    opened by danepowell 0
Owner
Sebastian Bergmann
Sebastian Bergmann is the creator of PHPUnit. He co-founded thePHP.cc and helps PHP teams build better software.
Sebastian Bergmann
PHP Architecture Tester - Easy to use architectural testing tool for PHP :heavy_check_mark:

Easy to use architecture testing tool for PHP Introduction ?? PHP Architecture Tester is a static analysis tool to verify architectural requirements.

Carlos A Sastre 765 Dec 30, 2022
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

null 11.6k Jan 3, 2023
PHP Static Analysis Tool - discover bugs in your code without running it!

PHPStan - PHP Static Analysis Tool PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even b

PHPStan 11.6k Dec 30, 2022
A PHP code-quality tool

GrumPHP Sick and tired of defending code quality over and over again? GrumPHP will do it for you! This composer plugin will register some git hooks in

PHPro 3.9k Jan 1, 2023
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Dec 22, 2022
A command line refactoring tool for PHP

PHP Refactoring Browser Note: This software is under development and in alpha state. Refactorings do not contain all necessary pre-conditions and migh

QafooLabs 562 Dec 30, 2022
A static php code analysis tool using the Graph Theory

Mondrian Ok guyz, you have a master degree in Graph Theory, you follow Law of Demeter and you live on S.O.L.I.D principles ? Let's have some Fun ! (^ω

Florent Genette 391 Nov 30, 2022
PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions.

PHPCheckstyle Overview PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the inpu

PHPCheckstyle 157 Dec 5, 2022
PHP completion, refactoring, introspection tool and language server.

Phpactor This project aims to provide heavy-lifting refactoring and introspection tools which can be used standalone or as the backend for a text edit

Phpactor 882 Jan 1, 2023
A static analysis tool for finding errors in PHP applications

Psalm Psalm is a static analysis tool for finding errors in PHP applications. Installation To get started, check out the installation guide. Live Demo

Vimeo 5k Jan 2, 2023
A web tool to explore the ASTs generated by PHP-Parser.

phpast.com A web tool to explore the ASTs generated by PHP-Parser. About This web tool provides a GUI for exploring the AST of your PHP code. You can

Ryan Chandler 23 Nov 29, 2022
Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.

QOSSMIC GmbH 2.2k Dec 30, 2022
A tool to automatically fix PHP Coding Standards issues by Dragon Code.

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

The Dragon Code 24 Aug 27, 2022
Tool helping us to analyze software projects

Qafoo Quality Analyzer This software is a tool to visualize metrics and source code. We use this software for Code Reviews together with our customers

Qafoo GmbH 494 Dec 29, 2022
Baseline tool for PHP_CodeSniffer

PHP_CodeSniffer Baseliner This tool enables you to integrate PHP_CodeSniffer into an existing project by automatically adding phpcs:ignore and phpcs:d

ISAAC 13 Nov 26, 2022
All In 1 Spam Tool For Termux Users Subscribe Us (Noob Hackers) some shit heads are trying to abuse this script so don't worry about them ...let them hallucinate ...but you are free to use this script

ABOUT TOOL : SPAMX is a all in one Bombing+Spam tool from this tool you can send anonymous messages to your target without showing your real number an

N17R0 449 Jan 7, 2023
A static analysis tool for security

progpilot A static analyzer for security purposes Only PHP language is currently supported Installation Option 1: use standalone phar Download the lat

null 271 Dec 27, 2022
A project to add Psalm support for Drupal for security testing, focused only on taint analysis.

psalm-plugin-drupal A Drupal integration for Psalm focused on security scanning (SAST) taint analysis. Features Stubs for sinks, sources, and sanitize

Samuel Mortenson 38 Aug 29, 2022
A PHP parser written in PHP

PHP Parser This is a PHP 5.2 to PHP 8.0 parser written in PHP. Its purpose is to simplify static code analysis and manipulation. Documentation for ver

Nikita Popov 15.9k Jan 3, 2023