<commit_before><?php

namespace PHPCR\Util;

use PHPCR\NodeInterface;
use PHPCR\PropertyInterface;
use PHPCR\PropertyType;
use PHPCR\RepositoryException;
use PHPCR\ValueFormatException;

/**
 * PHPCR compliant conversion between values.
 *
 * This class also proxies the determineType method to allow extending classes
 * to handle custom types.
 *
 * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
 * @license http://opensource.org/licenses/MIT MIT License
 *
 * @author <NAME> <<EMAIL>>
 *
 * @api
 */
class ValueConverter
{
    /**
     * Determine PropertyType from on variable type.
     *
     * This is most of the remainder of ValueFactory that is still needed.
     *
     * - if the given $value is a Node object, type will be REFERENCE, unless
     *    $weak is set to true which results in WEAKREFERENCE
     * - if the given $value is a DateTime object, the type will be DATE.
     *
     * Note that string is converted to date exactly if it matches the jcr
     * formatting spec for dates (sYYYY-MM-DDThh:mm:ss.sssTZD) according to
     * http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4.3%20From%20DATE%20To
     *
     * @param mixed   $value The variable we need to know the type of
     * @param boolean $weak  When a Node is given as $value this can be given
     *                       as true to create a WEAKREFERENCE.
     *
     * @return int One of the type constants
     *
     * @throws ValueFormatException if the type can not be determined
     */
    public function determineType($value, $weak = false)
    {
        return PropertyType::determineType($value, $weak);
    }

    /**<commit_msg>handle multivalue arrays in determineType<commit_after><?php

namespace PHPCR\Util;

use PHPCR\NodeInterface;
use PHPCR\PropertyInterface;
use PHPCR\PropertyType;
use PHPCR\RepositoryException;
use PHPCR\ValueFormatException;

/**
 * PHPCR compliant conversion between values.
 *
 * This class also proxies the determineType method to allow extending classes
 * to handle custom types.
 *
 * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
 * @license http://opensource.org/licenses/MIT MIT License
 *
 * @author <NAME> <<EMAIL>>
 *
 * @api
 */
class ValueConverter
{
    /**
     * Determine PropertyType from on variable type.
     *
     * This is most of the remainder of ValueFactory that is still needed.
     *
     * - if the given $value is a Node object, type will be REFERENCE, unless
     *    $weak is set to true which results in WEAKREFERENCE
     * - if the given $value is a DateTime object, the type will be DATE.
     * - if the $value is an empty array, the type is arbitrarily set to STRING
     * - if the $value is a non-empty array, the type of its first element is
     *   chosen.
     *
     * Note that string is converted to date exactly if it matches the jcr
     * formatting spec for dates (sYYYY-MM-DDThh:mm:ss.sssTZD) according to
     * http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4.3%20From%20DATE%20To
     *
     * @param mixed   $value The variable we need to know the type of
     * @param boolean $weak  When a Node is given as $value this can be given
     *                       as true to create a WEAKREFERENCE.
     *
     * @return int One of the type constants
     *
     * @throws ValueFormatException if the type can not be determined
     */
    public function determineType($value, $weak = false)
    {
        if (is_array($value)) {
            if (0 === count($value)) {
                // there is no value to determine the type on. we arbitrarily
                // chose string, which is what jackrabbit does as well.
                return PropertyType::STRING;
            }
            $value = reset($value);
        }

        return PropertyType::determineType($value, $weak);
    }

    /**
{'fraction_non_alphanumeric': 0.08697889861039629, 'fraction_numerical': 0.010036026762738034, 'mean_word_length': 2.5924214417744915, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, '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': '799559', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1100, 'n_words': 424}