Skip to content

Commit bf427fb

Browse files
committed
Cleanup API
1 parent e87f354 commit bf427fb

10 files changed

Lines changed: 37 additions & 52 deletions

src/View/Helper/CommonHelper.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function sp(string $singular, string $plural, int $count, bool $autoTrans
4949
* @param array<string>|string|null $type - private/public or array of index/follow/archtive,...
5050
* @return string HTML
5151
*/
52-
public function metaRobots($type = null): string {
52+
public function metaRobots(array|string|null $type = null): string {
5353
$meta = Configure::read('Config.robots');
5454
if ($type === null && $meta !== null) {
5555
$type = $meta;
@@ -78,7 +78,7 @@ public function metaRobots($type = null): string {
7878
* @param array<string>|string|null $content If array, it will be separated by commas
7979
* @return string HTML Markup
8080
*/
81-
public function metaName(?string $name = null, $content = null): string {
81+
public function metaName(?string $name = null, array|string|null $content = null): string {
8282
if (!$name || !$content) {
8383
return '';
8484
}
@@ -115,7 +115,7 @@ public function metaDescription(string $content, ?string $language = null, array
115115
* @param bool $escape
116116
* @return string HTML Markup
117117
*/
118-
public function metaKeywords($keywords = null, ?string $language = null, bool $escape = true): string {
118+
public function metaKeywords(array|string|null $keywords = null, ?string $language = null, bool $escape = true): string {
119119
if ($keywords === null) {
120120
$keywords = Configure::read('Config.keywords');
121121
}
@@ -142,7 +142,7 @@ public function metaKeywords($keywords = null, ?string $language = null, bool $e
142142
* @param bool $full
143143
* @return string HTML Markup
144144
*/
145-
public function metaCanonical($url = null, bool $full = false): string {
145+
public function metaCanonical(array|string|null $url = null, bool $full = false): string {
146146
$canonical = $this->Url->build($url, ['fullBase' => $full]);
147147
$options = ['rel' => 'canonical', 'link' => $canonical];
148148

@@ -152,7 +152,7 @@ public function metaCanonical($url = null, bool $full = false): string {
152152
/**
153153
* Convenience method for "alternate" SEO links
154154
*
155-
* @param array|string $url
155+
* @param array|string|null $url
156156
* @param array|string $lang (lang(iso2) or array of langs)
157157
* lang: language (in ISO 6391-1 format) + optionally the region (in ISO 3166-1 Alpha 2 format)
158158
* - de
@@ -161,7 +161,7 @@ public function metaCanonical($url = null, bool $full = false): string {
161161
* @param bool $full
162162
* @return string HTML Markup
163163
*/
164-
public function metaAlternate($url, $lang, bool $full = false): string {
164+
public function metaAlternate(array|string|null $url, array|string $lang, bool $full = false): string {
165165
$url = $this->Url->build($url, ['fullBase' => $full]);
166166
$lang = (array)$lang;
167167
$res = [];
@@ -185,11 +185,11 @@ public function metaAlternate($url, $lang, bool $full = false): string {
185185
/**
186186
* Convenience method for META Tags
187187
*
188-
* @param array|string $url
188+
* @param array|string|null $url
189189
* @param string|null $title
190190
* @return string HTML Markup
191191
*/
192-
public function metaRss($url, ?string $title = null): string {
192+
public function metaRss(array|string|null $url, ?string $title = null): string {
193193
$tags = [
194194
'meta' => '<link rel="alternate" type="application/rss+xml" title="%s" href="%s">',
195195
];

src/View/Helper/FormatHelper.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(View $View, array $config = []) {
6464
* @param array<string, mixed> $attributes
6565
* @return string
6666
*/
67-
public function thumbs($value, array $options = [], array $attributes = []) {
67+
public function thumbs($value, array $options = [], array $attributes = []): string {
6868
$icon = !empty($value) ? 'pro' : 'contra';
6969

7070
return $this->Icon->render($icon, $options, $attributes);
@@ -81,7 +81,7 @@ public function thumbs($value, array $options = [], array $attributes = []) {
8181
* - titleField: field or `Model.field`
8282
* @return string
8383
*/
84-
public function neighbors(array $neighbors, $field, array $options = []) {
84+
public function neighbors(array $neighbors, string $field, array $options = []): string {
8585
$name = 'Record'; // Translation further down!
8686
if (!empty($options['name'])) {
8787
$name = ucfirst($options['name']);
@@ -159,7 +159,7 @@ public function neighbors(array $neighbors, $field, array $options = []) {
159159
* @param array<string, mixed> $attributes
160160
* @return string
161161
*/
162-
public function genderIcon($value, array $options = [], array $attributes = []) {
162+
public function genderIcon($value, array $options = [], array $attributes = []): string {
163163
$value = (int)$value;
164164
if ($value == static::GENDER_FEMALE) {
165165
$icon = $this->Icon->render('female', $options, $attributes);
@@ -182,22 +182,7 @@ public function genderIcon($value, array $options = [], array $attributes = [])
182182
* - class, ...
183183
* @return string
184184
*/
185-
public function cIcon($icon, array $options = [], array $attributes = []) {
186-
return $this->_customIcon($icon, $options, $attributes);
187-
}
188-
189-
/**
190-
* Deprecated img icons, font icons should be used instead, but sometimes
191-
* we still need a custom img icon.
192-
*
193-
* @param string $icon (constant or filename)
194-
* @param array<string, mixed> $options :
195-
* - translate, title, ...
196-
* @param array<string, mixed> $attributes :
197-
* - class, ...
198-
* @return string
199-
*/
200-
protected function _customIcon($icon, array $options = [], array $attributes = []) {
185+
public function cIcon($icon, array $options = [], array $attributes = []): string {
201186
$translate = $options['translate'] ?? true;
202187

203188
$type = pathinfo($icon, PATHINFO_FILENAME);
@@ -232,7 +217,7 @@ protected function _customIcon($icon, array $options = [], array $attributes = [
232217
* - title, ...
233218
* @return string HTML icon Yes/No
234219
*/
235-
public function yesNo($value, array $options = [], array $attributes = []) {
220+
public function yesNo($value, array $options = [], array $attributes = []): string {
236221
$defaults = [
237222
'on' => 1,
238223
'onTitle' => __d('tools', 'Yes'),

src/View/Helper/GravatarHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct(View $View, array $config = []) {
8080
* @param array<string, mixed> $options Array of options, keyed from default settings
8181
* @return string Gravatar image string
8282
*/
83-
public function image($email, array $options = []) {
83+
public function image(string $email, array $options = []): string {
8484
$imageOptions = $options += [
8585
'escape' => false,
8686
];
@@ -99,7 +99,7 @@ public function image($email, array $options = []) {
9999
* @param array<string, mixed> $options Array of options, keyed from default settings
100100
* @return string Gravatar Image URL
101101
*/
102-
public function url($email, array $options = []) {
102+
public function url(string $email, array $options = []): string {
103103
$options = $this->_cleanOptions($options + $this->_config);
104104
$options += [
105105
'escape' => true,
@@ -182,7 +182,7 @@ protected function _emailHash($email) {
182182
* @param array<string, mixed> $options Array of options, keyed from default settings
183183
* @return string URL string of options
184184
*/
185-
protected function _buildOptions($options = []) {
185+
protected function _buildOptions(array $options = []): string {
186186
$gravatarOptions = array_intersect(array_keys($options), array_keys($this->_defaultConfig));
187187
if (!empty($gravatarOptions)) {
188188
$optionArray = [];

src/View/Helper/HtmlTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait HtmlTrait {
1515
* @param array<string, mixed> $options Attributes
1616
* @return string HTML image tag
1717
*/
18-
public function imageFromBlob($content, array $options = []) {
18+
public function imageFromBlob(string $content, array $options = []): string {
1919
$options += ['type' => 'png'];
2020
$mimeType = 'image/' . $options['type'];
2121

@@ -38,13 +38,13 @@ public function imageFromBlob($content, array $options = []) {
3838
* over value of `escape`)
3939
* - `confirm` JavaScript confirmation message.
4040
*
41-
* @param string $title The content to be wrapped by <a> tags.
41+
* @param array|string $title The content to be wrapped by <a> tags.
4242
* @param array|string|null $url URL or array of URL parameters, or
4343
* external URL (starts with http://)
4444
* @param array<string, mixed> $options Array of options and HTML attributes.
4545
* @return string An `a` HTML element.
4646
*/
47-
public function linkReset($title, $url = null, array $options = []) {
47+
public function linkReset(array|string $title, array|string|null $url = null, array $options = []): string {
4848
if (is_array($url)) {
4949
$url += ['prefix' => false, 'plugin' => false];
5050
}
@@ -63,13 +63,13 @@ public function linkReset($title, $url = null, array $options = []) {
6363
* over value of `escape`)
6464
* - `confirm` JavaScript confirmation message.
6565
*
66-
* @param string $title The content to be wrapped by <a> tags.
66+
* @param array|string $title The content to be wrapped by <a> tags.
6767
* @param array|string|null $url URL or array of URL parameters, or
6868
* external URL (starts with http://)
6969
* @param array<string, mixed> $options Array of options and HTML attributes.
7070
* @return string An `a` HTML element.
7171
*/
72-
public function linkComplete($title, $url = null, array $options = []) {
72+
public function linkComplete(array|string $title, array|string|null $url = null, array $options = []): string {
7373
if (is_array($url)) {
7474
// Add query strings
7575
if (!isset($url['?'])) {

src/View/Helper/IconHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function names(): array {
6060
* - class, ...
6161
* @return string
6262
*/
63-
public function render(string $icon, array $options = [], array $attributes = []) {
63+
public function render(string $icon, array $options = [], array $attributes = []): string {
6464
return $this->collection->render($icon, $options, $attributes);
6565
}
6666

src/View/Helper/MeterHelper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function calculatePercentage($total, $is) {
127127
* @param array<string, mixed> $attributes
128128
* @return string
129129
*/
130-
public function meterBar($value, $max, $min, $length, array $options = [], array $attributes = []) {
130+
public function meterBar($value, $max, $min, int $length, array $options = [], array $attributes = []): string {
131131
$defaults = [
132132
'overflow' => false,
133133
];
@@ -155,7 +155,7 @@ public function meterBar($value, $max, $min, $length, array $options = [], array
155155
* @throws \InvalidArgumentException
156156
* @return string
157157
*/
158-
public function draw($complete, $length) {
158+
public function draw($complete, int $length) {
159159
if ($length < static::LENGTH_MIN) {
160160
throw new InvalidArgumentException('Min length for such a progress bar is ' . static::LENGTH_MIN);
161161
}
@@ -180,7 +180,7 @@ public function draw($complete, $length) {
180180
* @param int $length
181181
* @return int
182182
*/
183-
protected function calculateBarLength($complete, $length) {
183+
protected function calculateBarLength($complete, int $length): int {
184184
$barLength = (int)round($length * $complete, 0);
185185

186186
return $barLength;
@@ -200,7 +200,7 @@ protected function calculateBarLength($complete, $length) {
200200
* @throws \InvalidArgumentException
201201
* @return float
202202
*/
203-
protected function prepareValue($value, $max, $min, $overflow) {
203+
protected function prepareValue($value, $max, $min, bool $overflow) {
204204
if ($max < $min) {
205205
throw new InvalidArgumentException('Max needs to be larger than Min.');
206206
}
@@ -227,7 +227,7 @@ protected function prepareValue($value, $max, $min, $overflow) {
227227
* @param bool $overflow
228228
* @return float
229229
*/
230-
protected function prepareMax($value, $max, $overflow) {
230+
protected function prepareMax($value, $max, bool $overflow) {
231231
if ($value <= $max) {
232232
return $max;
233233
}
@@ -251,7 +251,7 @@ protected function prepareMax($value, $max, $overflow) {
251251
* @param bool $overflow
252252
* @return float
253253
*/
254-
protected function prepareMin($value, $min, $overflow) {
254+
protected function prepareMin($value, $min, bool $overflow) {
255255
if ($value > $min) {
256256
return $min;
257257
}

src/View/Helper/ProgressHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(View $View, array $config = []) {
7373
* @param array<string, mixed> $attributes
7474
* @return string
7575
*/
76-
public function htmlProgressBar($value, array $options = [], array $attributes = []) {
76+
public function htmlProgressBar($value, array $options = [], array $attributes = []): string {
7777
$defaults = [
7878
'fallbackHtml' => null,
7979
];
@@ -101,7 +101,7 @@ public function htmlProgressBar($value, array $options = [], array $attributes =
101101
* @param array<string, mixed> $attributes
102102
* @return string
103103
*/
104-
public function progressBar($value, $length, array $attributes = []) {
104+
public function progressBar($value, int $length, array $attributes = []): string {
105105
$bar = $this->draw($value, $length);
106106

107107
$attributes += [
@@ -119,7 +119,7 @@ public function progressBar($value, $length, array $attributes = []) {
119119
* @throws \InvalidArgumentException
120120
* @return string
121121
*/
122-
public function draw($complete, $length) {
122+
public function draw($complete, int $length): string {
123123
if ($complete < 0.0 || $complete > 1.0) {
124124
throw new InvalidArgumentException('Min/Max overflow for value `' . $complete . '` (0...1)');
125125
}
@@ -174,7 +174,7 @@ public function roundPercentage($percentage) {
174174
* @param int $length
175175
* @return int
176176
*/
177-
protected function calculateBarLength($complete, $length) {
177+
protected function calculateBarLength($complete, int $length): int {
178178
$barLength = (int)round($length * $complete, 0);
179179
if ($barLength === 0 && $complete > 0.0) {
180180
$barLength = 1;

src/View/Helper/TimeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Wrapper for TimeHelper and TimeLib
1313
*
14-
* @mixin \Tools\Utility\DateTime
14+
* @mixin \Tools\I18n\DateTime
1515
* @property \Cake\View\Helper\HtmlHelper $Html
1616
*/
1717
class TimeHelper extends CakeTimeHelper {

src/View/Helper/TimelineHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Tools\View\Helper;
44

55
use Cake\View\Helper;
6-
use Tools\Utility\DateTime;
6+
use Tools\I18n\DateTime;
77

88
/**
99
* TimelineHelper for easy output of a timeline with multiple items.
@@ -106,7 +106,7 @@ public function addItems($items) {
106106
*
107107
* @return string|null Javascript if $return is true
108108
*/
109-
public function finalize($return = false, array $scriptOptions = []) {
109+
public function finalize(bool $return = false, array $scriptOptions = []): ?string {
110110
$settings = $this->getConfig();
111111
$timelineId = $settings['id'];
112112
$data = $this->_format($this->_items);

src/View/Helper/UrlTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function buildComplete($url, array $options = []): string {
6161
}
6262

6363
/**
64-
* @return array
64+
* @return array<string, mixed>
6565
*/
6666
public function defaults(): array {
6767
return [
@@ -89,7 +89,7 @@ protected function addQueryStrings(array $url): array {
8989
*
9090
* @return array
9191
*/
92-
protected function addPassed(array $url) {
92+
protected function addPassed(array $url): array {
9393
$pass = $this->_View->getRequest()->getParam('pass');
9494
$url = array_merge($url, $pass);
9595

0 commit comments

Comments
 (0)