1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hechoenlaravel\JarvisFoundation\Traits; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Trait EntryManager |
7
|
|
|
* Use this trait to manage entries for the entities |
8
|
|
|
* @author Jose Luis Fonseca <[email protected]> |
9
|
|
|
* @package Hechoenlaravel\JarvisFoundation\Traits |
10
|
|
|
*/ |
11
|
|
|
trait EntryManager |
12
|
|
|
{ |
13
|
|
|
use DispatchesCommands; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param $entityId |
17
|
|
|
* @param array $input |
18
|
|
|
* @return mixed |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
public function createEntry($entityId, array $input = []) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$input['entity'] = $entityId; |
23
|
|
|
return $this->execute('Hechoenlaravel\JarvisFoundation\Entries\CreateEntryCommand', |
24
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Handler\CreateEntryCommandHandler', $input, [ |
25
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\SetEntity', |
26
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\ValidateEntryData', |
27
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\FilterFieldFromInput', |
28
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\RunPreSaveEvent' |
29
|
|
|
]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param $entityId |
34
|
|
|
* @param array $input |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function updateEntry($entityId, $entryId, array $input = []) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$input['entity'] = $entityId; |
40
|
|
|
$input['entry_id'] = $entryId; |
41
|
|
|
return $this->execute('Hechoenlaravel\JarvisFoundation\Entries\UpdateEntryCommand', |
42
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Handler\UpdateEntryCommandHandler', $input, [ |
43
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\SetEntity', |
44
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\ValidateEntryData', |
45
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\FilterFieldFromInput', |
46
|
|
|
'Hechoenlaravel\JarvisFoundation\Entries\Middleware\RunPreSaveEvent' |
47
|
|
|
]); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
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.