<commit_before><?php

/*
 * This file is part of the 'octris' package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace octris\command {
    use \org\octris\core\provider as provider;
    use \org\octris\core\validate as validate;

    /**
     * Create a page graph of a project.
     *
     * @octdoc      c:command/graph
     * @copyright   copyright (c) 2011-2014 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class graph extends \octris\command
    /**/
    {
        /**
         * Return command description.
         *
         * @octdoc  m:graph/getDescription
         */
        public static function getDescription()
        /**/
        {
            return 'Create a page graph of a project.';
        }

        /**
         * Return command manual.
         *
         * @octdoc  m:create/getManual
         */
        public static function getManual()
        /**/
        {
            return <<<EOT
NAME
    octris graph - create a page graph of a project.
    
SYNOPSIS
    octris graph     <project-path>
    
DESCRIPTION
    This command is used to analyze the page flow of a project and
    to create a graph from it that can be visualized using the dot
    utility of graphviz.
    
    The generated graph will be printed to stdout and can as such
    be directly processed by the dot utility.
    
OPTIONS

EXAMPLES
    Create a graph of a project in PDF format:
    
        $ ./octris graph ~/tmp/org.octris.test |\
                dot -Tpdf

HINTS
    Graphviz is available for various platforms and can be downloaded
    from: http://www.graphviz.org/
EOT;
        }

        /**
         * Run command.
         *
         * @octdoc  m:graph/run
         */
        public function run()
        /**/
        {
            // import required parameters
            $args = provider::access('args');

            if ($args->isExist(0) && $args->isValid(0, validate::T_PATH)) {
                $dir = rtrim($args->getValue(0), '/');
            } else {
                $this->setError('specified path is not a directory or directory not found');
                
                return 1;
            }

            if (!is_dir($dir . '/libs/app') || !is_file($dir . '/libs/app/entry.class.php')) {
                $this->setError(sprintf('\'%s\' does not seem to be a web application created with the OCTRiS framework', $dir));
                
                return 1;
            }
            
            $project = basename($dir);
            $ns      = str_replace('.', '\\', $project) . '\\';
            
            /*
             * install new project-specific autoloader
             */
            spl_autoload_unregister(array('\octris\autoloader', 'autoload'));
            spl_autoload_register(function($classpath) use ($dir, $ns) {
                if (strpos($classpath, $ns) === 0) {
                    // main application library
                    $file = $dir . '/libs/' . str_replace('\\', '/', substr($classpath, strlen($ns))) . '.class.php';
                } else {
                    // vendor library
                    $classpath = preg_replace('|\\\\|', '.', ltrim($classpath, '\\'), 2);
                    $classpath = preg_replace('|\\\\|', '/libs/', $classpath, 1);
                    $classpath = str_replace('\\', '/', $classpath);
                    
                    $file = $dir . '/vendor/' . $classpath . '.class.php';
                }
                
                require_once($file);
            });
            
            // main
            $analyze = function($page) use (&$analyze) {
                static $processed = array();
<commit_msg>changes due to framework changes<commit_after><?php

/*
 * This file is part of the 'octris' package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace octris\command {
    use \org\octris\core\provider as provider;
    use \org\octris\core\validate as validate;

    /**
     * Create a page graph of a project.
     *
     * @octdoc      c:command/graph
     * @copyright   copyright (c) 2011-2014 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class graph extends \org\octris\cliff\app\command
    /**/
    {
        /**
         * Constructor.
         *
         * @octdoc  m:graph/__construct
         */
        public function __construct()
        /**/
        {
        }
        
        /**
         * Return command description.
         *
         * @octdoc  m:graph/getDescription
         */
        public static function getDescription()
        /**/
        {
            return 'Create a page graph of a project.';
        }

        /**
         * Return command manual.
         *
         * @octdoc  m:create/getManual
         */
        public static function getManual()
        /**/
        {
            return <<<EOT
NAME
    octris graph - create a page graph of a project.
    
SYNOPSIS
    octris graph     <project-path>
    
DESCRIPTION
    This command is used to analyze the page flow of a project and
    to create a graph from it that can be visualized using the dot
    utility of graphviz.
    
    The generated graph will be printed to stdout and can as such
    be directly processed by the dot utility.
    
OPTIONS

EXAMPLES
    Create a graph of a project in PDF format:
    
        $ ./octris graph ~/tmp/org.octris.test |\
                dot -Tpdf

HINTS
    Graphviz is available for various platforms and can be downloaded
    from: http://www.graphviz.org/
EOT;
        }

        /**
         * Run command.
         *
         * @octdoc  m:graph/run
         * @param   \org\octris\cliff\options\collection        $args           Parsed arguments for command.
         */
        public function run(\org\octris\cliff\options\collection $args)
        /**/
        {
            if (!isset($args[0])) {
                $this->setError(sprintf("no project path specified"));
                
                return false;
            } elseif (!is_dir($args[0])) {
                $this->setError('specified path is not a directory or directory not found');
                
                return false;
            } else {
                $dir = rtrim($args[0], '/');
            }
            
            if (!is_dir($dir . '/libs/app') || !is_file($dir . '/libs/app/entry.class.php')) {
                $this->setError(sprintf('\'%s\' does not seem to be a web application created with the OCTRiS framework', $dir));
                
                return false;
            }
            
            $project = basename($dir);
            $ns      = str_replace('.', '\\', $project) . '\\';
            
            /*
             * install new project-specific autoloader
             */
            spl_autoload_unregister(array('\octris\autoloader', 'autoload'));
            spl_autoload_register(function($classpath) use ($dir, $ns) {
                if (strpos($classpath, $ns) === 0) {
                    // main application library
                    $file = $dir . '/libs/' . str_replace('\\', '/', substr($classpath, strlen($ns))) . '.class.php';
                } else {
                    // vendor library
                    $classpath = preg_replace('|\\\\|', '.', ltrim($classpath, '\\'), 2);
                    $classpath = preg_replace('|\\\\|', '/libs/', $classpath, 1);
                    $classpath = str_replace('\\', '/', $classpath);
                    
                    $file = $dir . '/vendor/' . $classpath . '.class.php';
                }
                
                require_once($file);
            });
            
            // main
            $analyze = function($page) use (&$analyze) {
                static $processed = array();

{'fraction_non_alphanumeric': 0.12408850892632638, 'fraction_numerical': 0.0037716872014080965, 'mean_word_length': 1.3903245192307692, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3281706', 'n_tokens_mistral': 2222, 'n_tokens_neox': 2144, 'n_words': 609}