<commit_before><?php

namespace CatLab\Charon\Laravel\Resolvers;

use CatLab\Charon\Collections\PropertyValueCollection;
use CatLab\Charon\Interfaces\Context;
use CatLab\Charon\Interfaces\ResourceTransformer;
use CatLab\Charon\Exceptions\InvalidPropertyException;
use CatLab\Charon\Laravel\Database\Model;
use CatLab\Charon\Laravel\PropertySetterException;
use CatLab\Charon\Models\Properties\IdentifierField;
use CatLab\Charon\Models\Properties\RelationshipField;
use CatLab\Charon\Models\Properties\ResourceField;
use CatLab\Charon\Interfaces\PropertyResolver as PropertyResolverContract;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\Relation;

/**
 * Class PropertySetter
 * @package CatLab\RESTResource\Laravel\Resolvers
 */
class PropertySetter extends \CatLab\Charon\Resolvers\PropertySetter
{
    /**
     * @param ResourceTransformer $entity
     * @param mixed $name
     * @param ResourceField $value
     * @param array $setterParameters
     */
    protected function setChildInEntity($entity, $name, $value, $setterParameters = [])
    {
        // Check for link method name.
        $methodName = 'associate' . ucfirst($name);
        if (method_exists($entity, $methodName)) {
            array_unshift($setterParameters, $value);
            call_user_func_array(array ($entity, $methodName), $setterParameters)
        } else {
            $entity->$name()->associate($value);
        }
    }

    /**
     * @param $entity
     * @param $name
     * @param array $setterParameters
     * @throws InvalidPropertyException
     */
    protected function clearChildInEntity($entity, $name, $setterParameters = [])
    {
        // Check for link method name.
        $methodName = 'dissociate' . ucfirst($name);
        if (method_exists($entity, $methodName)) {
            call_user_func_array(array ($entity, $methodName), $setterParameters)
        } else {
            $entity->$name()->dissociate();
        }
    }

    /**
     * @param mixed $entity
     * @param string $name
     * @param mixed $value
     * @param array $setterParameters
     * @return mixed
     */
    protected function setValueInEntity($entity, $name, $value, $setterParameters = [])
    {
        // Check for set method
        if (method_exists($entity, 'set'.ucfirst($name))) {
            array_unshift($setterParameters, $value);
            return call_user_func_array(array($entity, 'set'.ucfirst($name)), $setterParameters);
        } else {
            $entity->$name = $value;
        }
    }<commit_msg>Woops syntax error in propertysetter that was not caught by unit tests...<commit_after><?php

namespace CatLab\Charon\Laravel\Resolvers;

use CatLab\Charon\Collections\PropertyValueCollection;
use CatLab\Charon\Interfaces\Context;
use CatLab\Charon\Interfaces\ResourceTransformer;
use CatLab\Charon\Exceptions\InvalidPropertyException;
use CatLab\Charon\Laravel\Database\Model;
use CatLab\Charon\Laravel\PropertySetterException;
use CatLab\Charon\Models\Properties\IdentifierField;
use CatLab\Charon\Models\Properties\RelationshipField;
use CatLab\Charon\Models\Properties\ResourceField;
use CatLab\Charon\Interfaces\PropertyResolver as PropertyResolverContract;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\Relation;

/**
 * Class PropertySetter
 * @package CatLab\RESTResource\Laravel\Resolvers
 */
class PropertySetter extends \CatLab\Charon\Resolvers\PropertySetter
{
    /**
     * @param ResourceTransformer $entity
     * @param mixed $name
     * @param ResourceField $value
     * @param array $setterParameters
     */
    protected function setChildInEntity($entity, $name, $value, $setterParameters = [])
    {
        // Check for link method name.
        $methodName = 'associate' . ucfirst($name);
        if (method_exists($entity, $methodName)) {
            array_unshift($setterParameters, $value);
            call_user_func_array(array ($entity, $methodName), $setterParameters);
        } else {
            $entity->$name()->associate($value);
        }
    }

    /**
     * @param $entity
     * @param $name
     * @param array $setterParameters
     * @throws InvalidPropertyException
     */
    protected function clearChildInEntity($entity, $name, $setterParameters = [])
    {
        // Check for link method name.
        $methodName = 'dissociate' . ucfirst($name);
        if (method_exists($entity, $methodName)) {
            call_user_func_array(array ($entity, $methodName), $setterParameters);
        } else {
            $entity->$name()->dissociate();
        }
    }

    /**
     * @param mixed $entity
     * @param string $name
     * @param mixed $value
     * @param array $setterParameters
     * @return mixed
     */
    protected function setValueInEntity($entity, $name, $value, $setterParameters = [])
    {
        // Check for set method
        if (method_exists($entity, 'set'.ucfirst($name))) {
            array_unshift($setterParameters, $value);
            return call_user_func_array(array($entity, 'set'.ucfirst($name)), $setterParameters);
        } else {
            $entity->$name = $value;
        }
    }
{'fraction_non_alphanumeric': 0.11925074183976261, 'fraction_numerical': 0.0, 'mean_word_length': 3.2431156569630213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4532225', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1571, 'n_words': 301}