Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Clud | |
0.00% |
0 / 13 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
create | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
load | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
update | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
delete | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\WikispeechSpeechDataCollector\Crud; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent; |
12 | |
13 | /** |
14 | * Convenience class used to create, load, update and delete any {@link Persistent} instance. |
15 | * @since 0.1.0 |
16 | */ |
17 | class Clud { |
18 | |
19 | /** |
20 | * @var CrudFactory Reused instance to save a couple of clock ticks. |
21 | * @note Consider implementing a flyweight pattern to reuse CRUDs returned by CrudFactory. |
22 | * That should probably be implemented as a reusable decorated CrudFactory |
23 | * rather than implemented directly in this class. |
24 | */ |
25 | private $crudFactory; |
26 | |
27 | /** |
28 | * @param CrudFactory $crudFactory |
29 | */ |
30 | public function __construct( |
31 | CrudFactory $crudFactory |
32 | ) { |
33 | $this->crudFactory = $crudFactory; |
34 | } |
35 | |
36 | /** |
37 | * Will set new identity using {@link Persistent::setIdentity()}. |
38 | * @param Persistent $instance Instance to be inserted to the persistent layer. |
39 | */ |
40 | public function create( Persistent $instance ) { |
41 | $instance |
42 | ->accept( $this->crudFactory ) |
43 | ->create( $instance ); |
44 | } |
45 | |
46 | /** |
47 | * Expects identity is available via {@link Persistent::getIdentity()}. |
48 | * @param Persistent $instance Object instance to be loaded from persistent layer. |
49 | * Identity must be set. |
50 | * @return bool true if found, false if not found. |
51 | */ |
52 | public function load( Persistent $instance ): bool { |
53 | return $instance |
54 | ->accept( $this->crudFactory ) |
55 | ->load( $instance ); |
56 | } |
57 | |
58 | /** |
59 | * @param Persistent $instance Object instance to be updated in persistent layer. |
60 | */ |
61 | public function update( Persistent $instance ): void { |
62 | $instance |
63 | ->accept( $this->crudFactory ) |
64 | ->update( $instance ); |
65 | } |
66 | |
67 | /** |
68 | * @param Persistent $instance Object instance to be updated in persistent layer. |
69 | */ |
70 | public function delete( Persistent $instance ): void { |
71 | $instance |
72 | ->accept( $this->crudFactory ) |
73 | ->delete( $instance->getIdentity() ); |
74 | } |
75 | } |