<commit_before><?php
/**
 * Copyright (C) 2016 <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

namespace CrEOF\Geo\Obj\Validator\Value\Traits;

use CrEOF\Geo\Obj\Configuration;
use CrEOF\Geo\Obj\Exception\ExceptionInterface;
use CrEOF\Geo\Obj\Exception\RangeException;
use CrEOF\Geo\Obj\Exception\UnexpectedValueException;
use CrEOF\Geo\Obj\Object;

/**
 * Class MultiPolygonValidator
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://dlambert.mit-license.org MIT
 */
trait ValidatePointTrait
{
    protected $dimension;

    /**
     * @param mixed  $point
     * @param string $messageType Name of object containing points used in exception messages
     *
     * @throws ExceptionInterface
     */
    protected function validatePoint($point, $messageType)
    {
        if (! is_array($point)) {
            throw new UnexpectedValueException($messageType . ' value must be array of "array", "' . gettype($point) . '" found');
        }

        if (null === $this->dimension) {
            $this->dimension = count($point);
        }

        if (count($point) !== $this->dimension) {
            throw new RangeException('Dimension mismatch'); //TODO fix message
        }

        $point = [
            'type' => 'point',
            'value' => $point
        ];

        try {
            Configuration::getInstance()->getValidators(Object::T_POINT)->validate($point);
        } catch (ExceptionInterface $e) {
            throw new RangeException('Bad point value in ' . $messageType . '. ' . $e->getMessage(), $e->getCode(), $e);<commit_msg>Add parameter for dimension. Pass dimension to point validator stack. Change parameter name to something more accurate.<commit_after><?php
/**
 * Copyright (C) 2016 <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

namespace CrEOF\Geo\Obj\Validator\Value\Traits;

use CrEOF\Geo\Obj\Configuration;
use CrEOF\Geo\Obj\Exception\ExceptionInterface;
use CrEOF\Geo\Obj\Exception\RangeException;
use CrEOF\Geo\Obj\Exception\UnexpectedValueException;
use CrEOF\Geo\Obj\Object;

/**
 * Class ValidatePointTrait
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://dlambert.mit-license.org MIT
 */
trait ValidatePointTrait
{
    /**
     * @param mixed  $point
     * @param string $dimension
     * @param string $parentType Name of object containing points used in exception messages
     *
     * @throws ExceptionInterface
     */
    protected function validatePoint($point, $dimension, $parentType)
    {
        if (! is_array($point)) {
            throw new UnexpectedValueException($parentType . ' value must be array of "array", "' . gettype($point) . '" found');
        }

        $point = [
            'type'      => 'point',
            'value'     => $point,
            'dimension' => $dimension
        ];

        try {
            Configuration::getInstance()->getValidators(Object::T_POINT)->validate($point);
        } catch (ExceptionInterface $e) {
            throw new RangeException('Bad point value in ' . $parentType . '. ' . $e->getMessage(), $e->getCode(), $e);
{'fraction_non_alphanumeric': 0.10058708414872798, 'fraction_numerical': 0.0015655577299412916, 'mean_word_length': 3.2662771285475793, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '2488336', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1314, 'n_words': 524}