Completed
Branch master (cbd196)
by Rémi
08:54
created
src/MagicSetters.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@
 block discarded – undo
7 7
  */
8 8
 trait MagicSetters
9 9
 {
10
-    /**
11
-     * Dynamically set attributes on the entity.
12
-     *
13
-     * @param string $key
14
-     * @param mixed  $value
15
-     *
16
-     * @return void
17
-     */
18
-    public function __set($key, $value)
19
-    {
20
-        $this->attributes[$key] = $value;
21
-    }
10
+	/**
11
+	 * Dynamically set attributes on the entity.
12
+	 *
13
+	 * @param string $key
14
+	 * @param mixed  $value
15
+	 *
16
+	 * @return void
17
+	 */
18
+	public function __set($key, $value)
19
+	{
20
+		$this->attributes[$key] = $value;
21
+	}
22 22
 
23
-    /**
24
-     * Unset an attribute on the entity.
25
-     *
26
-     * @param string $key
27
-     *
28
-     * @return void
29
-     */
30
-    public function __unset($key)
31
-    {
32
-        unset($this->attributes[$key]);
33
-    }
23
+	/**
24
+	 * Unset an attribute on the entity.
25
+	 *
26
+	 * @param string $key
27
+	 *
28
+	 * @return void
29
+	 */
30
+	public function __unset($key)
31
+	{
32
+		unset($this->attributes[$key]);
33
+	}
34 34
 }
Please login to merge, or discard this patch.
src/Commands/Command.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,32 +7,32 @@
 block discarded – undo
7 7
 
8 8
 abstract class Command
9 9
 {
10
-    /**
11
-     * The aggregated entity on which the command is executed.
12
-     *
13
-     * @var \Analogue\ORM\System\Aggregate
14
-     */
15
-    protected $aggregate;
10
+	/**
11
+	 * The aggregated entity on which the command is executed.
12
+	 *
13
+	 * @var \Analogue\ORM\System\Aggregate
14
+	 */
15
+	protected $aggregate;
16 16
 
17
-    /**
18
-     * Query Builder instance.
19
-     *
20
-     * @var \Illuminate\Database\Query\Builder
21
-     */
22
-    protected $query;
17
+	/**
18
+	 * Query Builder instance.
19
+	 *
20
+	 * @var \Illuminate\Database\Query\Builder
21
+	 */
22
+	protected $query;
23 23
 
24
-    /**
25
-     * Command constructor.
26
-     *
27
-     * @param Aggregate                                                 $aggregate
28
-     * @param QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter $query
29
-     */
30
-    public function __construct(Aggregate $aggregate, Builder $query)
31
-    {
32
-        $this->aggregate = $aggregate;
24
+	/**
25
+	 * Command constructor.
26
+	 *
27
+	 * @param Aggregate                                                 $aggregate
28
+	 * @param QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter $query
29
+	 */
30
+	public function __construct(Aggregate $aggregate, Builder $query)
31
+	{
32
+		$this->aggregate = $aggregate;
33 33
 
34
-        $this->query = $query->from($aggregate->getEntityMap()->getTable());
35
-    }
34
+		$this->query = $query->from($aggregate->getEntityMap()->getTable());
35
+	}
36 36
 
37
-    abstract public function execute();
37
+	abstract public function execute();
38 38
 }
Please login to merge, or discard this patch.
src/Commands/Delete.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
 
7 7
 class Delete extends Command
