FieldTransformer   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 22 1
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\FieldGenerator\Transformers;
4
5
use League\Fractal\TransformerAbstract;
6
use Hechoenlaravel\JarvisFoundation\FieldGenerator\FieldModel;
7
8
class FieldTransformer extends TransformerAbstract
9
{
10
    public function transform(FieldModel $field)
11
    {
12
        $fieldTypes = app('field.types');
13
        $type = $fieldTypes->getFieldClass($field->type);
14
        return [
15
            'id' => $field->id,
16
            'namespace' => $field->namespace,
17
            'name' => $field->name,
18
            'description' => $field->description,
19
            'slug' => $field->slug,
20
            'type' => $field->type,
21
            'options' => unserialize($field->options),
22
            'locked' => (bool) $field->locked,
23
            'hidden' => (bool) $field->hidden,
0 ignored issues
show
Documentation introduced by
The property $hidden is declared protected in Illuminate\Database\Eloq...oncerns\HidesAttributes. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
24
            'order' => $field->order,
25
            'default' => $field->default,
26
            'required' => (string)$field->required,
27
            'fieldType' => [
28
                'name' => $type->name
29
            ]
30
        ];
31
    }
32
}
33