Code Duplication    Length = 26-28 lines in 2 locations

src/Entry/EntryTranslationsModel.php 1 location

@@ 112-137 (lines=26) @@
109
     * @param string $key
110
     * @param mixed  $value
111
     */
112
    public function setAttribute($key, $value)
113
    {
114
        if (!$parent = $this->getParent()) {
115
            return null;
116
        }
117
118
        /* @var AssignmentInterface $assignment */
119
        $assignment = $parent->getAssignment($key);
120
121
        if (!$assignment) {
122
123
            parent::setAttribute($key, $value);
124
125
            return;
126
        }
127
128
        $type = $assignment->getFieldType($this);
129
130
        $type->setEntry($this);
131
        $type->setLocale($this->locale);
132
133
        $accessor = $type->getAccessor();
134
        $modifier = $type->getModifier();
135
136
        $accessor->set($modifier->modify($value));
137
    }
138
139
    /**
140
     * Fire field type events.

src/Entry/EntryModel.php 1 location

@@ 251-278 (lines=28) @@
248
     * @param  $fieldSlug
249
     * @return null|FieldType
250
     */
251
    public function getFieldType($fieldSlug)
252
    {
253
        $locale = config('app.locale');
254
255
        $assignment = $this->getAssignment($fieldSlug);
256
257
        if (!$assignment) {
258
            return null;
259
        }
260
261
        $type = $assignment->getFieldType();
262
263
        if ($assignment->isTranslatable()) {
264
265
            $entry = $this->translateOrDefault($locale);
266
267
            $type->setLocale($locale);
268
        } else {
269
            $entry = $this;
270
        }
271
272
        $type->setEntry($entry);
273
274
        $type->setValue($this->getFieldValue($fieldSlug));
275
        $type->setEntry($this);
276
277
        return $type;
278
    }
279
280
    /**
281
     * Get the field type query.