<commit_before><?php
/**
 * @copyright	Copyright (C) 2007 - 2015 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		Mozilla Public License, version 2.0
 * @link		http://github.com/joomlatools/joomlatools-console for the canonical source repository
 */

namespace Joomlatools\Console\Command\Site;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Joomlatools\Console\Command\Database;

class Listing extends Database\AbstractDatabase
{
    protected function configure()
    {
        $this
            ->setName('site:list')
            ->setDescription('List Joomla sites')
            ->setHelp('List Joomla sites running on this box');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        define('_JEXEC', true);
        define('JPATH_BASE', true);
        define('JPATH_PLATFORM', true);

        $dir = new \DirectoryIterator('/var/www');
        $sites = array();

        $canonical = function($version) {
            if (isset($version->RELEASE)) {
                return 'v' . $version->RELEASE . '.' . $version->DEV_LEVEL;
            }

            // Joomla 3.5 and up uses constants instead of properties in JVersion
            $className = get_class($version);
            if (defined("$className::RELEASE")) {
                return 'v'. $version::RELEASE . '.' . $version::DEV_LEVEL;
            }

            return 'unknown';
        };

        foreach ($dir as $fileinfo)
        {
            $code = $application = null;

            if ($fileinfo->isDir() && !$fileinfo->isDot())
            {
                $files = array(
                    'joomla-cms'           => $fileinfo->getPathname() . '/libraries/cms/version/version.php',
                    'joomlatools-platform' => $fileinfo->getPathname() . '/lib/libraries/cms/version/version.php',
                    'joomla-1.5'           => $fileinfo->getPathname() . '/libraries/joomla/version.php'
                );

                foreach ($files as $type => $file)
                {
                    if (file_exists($file))
                    {
                        $code        = $file;
                        $application = $type;

                        break;
                    }
                }

                if (!is_null($code) && file_exists($code))
                {
                    $identifier = uniqid();

                    $source = file_get_contents($code);
                    $source = preg_replace('/<\?php/', '', $source, 1);
                    $source = preg_replace('/class JVersion/i', 'class JVersion' . $identifier, $source);

                    eval($source);

                    $class   = 'JVersion'.$identifier;
                    $version = new $class();

                    $sites[] = (object) array(
                        'name'    => $fileinfo->getFilename(),
                        'docroot' => $fileinfo->getFilename() . '/' . ($application == 'joomlatools-platform' ? 'web' : ''),
                        'type'    => $application,
                        'version' => $canonical($version)
                    );
                }
            }
        }

        $i = 1;
        foreach ($sites as $site):
            $output->write("\n");
            $output->write(sprintf("<info>%s. %s</info> (%s %s)", $i, $site->name, $site->type, $site->version));
            $i++;
        endforeach;
        $output->write("\n");
    }
}
<commit_msg>#17: Full-hand notation on foreach control structure<commit_after><?php
/**
 * @copyright	Copyright (C) 2007 - 2015 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		Mozilla Public License, version 2.0
 * @link		http://github.com/joomlatools/joomlatools-console for the canonical source repository
 */

namespace Joomlatools\Console\Command\Site;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Joomlatools\Console\Command\Database;

class Listing extends Database\AbstractDatabase
{
    protected function configure()
    {
        $this
            ->setName('site:list')
            ->setDescription('List Joomla sites')
            ->setHelp('List Joomla sites running on this box');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        define('_JEXEC', true);
        define('JPATH_BASE', true);
        define('JPATH_PLATFORM', true);

        $dir = new \DirectoryIterator('/var/www');
        $sites = array();

        $canonical = function($version) {
            if (isset($version->RELEASE)) {
                return 'v' . $version->RELEASE . '.' . $version->DEV_LEVEL;
            }

            // Joomla 3.5 and up uses constants instead of properties in JVersion
            $className = get_class($version);
            if (defined("$className::RELEASE")) {
                return 'v'. $version::RELEASE . '.' . $version::DEV_LEVEL;
            }

            return 'unknown';
        };

        foreach ($dir as $fileinfo)
        {
            $code = $application = null;

            if ($fileinfo->isDir() && !$fileinfo->isDot())
            {
                $files = array(
                    'joomla-cms'           => $fileinfo->getPathname() . '/libraries/cms/version/version.php',
                    'joomlatools-platform' => $fileinfo->getPathname() . '/lib/libraries/cms/version/version.php',
                    'joomla-1.5'           => $fileinfo->getPathname() . '/libraries/joomla/version.php'
                );

                foreach ($files as $type => $file)
                {
                    if (file_exists($file))
                    {
                        $code        = $file;
                        $application = $type;

                        break;
                    }
                }

                if (!is_null($code) && file_exists($code))
                {
                    $identifier = uniqid();

                    $source = file_get_contents($code);
                    $source = preg_replace('/<\?php/', '', $source, 1);
                    $source = preg_replace('/class JVersion/i', 'class JVersion' . $identifier, $source);

                    eval($source);

                    $class   = 'JVersion'.$identifier;
                    $version = new $class();

                    $sites[] = (object) array(
                        'name'    => $fileinfo->getFilename(),
                        'docroot' => $fileinfo->getFilename() . '/' . ($application == 'joomlatools-platform' ? 'web' : ''),
                        'type'    => $application,
                        'version' => $canonical($version)
                    );
                }
            }
        }

        $i = 1;
        foreach ($sites as $site) {
            $output->write("\n");
            $output->write(sprintf("<info>%s. %s</info> (%s %s)", $i, $site->name, $site->type, $site->version));
            $i++;
        }
        $output->write("\n");
    }
}

{'fraction_non_alphanumeric': 0.14583333333333334, 'fraction_numerical': 0.00481859410430839, 'mean_word_length': 1.5140719629497685, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146035', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1853, 'n_words': 377}