<commit_before><?php

namespace EM\GameBundle\Validator;

use JMS\Serializer\Annotation as Serializer;

/**
 * @since 18.0
 */
class GameInitiationRequestValidator
{
    /**
     * @var int
     */
    private $minBattlefieldSize;
    /**
     * @var int
     */
    private $maxBattlefieldSize;
    /**
     * @var int
     */
    private $minOpponents;
    /**
     * @var int
     */
    private $maxOpponents;

    /**
     * @param int $minBattlefieldSize
     * @param int $maxBattlefieldSize
     * @param int $minOpponents
     * @param int $maxOpponents
     */
    public function __construct(int $minBattlefieldSize, int $maxBattlefieldSize, int $minOpponents, int $maxOpponents)
    {
        $this->minBattlefieldSize = $minBattlefieldSize;
        $this->maxBattlefieldSize = $maxBattlefieldSize;
        $this->minOpponents = $minOpponents;
        $this->maxOpponents = $maxOpponents;
    }

    public function validate(string $json) : bool
    {
        $data = json_decode($json);

        return
            $data instanceof \stdClass
            && $this->validateStructure($data)
            && $this->validateBattlefieldSize($data->size)
            && $this->validatePlayerName($data->playerName)
            && $this->validateOpponentsAmount($data->opponents)
            && $this->validateCoordinates($data->coordinates);
    }

    protected function validateStructure(\stdClass $data) : bool
    {
        return
            isset($data->opponents, $data->playerName, $data->size, $data->coordinates)
            && is_array($data->coordinates);
    }

    protected function validateOpponentsAmount(int $value) : bool
    {
        return $this->isBetween($value, $this->minOpponents, $this->maxOpponents);
    }

    protected function validateBattlefieldSize(int $value) : bool
    {
        return $this->isBetween($value, $this->minBattlefieldSize, $this->maxBattlefieldSize);
    }

    // TODO: replace name with ID
    protected function validatePlayerName(string $value) : bool
    {
        return !empty($value);
    }

    protected function validateCoordinates(array $coordinates) : bool
    {<commit_msg>cleanup<commit_after><?php

namespace EM\GameBundle\Validator;

use JMS\Serializer\Annotation as Serializer;

/**
 * @since 18.0
 */
class GameInitiationRequestValidator
{
    /**
     * @var int
     */
    private $minBattlefieldSize;
    /**
     * @var int
     */
    private $maxBattlefieldSize;
    /**
     * @var int
     */
    private $minOpponents;
    /**
     * @var int
     */
    private $maxOpponents;

    /**
     * @param int $minBattlefieldSize
     * @param int $maxBattlefieldSize
     * @param int $minOpponents
     * @param int $maxOpponents
     */
    public function __construct(int $minBattlefieldSize, int $maxBattlefieldSize, int $minOpponents, int $maxOpponents)
    {
        $this->minBattlefieldSize = $minBattlefieldSize;
        $this->maxBattlefieldSize = $maxBattlefieldSize;
        $this->minOpponents = $minOpponents;
        $this->maxOpponents = $maxOpponents;
    }

    public function validate(string $json) : bool
    {
        $data = json_decode($json);

        return
            $data instanceof \stdClass
            && $this->validateStructure($data)
            && $this->validateBattlefieldSize($data->size)
            && $this->validatePlayerName($data->playerName)
            && $this->validateOpponentsAmount($data->opponents)
            && $this->validateCoordinates($data->coordinates);
    }

    protected function validateStructure(\stdClass $data) : bool
    {
        return
            isset($data->opponents, $data->playerName, $data->size, $data->coordinates)
            && is_array($data->coordinates);
    }

    protected function validateOpponentsAmount(int $value) : bool
    {
        return $this->isBetween($value, $this->minOpponents, $this->maxOpponents);
    }

    protected function validateBattlefieldSize(int $value) : bool
    {
        return $this->isBetween($value, $this->minBattlefieldSize, $this->maxBattlefieldSize);
    }

    protected function validatePlayerName(string $value) : bool
    {
        return !empty($value);
    }

    protected function validateCoordinates(array $coordinates) : bool
    {
{'fraction_non_alphanumeric': 0.12347130761994356, 'fraction_numerical': 0.0014111006585136407, 'mean_word_length': 2.6381522668947817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '6200436', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1229, 'n_words': 233}