<commit_before><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace CommonBundle\Component\Redis;

use InvalidArgumentException;

class Uri
{
    /**
     * @param  array $components
     * @return string
     */
    public static function build($components, $format = 'redis')
    {
        switch ($format) {
            case 'redis':
                $uri = 'redis://';
                if (isset($components['password']) && $components['password'] != '') {
                    $uri .= ':' . $components['password'] . '@';
                }

                $uri .= $components['host'];

                if (isset($components['port'])) {
                    $uri .= ':' . $components['port'];
                }

                if (isset($components['database'])) {
                    $uri .= '/' . $components['database'];
                }

                return $uri;

            case 'tcp':
                $uri = 'tcp://' . $components['host'] . ':' . $components['port'];

                $options = array();
                if (isset($components['password']) && $components['password'] != '') {
                    $options[] = 'auth=' . $components['password'];
                }

                if (isset($components['database']) && $components['password'] != 0) {
                    $options[] = 'database=' . $components['database'];
                }

                if (isset($components['timeout']) && $components['timeout'] !== null) {
                    $options[] = 'timeout=' . $components['timeout'];
                }

                return $uri . (count($options) > 0 ? '?' . implode('&', $options) : '');

            default:
                throw new InvalidArgumentException('Invalid format');
        }
    }
}<commit_msg>Support for more options in our Redis URI builder<commit_after><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace CommonBundle\Component\Redis;

use InvalidArgumentException;

class Uri
{
    /**
     * @param  array $components
     * @return string
     */
    public static function build($components, $format = 'redis')
    {
        switch ($format) {
            case 'redis':
                $uri = 'redis://';
                if (isset($components['password']) && $components['password'] != '') {
                    $uri .= ':' . $components['password'] . '@';
                }

                $uri .= $components['host'];

                if (isset($components['port'])) {
                    $uri .= ':' . $components['port'];
                }

                if (isset($components['database'])) {
                    $uri .= '/' . $components['database'];
                }

                return $uri;

            case 'tcp':
                $uri = 'tcp://' . $components['host'] . ':' . $components['port'];

                $parameters = array();
                if (isset($components['weight']) && $components['weight'] !== null) {
                    $parameters[] = 'weight=' . $components['weight'];
                }

                if (isset($components['timeout']) && $components['timeout'] !== null) {
                    $parameters[] = 'timeout=' . $components['timeout'];
                }

                if (isset($components['persistent_id']) && $components['persistent_id'] != '') {
                    $parameters[] = 'persistent=1';
                    $parameters[] = 'persistent_id=' . $components['persistent_id'];
                }

                if (isset($components['password']) && $components['password'] != '') {
                    $parameters[] = 'auth=' . $components['password'];
                }

                if (isset($components['database']) && $components['password'] != 0) {
                    $parameters[] = 'database=' . $components['database'];
                }

                return $uri . (count($parameters) > 0 ? '?' . implode('&', $parameters) : '');

            default:
                throw new InvalidArgumentException('Invalid format');
        }
    }
}
{'fraction_non_alphanumeric': 0.18488583552232773, 'fraction_numerical': 0.0010103051121438675, 'mean_word_length': 1.8156996587030716, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7381026', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1275, 'n_words': 309}