8 8
 {
9
-    /**
10
-     * Execute the Delete Statement.
11
-     *
12
-     * @throws MappingException
13
-     * @throws \InvalidArgumentException
14
-     *
15
-     * @return false|void
16
-     */
17
-    public function execute()
18
-    {
19
-        $aggregate = $this->aggregate;
9
+	/**
10
+	 * Execute the Delete Statement.
11
+	 *
12
+	 * @throws MappingException
13
+	 * @throws \InvalidArgumentException
14
+	 *
15
+	 * @return false|void
16
+	 */
17
+	public function execute()
18
+	{
19
+		$aggregate = $this->aggregate;
20 20
 
21
-        $entity = $aggregate->getEntityObject();
21
+		$entity = $aggregate->getEntityObject();
22 22
 
23
-        $mapper = $aggregate->getMapper();
23
+		$mapper = $aggregate->getMapper();
24 24
 
25
-        if ($mapper->fireEvent('deleting', $entity) === false) {
26
-            return false;
27
-        }
25
+		if ($mapper->fireEvent('deleting', $entity) === false) {
26
+			return false;
27
+		}
28 28
 
29
-        $keyName = $aggregate->getEntityMap()->getKeyName();
29
+		$keyName = $aggregate->getEntityMap()->getKeyName();
30 30
 
31
-        $id = $this->aggregate->getEntityId();
31
+		$id = $this->aggregate->getEntityId();
32 32
 
33
-        if (is_null($id)) {
34
-            throw new MappingException('Executed a delete command on an entity with "null" as primary key');
35
-        }
33
+		if (is_null($id)) {
34
+			throw new MappingException('Executed a delete command on an entity with "null" as primary key');
35
+		}
36 36
 
37
-        $this->query->where($keyName, '=', $id)->delete();
37
+		$this->query->where($keyName, '=', $id)->delete();
38 38
 
39
-        $mapper->fireEvent('deleted', $entity, false);
39
+		$mapper->fireEvent('deleted', $entity, false);
40 40
 
41
-        // Once the Entity is successfully deleted, we'll just set the primary key to null.
42
-        $aggregate->setEntityAttribute($keyName, null);
43
-    }
41
+		// Once the Entity is successfully deleted, we'll just set the primary key to null.
42
+		$aggregate->setEntityAttribute($keyName, null);
43
+	}
44 44
 }
Please login to merge, or discard this patch.
src/MagicGetters.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -4,54 +4,54 @@
 block discarded – undo
4 4
 
5 5
 trait MagicGetters
