Skip to content

Commit efc4e25

Browse files
committed
[crud] add return types in CRUD base classes
1 parent 90a963a commit efc4e25

File tree

7 files changed

+62
-50
lines changed

7 files changed

+62
-50
lines changed

src/Ubiquity/controllers/auth/AuthFiles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function getViewRecovery(): string {
121121
/**
122122
* To override
123123
* Returns the base template filename, default : null
124+
* @return string|null
124125
*/
125126
public function getBaseTemplate() {
126127
return;

src/Ubiquity/controllers/crud/CRUDDatas.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ public function __construct($controller) {
2525
/**
2626
* Returns the table names to display in the left admin menu
2727
*/
28-
public function getTableNames() {
28+
public function getTableNames():array {
2929
return DAO::$db->getTablesName ();
3030
}
3131

3232
/**
3333
* Returns the fields to display in the showModel action for $model (DataTable)
3434
*
3535
* @param string $model
36+
* @return array
3637
*/
37-
public function getFieldNames($model) {
38+
public function getFieldNames(string $model): array {
3839
return OrmUtils::getSerializableMembers ( $model );
3940
}
4041

@@ -43,26 +44,29 @@ public function getFieldNames($model) {
4344
*
4445
* @param string $model
4546
* @param object $instance
47+
* @return array
4648
*/
47-
public function getFormFieldNames($model, $instance) {
49+
public function getFormFieldNames(string $model, $instance): array {
4850
return OrmUtils::getFormAllFields ( $model );
4951
}
5052

5153
/**
5254
* Returns the fields to use in search queries
5355
*
5456
* @param string $model
57+
* @return array
5558
*/
56-
public function getSearchFieldNames($model) {
59+
public function getSearchFieldNames(string $model): array {
5760
return OrmUtils::getSerializableFields ( $model );
5861
}
5962

6063
/**
6164
* Returns the fields for displaying an instance of $model (DataElement)
6265
*
6366
* @param string $model
67+
* @return array
6468
*/
65-
public function getElementFieldNames($model) {
69+
public function getElementFieldNames(string $model): array {
6670
return OrmUtils::getMembers ( $model );
6771
}
6872

@@ -74,7 +78,7 @@ public function getElementFieldNames($model) {
7478
* @param string $member The member associated with a manyToMany relation
7579
* @return array
7680
*/
77-
public function getManyToManyDatas($fkClass, $instance, $member) {
81+
public function getManyToManyDatas($fkClass, $instance, $member): array {
7882
return DAO::getAll ( $fkClass, "", false );
7983
}
8084

@@ -86,7 +90,7 @@ public function getManyToManyDatas($fkClass, $instance, $member) {
8690
* @param string $member The member associated with a manyToOne relation
8791
* @return array
8892
*/
89-
public function getManyToOneDatas($fkClass, $instance, $member) {
93+
public function getManyToOneDatas($fkClass, $instance, $member):array {
9094
return DAO::getAll ( $fkClass, "", false );
9195
}
9296

@@ -98,31 +102,31 @@ public function getManyToOneDatas($fkClass, $instance, $member) {
98102
* @param string $member The member associated with a oneToMany relation
99103
* @return array
100104
*/
101-
public function getOneToManyDatas($fkClass, $instance, $member) {
105+
public function getOneToManyDatas($fkClass, $instance, $member):array {
102106
return DAO::getAll ( $fkClass, "", false );
103107
}
104108

105109
/**
106110
*
107111
* @return boolean
108112
*/
109-
public function getUpdateOneToManyInForm() {
113+
public function getUpdateOneToManyInForm(): bool {
110114
return false;
111115
}
112116

113117
/**
114118
*
115119
* @return boolean
116120
*/
117-
public function getUpdateManyToManyInForm() {
121+
public function getUpdateManyToManyInForm(): bool {
118122
return true;
119123
}
120124

121125
/**
122126
*
123127
* @return boolean
124128
*/
125-
public function getUpdateManyToOneInForm() {
129+
public function getUpdateManyToOneInForm(): bool {
126130
return true;
127131
}
128132

@@ -131,7 +135,7 @@ public function getUpdateManyToOneInForm() {
131135
*
132136
* @return boolean
133137
*/
134-
public function refreshPartialInstance() {
138+
public function refreshPartialInstance(): bool {
135139
return true;
136140
}
137141

@@ -142,7 +146,7 @@ public function refreshPartialInstance() {
142146
* @param string $model
143147
* @return string
144148
*/
145-
public function _getInstancesFilter($model) {
149+
public function _getInstancesFilter(string $model): string {
146150
return "1=1";
147151
}
148152
}

src/Ubiquity/controllers/crud/CRUDFiles.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(string $viewBase='@framework/crud') {
2626
*
2727
* @return string
2828
*/
29-
public function getViewIndex() {
29+
public function getViewIndex():string {
3030
return $this->viewBase . '/index.html';
3131
}
3232

@@ -36,7 +36,7 @@ public function getViewIndex() {
3636
*
3737
* @return string
3838
*/
39-
public function getViewHome(){
39+
public function getViewHome(): string {
4040
return $this->viewBase . '/home.html';
4141
}
4242

@@ -46,7 +46,7 @@ public function getViewHome(){
4646
*
4747
* @return string
4848
*/
49-
public function getViewItemHome(){
49+
public function getViewItemHome(): string {
5050
return $this->viewBase . '/itemHome.html';
5151
}
5252

@@ -56,7 +56,7 @@ public function getViewItemHome(){
5656
*
5757
* @return string
5858
*/
59-
public function getViewNav(){
59+
public function getViewNav(): string {
6060
return $this->viewBase . '/nav.html';
6161
}
6262

@@ -66,7 +66,7 @@ public function getViewNav(){
6666
*
6767
* @return string
6868
*/
69-
public function getViewForm() {
69+
public function getViewForm(): string {
7070
return $this->viewBase . '/form.html';
7171
}
7272

@@ -76,7 +76,7 @@ public function getViewForm() {
7676
*
7777
* @return string
7878
*/
79-
public function getViewDisplay() {
79+
public function getViewDisplay(): string {
8080
return $this->viewBase . '/display.html';
8181
}
8282

@@ -85,13 +85,14 @@ public function getViewDisplay() {
8585
*
8686
* @return string
8787
*/
88-
public function getViewBaseTemplate() {
88+
public function getViewBaseTemplate(): string {
8989
return $this->viewBase . '/baseTemplate.html';
9090
}
9191

9292
/**
9393
* To override
9494
* Returns the base template filename, default : null
95+
* @return string|null
9596
*/
9697
public function getBaseTemplate() {
9798
return;

src/Ubiquity/controllers/crud/CRUDMessage.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,36 @@ public function __construct($message,$title="",$type="",$icon="",$timeout=null){
2222
/**
2323
* @return string
2424
*/
25-
public function getMessage() {
25+
public function getMessage(): string {
2626
return $this->_message;
2727
}
2828

2929
/**
3030
* @return string
3131
*/
32-
public function getType() {
32+
public function getType(): string {
3333
return $this->type;
3434
}
3535

3636
/**
3737
* @return mixed
3838
*/
39-
public function getIcon() {
39+
public function getIcon(): string {
4040
return $this->icon;
4141
}
4242

4343
/**
4444
* @return string
4545
*/
46-
public function getTitle() {
46+
public function getTitle(): string {
4747
return $this->title;
4848
}
4949

5050
/**
5151
* @param string $message
52+
* @return CRUDMessage
5253
*/
53-
public function setMessage($message) {
54+
public function setMessage(string $message): CRUDMessage {
5455
$this->_message = $message;
5556
$this->message=$message;
5657
return $this;
@@ -60,7 +61,7 @@ public function setMessage($message) {
6061
* @param string $type
6162
* @return $this
6263
*/
63-
public function setType($type) {
64+
public function setType(string $type): CRUDMessage {
6465
$this->type = $type;
6566
return $this;
6667
}
@@ -69,7 +70,7 @@ public function setType($type) {
6970
* @param string $icon
7071
* @return $this
7172
*/
72-
public function setIcon($icon) {
73+
public function setIcon(string $icon): CRUDMessage {
7374
$this->icon = $icon;
7475
return $this;
7576
}
@@ -78,37 +79,42 @@ public function setIcon($icon) {
7879
* @param string $title
7980
* @return $this
8081
*/
81-
public function setTitle($title) {
82+
public function setTitle(string $title): CRUDMessage {
8283
$this->title = $title;
8384
return $this;
8485
}
8586

8687
/**
8788
* @return integer
8889
*/
89-
public function getTimeout() {
90+
public function getTimeout(): ?int {
9091
return $this->timeout;
9192
}
9293

9394
/**
9495
* @param integer $timeout
9596
* @return $this
9697
*/
97-
public function setTimeout($timeout) {
98+
public function setTimeout(int $timeout): CRUDMessage {
9899
$this->timeout = $timeout;
99100
return $this;
100101
}
102+
101103
/**
102-
*
104+
*
103105
* @param string $value
104106
* @return $this
105107
*/
106-
public function parse($value){
107-
$this->_message=str_replace("{value}", $value, $this->message);
108+
public function parse(string $value): CRUDMessage {
109+
$this->_message=\str_replace("{value}", $value, $this->message);
108110
return $this;
109111
}
110-
111-
public function parseContent($keyValues){
112+
113+
/**
114+
* @param array $keyValues
115+
* @return $this
116+
*/
117+
public function parseContent(array $keyValues): CRUDMessage {
112118
$msg=$this->_message;
113119
foreach ($keyValues as $key=>$value){
114120
$msg=str_replace("{".$key."}", $value, $msg);

src/Ubiquity/controllers/crud/viewers/ModelViewer.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function setStyle($elm) {
6262
* @param boolean $modal
6363
* @return \Ajax\semantic\widgets\dataelement\DataElement
6464
*/
65-
public function getModelDataElement($instance, $model, $modal) {
65+
public function getModelDataElement($instance, $model, $modal): \Ajax\semantic\widgets\dataelement\DataElement {
6666
$semantic = $this->jquery->semantic ();
6767
$fields = $this->controller->_getAdminData ()->getElementFieldNames ( $model );
6868

@@ -93,7 +93,7 @@ public function getModelDataElement($instance, $model, $modal) {
9393
* @param array $captions
9494
* @param string $className
9595
*/
96-
public function getElementCaptions($captions, $className, $instance) {
96+
public function getElementCaptions($captions, $className, $instance): array {
9797
return \array_map ( 'ucfirst', $captions );
9898
}
9999

@@ -104,7 +104,7 @@ public function getElementCaptions($captions, $className, $instance) {
104104
* @param string $model model class name (long name)
105105
* @return DataTable
106106
*/
107-
public function getModelDataTable($instances, $model, $totalCount, $page = 1) {
107+
public function getModelDataTable($instances, $model, $totalCount, $page = 1): DataTable {
108108
$adminRoute = $this->controller->_getBaseRoute ();
109109
$files = $this->controller->_getFiles ();
110110
$dataTable = $this->getDataTableInstance ( $instances, $model, $totalCount, $page );
@@ -170,9 +170,10 @@ public function addEditMemberFonctionality($part) {
170170
* @return void|number default : 6
171171
*/
172172
public function recordsPerPage($model, $totalCount = 0) {
173-
if ($totalCount > 6)
173+
if ($totalCount > 6) {
174174
return 6;
175-
return;
175+
}
176+
return;
176177
}
177178

178179
/**
@@ -217,7 +218,7 @@ protected function getDataTableInstance($instances, $model, $totalCount, $page =
217218
*
218219
* @return string[]
219220
*/
220-
protected function getDataTableRowButtons() {
221+
protected function getDataTableRowButtons(): array {
221222
return [ 'edit','delete' ];
222223
}
223224

@@ -256,11 +257,11 @@ public function addAllButtons(DataTable $dataTable, $attributes) {
256257
*
257258
* @return string
258259
*/
259-
public function getTransition() {
260+
public function getTransition(): string {
260261
return 'fade';
261262
}
262263

263-
public function getDataTableId() {
264+
public function getDataTableId(): string {
264265
return 'lv';
265266
}
266267

@@ -288,7 +289,7 @@ public function onConfirmButtons(HtmlButton $confirmBtn, HtmlButton $cancelBtn)
288289
* @param array $captions
289290
* @param string $className
290291
*/
291-
public function getCaptions($captions, $className) {
292+
public function getCaptions($captions, $className):array {
292293
return \array_map ( 'ucfirst', $captions );
293294
}
294295

@@ -471,7 +472,7 @@ public function getFkElement($member, $className, $object) {
471472
*
472473
* @return boolean Return true if you want to see details
473474
*/
474-
public function showDetailsOnDataTableClick() {
475+
public function showDetailsOnDataTableClick(): bool {
475476
return true;
476477
}
477478
}

0 commit comments

Comments
 (0)