Hooks::getAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 1
nop 0
1
<?php
2
3
namespace Sofa\Eloquence\Mutable;
4
5
/**
6
 * This class provides instance scope for the closures
7
 * so they can be rebound later onto the acutal model.
8
 */
9
class Hooks
10
{
11
    /**
12
     * Register hook on getAttribute method.
13
     *
14
     * @return \Closure
15
     */
16 View Code Duplication
    public function getAttribute()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18
        return function ($next, $value, $args) {
19
            $key = $args->get('key');
20
21
            if ($this->hasGetterMutator($key)) {
0 ignored issues
show
Bug introduced by
The method hasGetterMutator() does not seem to exist on object<Sofa\Eloquence\Mutable\Hooks>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
                $value = $this->mutableMutate($key, $value, 'getter');
0 ignored issues
show
Bug introduced by
The method mutableMutate() does not seem to exist on object<Sofa\Eloquence\Mutable\Hooks>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
            }
24
25
            return $next($value, $args);
26
        };
27
    }
28
29
    /**
30
     * Register hook on setAttribute method.
31
     *
32
     * @return \Closure
33
     */
34
    public function setAttribute()
35
    {
36
        return function ($next, $value, $args) {
37
            $key = $args->get('key');
38
39
            if ($this->hasSetterMutator($key)) {
0 ignored issues
show
Bug introduced by
The method hasSetterMutator() does not seem to exist on object<Sofa\Eloquence\Mutable\Hooks>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
                $value = $this->mutableMutate($key, $value, 'setter');
0 ignored issues
show
Bug introduced by
The method mutableMutate() does not seem to exist on object<Sofa\Eloquence\Mutable\Hooks>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            }
42
43
            return $next($value, $args);
44
        };
45
    }
46
47
    /**
48
     * Register hook on toArray method.
49
     *
50
     * @return \Closure
51
     */
52
    public function toArray()
53
    {
54
        return function ($next, $attributes) {
55
            $attributes = $this->mutableAttributesToArray($attributes);
0 ignored issues
show
Bug introduced by
The method mutableAttributesToArray() does not exist on Sofa\Eloquence\Mutable\Hooks. Did you maybe mean toArray()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
57
            return $next($attributes);
58
        };
59
    }
60
}
61