6 6
 {
7
-    /**
8
-     * Contains the entity's attributes.
9
-     *
10
-     * @var array
11
-     */
12
-    protected $attributes = [];
7
+	/**
8
+	 * Contains the entity's attributes.
9
+	 *
10
+	 * @var array
11
+	 */
12
+	protected $attributes = [];
13 13
 
14
-    /**
15
-     * Dynamically retrieve attributes on the entity.
16
-     *
17
-     * @param string $key
18
-     *
19
-     * @return mixed
20
-     */
21
-    public function __get($key)
22
-    {
23
-        // When using mixed mapping, we will check
24
-        // for a class property corresponding to
25
-        // the attribute's key first.
26
-        //
27
-        // Note : this may raise issues as we may grant
28
-        // access to unwanted properties, like class dependencies.
29
-        //
30
-        // -> Solution would be to access the entityMap's $attributes, but we
31
-        // have to do this in a very efficient way.
32
-        //
33
-        // Manager::getEntityMap(get_class($this))->hasProperty()
34
-        //
35
-        // We could do the casting to array / json the same way, and it would
14
+	/**
15
+	 * Dynamically retrieve attributes on the entity.
16
+	 *
17
+	 * @param string $key
18
+	 *
19
+	 * @return mixed
20
+	 */
21
+	public function __get($key)
22
+	{
23
+		// When using mixed mapping, we will check
24
+		// for a class property corresponding to
25
+		// the attribute's key first.
26
+		//
27
+		// Note : this may raise issues as we may grant
28
+		// access to unwanted properties, like class dependencies.
29
+		//
30
+		// -> Solution would be to access the entityMap's $attributes, but we
31
+		// have to do this in a very efficient way.
32
+		//
33
+		// Manager::getEntityMap(get_class($this))->hasProperty()
34
+		//
35
+		// We could do the casting to array / json the same way, and it would
36 36
 
37
-        if (property_exists($this, $key)) {
38
-            return $this->$key;
39
-        }
37
+		if (property_exists($this, $key)) {
38
+			return $this->$key;
39
+		}
40 40
 
41
-        if (array_key_exists($key, $this->attributes)) {
42
-            return $this->attributes[$key];
43
-        }
44
-    }
41
+		if (array_key_exists($key, $this->attributes)) {
42
+			return $this->attributes[$key];
43
+		}
44
+	}
45 45
 
46
-    /**
47
-     * Determine if an attribute exists on the entity.
48
-     *
49
-     * @param string $key
50
-     *
51
-     * @return bool
52
-     */
53
-    public function __isset($key)
54
-    {
55
-        return array_key_exists($key, $this->attributes) || property_exists($this, $key);
56
-    }
46
+	/**
47
+	 * Determine if an attribute exists on the entity.
48
+	 *
49
+	 * @param string $key
50
+	 *
51
+	 * @return bool
52
+	 */
53
+	public function __isset($key)
54
+	{
55
+		return array_key_exists($key, $this->attributes) || property_exists($this, $key);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
src/AnalogueServiceProvider.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@
 block discarded – undo
13 13
  */
14 14
 class AnalogueServiceProvider extends ServiceProvider
15 15
 {
16
-    /**
17
-     * Indicates if loading of the provider is deferred.
18
-     *
19
-     * @var bool
20
-     */
21
-    protected $defer = false;
16
+	/**
17
+	 * Indicates if loading of the provider is deferred.
18
+	 *
19
+	 * @var bool
20
+	 */
21
+	protected $defer = false;
22 22
 
23
-    public function boot()
24
-    {
25
-        //
26
-    }
23
+	public function boot()
24
+	{
25
+		//
26
+	}
27 27
 
28
-    /**
29
-     * Register the service provider.
30
-     *
31
-     * @return void
32
-     */
33
-    public function register()
34
-    {
35
-        $this->app->singleton('analogue', function ($app) {
36
-            $db = $app['db'];
28
+	/**
29
+	 * Register the service provider.
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function register()
34
+	{
35
+		$this->app->singleton('analogue', function ($app) {
36
+			$db = $app['db'];
37 37
 
38
-            $connectionProvider = new IlluminateConnectionProvider($db);
38
+			$connectionProvider = new IlluminateConnectionProvider($db);
39 39
 
40
-            $illuminate = new IlluminateDriver($connectionProvider);
40
+			$illuminate = new IlluminateDriver($connectionProvider);
41 41
 
42
-            $driverManager = new DriverManager();
42
+			$driverManager = new DriverManager();
43 43
 
44
-            $driverManager->addDriver($illuminate);
44
+			$driverManager->addDriver($illuminate);
45 45
 
46
-            $event = $app->make('events');
46
+			$event = $app->make('events');
47 47
 
48
-            $manager = new Manager($driverManager, $event);
48
+			$manager = new Manager($driverManager, $event);
49 49
 
50
-            $manager->registerPlugin(\Analogue\ORM\Plugins\Timestamps\TimestampsPlugin::class);
51
-            $manager->registerPlugin(\Analogue\ORM\Plugins\SoftDeletes\SoftDeletesPlugin::class);
50
+			$manager->registerPlugin(\Analogue\ORM\Plugins\Timestamps\TimestampsPlugin::class);
51
+			$manager->registerPlugin(\Analogue\ORM\Plugins\SoftDeletes\SoftDeletesPlugin::class);
52 52
 
53
-            return $manager;
54
-        });
53
+			return $manager;
54
+		});
55 55
 
56
-        $this->app->bind(Manager::class, function ($app) {
57
-            return $app->make('analogue');
58
-        });
59
-    }
56
+		$this->app->bind(Manager::class, function ($app) {
57
+			return $app->make('analogue');
58
+		});
59
+	}
60 60
 
61
-    /**
62
-     * Get the services provided by the provider.
63
-     *
64
-     * @return array
65
-     */
66
-    public function provides()
67
-    {
68
-        return ['analogue'];
69
-    }
61
+	/**
62
+	 * Get the services provided by the provider.
63
+	 *
64
+	 * @return array
65
+	 */
66
+	public function provides()
67
+	{
68
+		return ['analogue'];
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function register()
34 34
     {
35
-        $this->app->singleton('analogue', function ($app) {
35
+        $this->app->singleton('analogue', function($app) {
36 36
             $db = $app['db'];
37 37
 
38 38
             $connectionProvider = new IlluminateConnectionProvider($db);
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             return $manager;
54 54
         });
55 55
 
56
-        $this->app->bind(Manager::class, function ($app) {
56
+        $this->app->bind(Manager::class, function($app) {
57 57
             return $app->make('analogue');
58 58
         });
59 59
     }
Please login to merge, or discard this patch.
src/Plugins/AnaloguePluginInterface.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@
 block discarded – undo
4 4
 
5 5
 interface AnaloguePluginInterface
6 6
 {
7
-    /**
8
-     * Boot the plugin.
9
-     *
10
-     * @return void
11
-     */
12
-    public function register();
7
+	/**
8
+	 * Boot the plugin.
9
+	 *
10
+	 * @return void
11
+	 */
12
+	public function register();
13 13
 
14
-    /**
15
-     * Get custom events provided by the plugin.
16
-     *
17
-     * @return array
18
-     */
19
-    public function getCustomEvents();
14
+	/**
15
+	 * Get custom events provided by the plugin.
16
+	 *
17
+	 * @return array
18
+	 */
19
+	public function getCustomEvents();
20 20
 }
Please login to merge, or discard this patch.
src/Plugins/AnaloguePlugin.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -6,34 +6,34 @@
 block discarded – undo
6 6
 
7 7
 abstract class AnaloguePlugin implements AnaloguePluginInterface
8 8
 {
9
-    /**
10
-     * Manager instance.
11
-     *
12
-     * @var Manager
13
-     */
14
-    protected $manager;
9
+	/**
10
+	 * Manager instance.
11
+	 *
12
+	 * @var Manager
13
+	 */
14
+	protected $manager;
15 15
 
16
-    /**
17
-     * AnaloguePlugin constructor.
18
-     *
19
-     * @param Manager $manager
20
-     */
21
-    public function __construct(Manager $manager)
22
-    {
23
-        $this->manager = $manager;
24
-    }
16
+	/**
17
+	 * AnaloguePlugin constructor.
18
+	 *
19
+	 * @param Manager $manager
20
+	 */
21
+	public function __construct(Manager $manager)
22
+	{
23
+		$this->manager = $manager;
24
+	}
25 25
 
26
-    /**
27
-     * Boot the plugin.
28
-     *
29
-     * @return void
30
-     */
31
-    abstract public function register();
26
+	/**
27
+	 * Boot the plugin.
28
+	 *
29
+	 * @return void
30
+	 */
31
+	abstract public function register();
32 32
 
33
-    /**
34
-     * Get custom events provided by the plugin.
35
-     *
36
-     * @return array
37
-     */
38
-    abstract public function getCustomEvents();
33
+	/**
34
+	 * Get custom events provided by the plugin.
35
+	 *
36
+	 * @return array
37
+	 */
38
+	abstract public function getCustomEvents();
39 39
 }
Please login to merge, or discard this patch.
src/Plugins/SoftDeletes/Restore.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,36 +6,36 @@
 block discarded – undo
6 6
 
7 7
 class Restore extends Command
8 8
 {
9
-    /**
10
-     * @throws \InvalidArgumentException
11
-     *
12
-     * @return false|mixed
13
-     */
14
-    public function execute()
15
-    {
16
-        $aggregate = $this->aggregate;
17
-        $entity = $aggregate->getEntityObject();
18
-        $mapper = $aggregate->getMapper();
19
-        $entityMap = $mapper->getEntityMap();
9
+	/**
10
+	 * @throws \InvalidArgumentException
11
+	 *
12
+	 * @return false|mixed
13
+	 */
14
+	public function execute()
15
+	{
16
+		$aggregate = $this->aggregate;
17
+		$entity = $aggregate->getEntityObject();
18
+		$mapper = $aggregate->getMapper();
19
+		$entityMap = $mapper->getEntityMap();
20 20
 
21
-        if ($mapper->fireEvent('restoring', $entity) === false) {
22
-            return false;
23
-        }
21
+		if ($mapper->fireEvent('restoring', $entity) === false) {
22
+			return false;
23
+		}
24 24
 
25
-        $keyName = $entityMap->getKeyName();
25
+		$keyName = $entityMap->getKeyName();
26 26
 
27
-        $query = $this->query->where($keyName, '=', $aggregate->getEntityAttribute($keyName));
27
+		$query = $this->query->where($keyName, '=', $aggregate->getEntityAttribute($keyName));
28 28
 
29
-        $deletedAtColumn = $entityMap->getQualifiedDeletedAtColumn();
29
+		$deletedAtColumn = $entityMap->getQualifiedDeletedAtColumn();
30 30
 
31
-        $query->update([$deletedAtColumn => null]);
31
+		$query->update([$deletedAtColumn => null]);
32 32
 
33
-        $aggregate->setEntityAttribute($deletedAtColumn, null);
33
+		$aggregate->setEntityAttribute($deletedAtColumn, null);
34 34
 
35
-        $mapper->fireEvent('restored', $entity, false);
35
+		$mapper->fireEvent('restored', $entity, false);
36 36
 
37
-        $mapper->getEntityCache()->refresh($aggregate);
37
+		$mapper->getEntityCache()->refresh($aggregate);
38 38
 
39
-        return $entity;
40
-    }
39
+		return $entity;
40
+	}
41 41
 }
Please login to merge, or discard this patch.
src/Entity.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -6,141 +6,141 @@
 block discarded – undo
6 6
 
7 7
 class Entity extends ValueObject
8 8
 {
9
-    /**
10
-     * Entities Hidden Attributes, that will be discarded when converting
11
-     * the entity to Array/Json
12
-     * (can include any embedded object's attribute).
13
-     *
14
-     * @var array
15
-     */
16
-    protected $hidden = [];
17
-
18
-    /**
19
-     * Return the entity's attribute.
20
-     *
21
-     * @param string $key
22
-     *
23
-     * @return mixed
24
-     */
25
-    public function __get($key)
26
-    {
27
-        if ($this->hasGetMutator($key)) {
28
-            $method = 'get'.$this->getMutatorMethod($key);
29
-
30
-            $attribute = null;
31
-
32
-            if (isset($this->attributes[$key])) {
33
-                $attribute = $this->attributes[$key];
34
-            }
35
-
36
-            return $this->$method($attribute);
37
-        }
38
-        if (!array_key_exists($key, $this->attributes)) {
39
-            return;
40
-        }
41
-        if ($this->attributes[$key] instanceof EntityProxy) {
42
-            $this->attributes[$key] = $this->attributes[$key]->load();
43
-        }
44
-
45
-        return $this->attributes[$key];
46
-    }
47
-
48
-    /**
49
-     * Dynamically set attributes on the entity.
50
-     *
51
-     * @param string $key
52
-     * @param mixed  $value
53
-     *
54
-     * @return void
55
-     */
56
-    public function __set($key, $value)
57
-    {
58
-        if ($this->hasSetMutator($key)) {
59
-            $method = 'set'.$this->getMutatorMethod($key);
60
-
61
-            $this->$method($value);
62
-        } else {
63
-            $this->attributes[$key] = $value;
64
-        }
65
-    }
66
-
67
-    /**
68
-     * Is a getter method defined ?
69
-     *
70
-     * @param string $key
71
-     *
72
-     * @return bool
73
-     */
74
-    protected function hasGetMutator($key)
75
-    {
76
-        return method_exists($this, 'get'.$this->getMutatorMethod($key)) ? true : false;
77
-    }
78
-
79
-    /**
80
-     * Is a setter method defined ?
81
-     *
82
-     * @param string $key
83
-     *
84
-     * @return bool
85
-     */
86
-    protected function hasSetMutator($key)
87
-    {
88
-        return method_exists($this, 'set'.$this->getMutatorMethod($key)) ? true : false;
89
-    }
90
-
91
-    /**
92
-     * @param $key
93
-     *
94
-     * @return string
95
-     */
96
-    protected function getMutatorMethod($key)
97
-    {
98
-        $key = ucwords(str_replace(['-', '_'], ' ', $key));
99
-
100
-        return str_replace(' ', '', $key).'Attribute';
101
-    }
102
-
103
-    /**
104
-     * Convert every attributes to value / arrays.
105
-     *
106
-     * @return array
107
-     */
108
-    public function toArray()
109
-    {
110
-        // First, call the trait method before filtering
111
-        // with Entity specific methods
112
-        $attributes = $this->attributesToArray($this->attributes);
113
-
114
-        foreach ($this->attributes as $key => $attribute) {
115
-            if (in_array($key, $this->hidden)) {
116
-                unset($attributes[$key]);
117
-                continue;
118
-            }
119
-            if ($this->hasGetMutator($key)) {
120
-                $method = 'get'.$this->getMutatorMethod($key);
121
-                $attributes[$key] = $this->$method($attribute);
122
-            }
123
-        }
124
-
125
-        return $attributes;
126
-    }
127
-
128
-    /**
129
-     * Fill an entity with key-value pairs.
130
-     *
131
-     * @param array $attributes
132
-     *
133
-     * @return void
134
-     */
135
-    public function fill(array $attributes)
136
-    {
137
-        foreach ($attributes as $key => $attribute) {
138
-            if ($this->hasSetMutator($key)) {
139
-                $method = 'set'.$this->getMutatorMethod($key);
140
-                $this->attributes[$key] = $this->$method($attribute);
141
-            } else {
142
-                $this->attributes[$key] = $attribute;
143
-            }
144
-        }
145
-    }
9
+	/**
10
+	 * Entities Hidden Attributes, that will be discarded when converting
11
+	 * the entity to Array/Json
12
+	 * (can include any embedded object's attribute).
13
+	 *
14
+	 * @var array
15
+	 */
16
+	protected $hidden = [];
17
+
18
+	/**
19
+	 * Return the entity's attribute.
20
+	 *
21
+	 * @param string $key
22
+	 *
23
+	 * @return mixed
24
+	 */
25
+	public function __get($key)
26
+	{
27
+		if ($this->hasGetMutator($key)) {
28
+			$method = 'get'.$this->getMutatorMethod($key);
29
+
30
+			$attribute = null;
31
+
32
+			if (isset($this->attributes[$key])) {
33
+				$attribute = $this->attributes[$key];
34
+			}
35
+
36
+			return $this->$method($attribute);
37
+		}
38
+		if (!array_key_exists($key, $this->attributes)) {
39
+			return;
40
+		}
41
+		if ($this->attributes[$key] instanceof EntityProxy) {
42
+			$this->attributes[$key] = $this->attributes[$key]->load();
43
+		}
44
+
45
+		return $this->attributes[$key];
46
+	}
47
+
48
+	/**
49
+	 * Dynamically set attributes on the entity.
50
+	 *
51
+	 * @param string $key
52
+	 * @param mixed  $value
53
+	 *
54
+	 * @return void
55
+	 */
56
+	public function __set($key, $value)
57
+	{
58
+		if ($this->hasSetMutator($key)) {
59
+			$method = 'set'.$this->getMutatorMethod($key);
60
+
61
+			$this->$method($value);
62
+		} else {
63
+			$this->attributes[$key] = $value;
64
+		}
65
+	}
66
+
67
+	/**
68
+	 * Is a getter method defined ?
69
+	 *
70
+	 * @param string $key
71
+	 *
72
+	 * @return bool
73
+	 */
74
+	protected function hasGetMutator($key)
75
+	{
76
+		return method_exists($this, 'get'.$this->getMutatorMethod($key)) ? true : false;
77
+	}
78
+
79
+	/**
80
+	 * Is a setter method defined ?
81
+	 *
82
+	 * @param string $key
83
+	 *
84
+	 * @return bool
85
+	 */
86
+	protected function hasSetMutator($key)
87
+	{
88
+		return method_exists($this, 'set'.$this->getMutatorMethod($key)) ? true : false;
89
+	}
90
+
91
+	/**
92
+	 * @param $key
93
+	 *
94
+	 * @return string
95
+	 */
96
+	protected function getMutatorMethod($key)
97
+	{
98
+		$key = ucwords(str_replace(['-', '_'], ' ', $key));
99
+
100
+		return str_replace(' ', '', $key).'Attribute';
101
+	}
102
+
103
+	/**
104
+	 * Convert every attributes to value / arrays.
105
+	 *
106
+	 * @return array
107
+	 */
108
+	public function toArray()
109
+	{
110
+		// First, call the trait method before filtering
111
+		// with Entity specific methods
112
+		$attributes = $this->attributesToArray($this->attributes);
113
+
114
+		foreach ($this->attributes as $key => $attribute) {
115
+			if (in_array($key, $this->hidden)) {
116
+				unset($attributes[$key]);
117
+				continue;
118
+			}
119
+			if ($this->hasGetMutator($key)) {
120
+				$method = 'get'.$this->getMutatorMethod($key);
121
+				$attributes[$key] = $this->$method($attribute);
122
+			}
123
+		}
124
+
125
+		return $attributes;
126
+	}
127
+
128
+	/**
129
+	 * Fill an entity with key-value pairs.
130
+	 *
131
+	 * @param array $attributes
132
+	 *
133
+	 * @return void
134
+	 */
135
+	public function fill(array $attributes)
136
+	{
137
+		foreach ($attributes as $key => $attribute) {
138
+			if ($this->hasSetMutator($key)) {
139
+				$method = 'set'.$this->getMutatorMethod($key);
140
+				$this->attributes[$key] = $this->$method($attribute);
141
+			} else {
142
+				$this->attributes[$key] = $attribute;
143
+			}
144
+		}
145
+	}
146 146
 }
Please login to merge, or discard this patch.