<commit_before><?php

namespace gamringer\JSONPatch;

abstract class Operation
{

    const OP_TEST = 'test';
    const OP_ADD = 'add';
    const OP_REMOVE = 'remove';
    const OP_REPLACE = 'replace';
    const OP_MOVE = 'move';
    const OP_COPY = 'copy';

    protected $path;

    public static function fromDecodedJSON($operationContent)
    {
        static::assertValidOperationContent($operationContent);

        switch ($operationContent->op) {
            case static::OP_TEST:
                return Operation\Test::fromDecodedJSON($operationContent);
            case static::OP_ADD:
                return Operation\Add::fromDecodedJSON($operationContent);
            case static::OP_REMOVE:
                return Operation\Remove::fromDecodedJSON($operationContent);
            case static::OP_REPLACE:
                return Operation\Replace::fromDecodedJSON($operationContent);
            case static::OP_MOVE:
                return Operation\Move::fromDecodedJSON($operationContent);
            case static::OP_COPY:
                return Operation\Copy::fromDecodedJSON($operationContent);
        }
    }

    public function getPath()
    {
        return $this->path;
    }

    private static function assertValidOperationContent($operationContent)
    {
        if (!($operationContent instanceof \stdClass)) {
            throw new Operation\Exception('Operation Content is not an object');
        }

        if (!isset($operationContent->op)) {
            throw new Operation\Exception('All Operations must contain exactly one "op" member');
        }

        if (!in_array($operationContent->op, ['test', 'add', 'remove', 'replace', 'move', 'copy'])) {
            throw new Operation\Exception('Operation must be one of "test", "add", "remove", "replace", "move", "copy"');
        }
    }
}<commit_msg>Made operation list in assertion less error prone<commit_after><?php

namespace gamringer\JSONPatch;

abstract class Operation
{

    const OP_TEST = 'test';
    const OP_ADD = 'add';
    const OP_REMOVE = 'remove';
    const OP_REPLACE = 'replace';
    const OP_MOVE = 'move';
    const OP_COPY = 'copy';

    protected $path;

    public static function fromDecodedJSON($operationContent)
    {
        static::assertValidOperationContent($operationContent);

        switch ($operationContent->op) {
            case static::OP_TEST:
                return Operation\Test::fromDecodedJSON($operationContent);
            case static::OP_ADD:
                return Operation\Add::fromDecodedJSON($operationContent);
            case static::OP_REMOVE:
                return Operation\Remove::fromDecodedJSON($operationContent);
            case static::OP_REPLACE:
                return Operation\Replace::fromDecodedJSON($operationContent);
            case static::OP_MOVE:
                return Operation\Move::fromDecodedJSON($operationContent);
            case static::OP_COPY:
                return Operation\Copy::fromDecodedJSON($operationContent);
        }
    }

    public function getPath()
    {
        return $this->path;
    }

    private static function assertValidOperationContent($operationContent)
    {
        if (!($operationContent instanceof \stdClass)) {
            throw new Operation\Exception('Operation Content is not an object');
        }

        if (!isset($operationContent->op)) {
            throw new Operation\Exception('All Operations must contain exactly one "op" member');
        }

        $possibleOperations = [OP_TEST, OP_ADD, OP_REMOVE, OP_REPLACE, OP_MOVE, OP_COPY];
        if (!in_array($operationContent->op, $possibleOperations)) {
            throw new Operation\Exception('Operation must be one of "'.implode('", "', $possibleOperations).'"');
        }
    }
}
{'fraction_non_alphanumeric': 0.10984345980366145, 'fraction_numerical': 0.0, 'mean_word_length': 2.667315175097276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1500838', 'n_tokens_mistral': 979, 'n_tokens_neox': 949, 'n_words': 227}