propelorm/Propel2

src/Propel/Generator/Config/ArrayToPhpConverter.php
C

Remove call to debugging function var_export

\$manager->setReadConfiguration(" . var_export($params['slaves'], true). ");";
Severity: Minor
Found in src/Propel/Generator/Config/ArrayToPhpConverter.php - About 5 mins to fix

Remove call to debugging function var_export

\$manager->{$masterConfigurationSetter}(". var_export($connection, true) . ");";
Severity: Minor
Found in src/Propel/Generator/Config/ArrayToPhpConverter.php - About 5 mins to fix

Remove call to debugging function var_export

\$serviceContainer->setProfilerConfiguration(" . var_export($profilerConf, true) . ");";
Severity: Minor
Found in src/Propel/Generator/Config/ArrayToPhpConverter.php - About 5 mins to fix

Remove call to debugging function var_export

\$serviceContainer->setLoggerConfiguration('{$key}', " . var_export($logger, true) . ");";
Severity: Minor
Found in src/Propel/Generator/Config/ArrayToPhpConverter.php - About 5 mins to fix

Complex method in convert

    public static function convert($c)
    {
        $runtimeVersion = Propel::VERSION;

        $conf = '';

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Method convert is too long

    public static function convert($c)
    {
        $runtimeVersion = Propel::VERSION;

        $conf = '';
Severity: Minor
Found in src/Propel/Generator/Config/ArrayToPhpConverter.php - About 1 hr to fix

Cyclomatic complexity for function convert is too high

    public static function convert($c)
    {
        $runtimeVersion = Propel::VERSION;

        $conf = '';
Severity: Minor
Found in src/Propel/Generator/Config/ArrayToPhpConverter.php - About 1 hr to fix

The variable name, masterConfigurationSetter, is too long

                    $masterConfigurationSetter = isset($params['slaves']) ? 'setWriteConfiguration' : 'setConfiguration';
Severity: Minor
Found in src/Propel/Generator/Config/ArrayToPhpConverter.php - About 5 mins to fix

There are no issues that match your filters.

<?php

/**
 * This file is part of the Propel package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license MIT License
 */

namespace Propel\Generator\Config;
use Propel\Runtime\Propel;

/**
 * Runtime configuration converter
 * From array to PHP string
 */
class ArrayToPhpConverter
{
    /**
     * Create a PHP configuration from an array
     *
     * @param array $c The array configuration
     *
     * @return string
     */
    public static function convert($c)
    {
        $runtimeVersion = Propel::VERSION;

        $conf = '';
        $conf .= "\$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();";
        $conf .= "
\$serviceContainer->checkVersion('{$runtimeVersion}');";
        // set datasources
        if (isset($c['connections'])) {
            foreach ($c['connections'] as $name => $params) {
                if (!is_array($params)) {
                    continue;
                }

                // set adapters
                if (isset($params['adapter'])) {
                    $conf .= "
\$serviceContainer->setAdapterClass('{$name}', '{$params['adapter']}');";
                }

                // set connection settings
                if (isset($params['slaves'])) {
                    $conf .= "
\$manager = new \Propel\Runtime\Connection\ConnectionManagerMasterSlave();
\$manager->setReadConfiguration(" . var_export($params['slaves'], true). ");";
                } elseif (isset($params['dsn'])) {
                    $conf .= "
\$manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();";
                } else {
                    continue;
                }

                if (isset($params['dsn'])) {
                    $masterConfigurationSetter = isset($params['slaves']) ? 'setWriteConfiguration' : 'setConfiguration';
                    $connection = $params;
                    unset($connection['adapter']);
                    unset($connection['slaves']);
                    $conf .= "
\$manager->{$masterConfigurationSetter}(". var_export($connection, true) . ");";
                }

                $conf .= "
\$manager->setName('{$name}');
\$serviceContainer->setConnectionManager('{$name}', \$manager);";
            }

            // set default datasource
            if (isset($c['defaultConnection'])) {
                $defaultDatasource = $c['defaultConnection'];
            } elseif (isset($c['connections']) && is_array($c['connections'])) {
                // fallback to the first datasource
                $datasourceNames = array_keys($c['connections']);
                $defaultDatasource = $datasourceNames[0];
            }

            $conf .= "
\$serviceContainer->setDefaultDatasource('{$defaultDatasource}');";
        }

        // set profiler
        if (isset($c['profiler'])) {
            $profilerConf = $c['profiler'];
            if (isset($profilerConf['classname'])) {
                $conf .= "
\$serviceContainer->setProfilerClass('{$profilerConf['classname']}');";
                unset($profilerConf['classname']);
            }

            if ($profilerConf) {
                $conf .= "
\$serviceContainer->setProfilerConfiguration(" . var_export($profilerConf, true) . ");";
            }
            unset($c['profiler']);
        }

        // set logger
        if (isset($c['log']) && count($c['log']) > 0) {
            foreach ($c['log'] as $key => $logger) {
                $conf .= "
\$serviceContainer->setLoggerConfiguration('{$key}', " . var_export($logger, true) . ");";
            }
            unset($c['log']);
        }

        return preg_replace('/[ \t]*$/m', '', $conf);
    }
}

Size

Lines of code
75