Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Created March 22, 2013 15:35
Show Gist options
  • Save mageekguy/5222226 to your computer and use it in GitHub Desktop.
Save mageekguy/5222226 to your computer and use it in GitHub Desktop.
Using scripts\treemap.php
To known how to use it, just do `php scripts/treemap.php --help`.
By default, there is no analyzer defined, so to add them, create a configuration file and add in it:`
```
<?php
use mageekguy\atoum\scripts\treemap\analyzers;
$script
->addAnalyzer(new analyzers\token())
->addAnalyzer(new analyzers\size())
->addAnalyzer(new analyzers\sloc())
;
```
And use it with `-c` argument.
@jubianchi
Copy link

Awesome! 👍

<?php
//.atoum.treemap.php

use mageekguy\atoum\scripts\treemap;
use mageekguy\atoum\scripts\treemap\analyzers;

// This is just a simple/sample analyzer to show how simple it is to add new metrics
class members implements treemap\analyzer
{
    public function getMetricName()
    {
        return 'members';
    }

    public function getMetricFromFile(\splFileInfo $file)
    {
        $tokenFilter = function($token) {
            if (is_array($token) === true)
            {
                switch ($token[0])
                {
                    case T_PUBLIC:
                    case T_PRIVATE:
                    case T_PROTECTED:
                        return true;

                    default:
                        return false;
                }
            }

            return true;
        };

        return sizeof(array_filter(token_get_all(file_get_contents($file)), $tokenFilter));
    }
}

$script
    ->setDirectory(__DIR__ . DIRECTORY_SEPARATOR . 'src')
    ->setOutputFile(__DIR__ . DIRECTORY_SEPARATOR . 'doc/treemap.json')
    ->setProjectName(basename(__DIR__))
    ->addAnalyzer(new analyzers\token())
    ->addAnalyzer(new analyzers\size())
    ->addAnalyzer(new analyzers\sloc())
    // The analyzer we declared above
    ->addAnalyzer(new members())
;
$ php vendor/atoum/atoum/scripts/treemap.php -c .atoum.treemap.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment