Browse Source

Cleanup API

mscherer 2 years ago
parent
commit
bf427fb668

+ 8 - 8
src/View/Helper/CommonHelper.php

@@ -49,7 +49,7 @@ class CommonHelper extends Helper {
 	 * @param array<string>|string|null $type - private/public or array of index/follow/archtive,...
 	 * @return string HTML
 	 */
-	public function metaRobots($type = null): string {
+	public function metaRobots(array|string|null $type = null): string {
 		$meta = Configure::read('Config.robots');
 		if ($type === null && $meta !== null) {
 			$type = $meta;
@@ -78,7 +78,7 @@ class CommonHelper extends Helper {
 	 * @param array<string>|string|null $content If array, it will be separated by commas
 	 * @return string HTML Markup
 	 */
-	public function metaName(?string $name = null, $content = null): string {
+	public function metaName(?string $name = null, array|string|null $content = null): string {
 		if (!$name || !$content) {
 			return '';
 		}
@@ -115,7 +115,7 @@ class CommonHelper extends Helper {
 	 * @param bool $escape
 	 * @return string HTML Markup
 	 */
-	public function metaKeywords($keywords = null, ?string $language = null, bool $escape = true): string {
+	public function metaKeywords(array|string|null $keywords = null, ?string $language = null, bool $escape = true): string {
 		if ($keywords === null) {
 			$keywords = Configure::read('Config.keywords');
 		}
@@ -142,7 +142,7 @@ class CommonHelper extends Helper {
 	 * @param bool $full
 	 * @return string HTML Markup
 	 */
-	public function metaCanonical($url = null, bool $full = false): string {
+	public function metaCanonical(array|string|null $url = null, bool $full = false): string {
 		$canonical = $this->Url->build($url, ['fullBase' => $full]);
 		$options = ['rel' => 'canonical', 'link' => $canonical];
 
@@ -152,7 +152,7 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience method for "alternate" SEO links
 	 *
-	 * @param array|string $url
+	 * @param array|string|null $url
 	 * @param array|string $lang (lang(iso2) or array of langs)
 	 * lang: language (in ISO 6391-1 format) + optionally the region (in ISO 3166-1 Alpha 2 format)
 	 * - de
@@ -161,7 +161,7 @@ class CommonHelper extends Helper {
 	 * @param bool $full
 	 * @return string HTML Markup
 	 */
-	public function metaAlternate($url, $lang, bool $full = false): string {
+	public function metaAlternate(array|string|null $url, array|string $lang, bool $full = false): string {
 		$url = $this->Url->build($url, ['fullBase' => $full]);
 		$lang = (array)$lang;
 		$res = [];
@@ -185,11 +185,11 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience method for META Tags
 	 *
-	 * @param array|string $url
+	 * @param array|string|null $url
 	 * @param string|null $title
 	 * @return string HTML Markup
 	 */
-	public function metaRss($url, ?string $title = null): string {
+	public function metaRss(array|string|null $url, ?string $title = null): string {
 		$tags = [
 			'meta' => '<link rel="alternate" type="application/rss+xml" title="%s" href="%s">',
 		];

+ 5 - 20
src/View/Helper/FormatHelper.php

@@ -64,7 +64,7 @@ class FormatHelper extends Helper {
 	 * @param array<string, mixed> $attributes
 	 * @return string
 	 */
-	public function thumbs($value, array $options = [], array $attributes = []) {
+	public function thumbs($value, array $options = [], array $attributes = []): string {
 		$icon = !empty($value) ? 'pro' : 'contra';
 
 		return $this->Icon->render($icon, $options, $attributes);
@@ -81,7 +81,7 @@ class FormatHelper extends Helper {
 	 * - titleField: field or `Model.field`
 	 * @return string
 	 */
-	public function neighbors(array $neighbors, $field, array $options = []) {
+	public function neighbors(array $neighbors, string $field, array $options = []): string {
 		$name = 'Record'; // Translation further down!
 		if (!empty($options['name'])) {
 			$name = ucfirst($options['name']);
@@ -159,7 +159,7 @@ class FormatHelper extends Helper {
 	 * @param array<string, mixed> $attributes
 	 * @return string
 	 */
-	public function genderIcon($value, array $options = [], array $attributes = []) {
+	public function genderIcon($value, array $options = [], array $attributes = []): string {
 		$value = (int)$value;
 		if ($value == static::GENDER_FEMALE) {
 			$icon = $this->Icon->render('female', $options, $attributes);
@@ -182,22 +182,7 @@ class FormatHelper extends Helper {
 	 * - class, ...
 	 * @return string
 	 */
-	public function cIcon($icon, array $options = [], array $attributes = []) {
-		return $this->_customIcon($icon, $options, $attributes);
-	}
-
-	/**
-	 * Deprecated img icons, font icons should be used instead, but sometimes
-	 * we still need a custom img icon.
-	 *
-	 * @param string $icon (constant or filename)
-	 * @param array<string, mixed> $options :
-	 * - translate, title, ...
-	 * @param array<string, mixed> $attributes :
-	 * - class, ...
-	 * @return string
-	 */
-	protected function _customIcon($icon, array $options = [], array $attributes = []) {
+	public function cIcon($icon, array $options = [], array $attributes = []): string {
 		$translate = $options['translate'] ?? true;
 
 		$type = pathinfo($icon, PATHINFO_FILENAME);
@@ -232,7 +217,7 @@ class FormatHelper extends Helper {
 	 * - title, ...
 	 * @return string HTML icon Yes/No
 	 */
-	public function yesNo($value, array $options = [], array $attributes = []) {
+	public function yesNo($value, array $options = [], array $attributes = []): string {
 		$defaults = [
 			'on' => 1,
 			'onTitle' => __d('tools', 'Yes'),

+ 3 - 3
src/View/Helper/GravatarHelper.php

@@ -80,7 +80,7 @@ class GravatarHelper extends Helper {
 	 * @param array<string, mixed> $options Array of options, keyed from default settings
 	 * @return string Gravatar image string
 	 */
-	public function image($email, array $options = []) {
+	public function image(string $email, array $options = []): string {
 		$imageOptions = $options += [
 			'escape' => false,
 		];
@@ -99,7 +99,7 @@ class GravatarHelper extends Helper {
 	 * @param array<string, mixed> $options Array of options, keyed from default settings
 	 * @return string Gravatar Image URL
 	 */
-	public function url($email, array $options = []) {
+	public function url(string $email, array $options = []): string {
 		$options = $this->_cleanOptions($options + $this->_config);
 		$options += [
 			'escape' => true,
@@ -182,7 +182,7 @@ class GravatarHelper extends Helper {
 	 * @param array<string, mixed> $options Array of options, keyed from default settings
 	 * @return string URL string of options
 	 */
-	protected function _buildOptions($options = []) {
+	protected function _buildOptions(array $options = []): string {
 		$gravatarOptions = array_intersect(array_keys($options), array_keys($this->_defaultConfig));
 		if (!empty($gravatarOptions)) {
 			$optionArray = [];

+ 5 - 5
src/View/Helper/HtmlTrait.php

@@ -15,7 +15,7 @@ trait HtmlTrait {
 	 * @param array<string, mixed> $options Attributes
 	 * @return string HTML image tag
 	 */
-	public function imageFromBlob($content, array $options = []) {
+	public function imageFromBlob(string $content, array $options = []): string {
 		$options += ['type' => 'png'];
 		$mimeType = 'image/' . $options['type'];
 
@@ -38,13 +38,13 @@ trait HtmlTrait {
 	 *   over value of `escape`)
 	 * - `confirm` JavaScript confirmation message.
 	 *
-	 * @param string $title The content to be wrapped by <a> tags.
+	 * @param array|string $title The content to be wrapped by <a> tags.
 	 * @param array|string|null $url URL or array of URL parameters, or
 	 *   external URL (starts with http://)
 	 * @param array<string, mixed> $options Array of options and HTML attributes.
 	 * @return string An `a` HTML element.
 	 */
-	public function linkReset($title, $url = null, array $options = []) {
+	public function linkReset(array|string $title, array|string|null $url = null, array $options = []): string {
 		if (is_array($url)) {
 			$url += ['prefix' => false, 'plugin' => false];
 		}
@@ -63,13 +63,13 @@ trait HtmlTrait {
 	 *   over value of `escape`)
 	 * - `confirm` JavaScript confirmation message.
 	 *
-	 * @param string $title The content to be wrapped by <a> tags.
+	 * @param array|string $title The content to be wrapped by <a> tags.
 	 * @param array|string|null $url URL or array of URL parameters, or
 	 *   external URL (starts with http://)
 	 * @param array<string, mixed> $options Array of options and HTML attributes.
 	 * @return string An `a` HTML element.
 	 */
-	public function linkComplete($title, $url = null, array $options = []) {
+	public function linkComplete(array|string $title, array|string|null $url = null, array $options = []): string {
 		if (is_array($url)) {
 			// Add query strings
 			if (!isset($url['?'])) {

+ 1 - 1
src/View/Helper/IconHelper.php

@@ -60,7 +60,7 @@ class IconHelper extends Helper {
 	 * - class, ...
 	 * @return string
 	 */
-	public function render(string $icon, array $options = [], array $attributes = []) {
+	public function render(string $icon, array $options = [], array $attributes = []): string {
 		return $this->collection->render($icon, $options, $attributes);
 	}
 

+ 6 - 6
src/View/Helper/MeterHelper.php

@@ -127,7 +127,7 @@ class MeterHelper extends Helper {
 	 * @param array<string, mixed> $attributes
 	 * @return string
 	 */
-	public function meterBar($value, $max, $min, $length, array $options = [], array $attributes = []) {
+	public function meterBar($value, $max, $min, int $length, array $options = [], array $attributes = []): string {
 		$defaults = [
 			'overflow' => false,
 		];
@@ -155,7 +155,7 @@ class MeterHelper extends Helper {
 	 * @throws \InvalidArgumentException
 	 * @return string
 	 */
-	public function draw($complete, $length) {
+	public function draw($complete, int $length) {
 		if ($length < static::LENGTH_MIN) {
 			throw new InvalidArgumentException('Min length for such a progress bar is ' . static::LENGTH_MIN);
 		}
@@ -180,7 +180,7 @@ class MeterHelper extends Helper {
 	 * @param int $length
 	 * @return int
 	 */
-	protected function calculateBarLength($complete, $length) {
+	protected function calculateBarLength($complete, int $length): int {
 		$barLength = (int)round($length * $complete, 0);
 
 		return $barLength;
@@ -200,7 +200,7 @@ class MeterHelper extends Helper {
 	 * @throws \InvalidArgumentException
 	 * @return float
 	 */
-	protected function prepareValue($value, $max, $min, $overflow) {
+	protected function prepareValue($value, $max, $min, bool $overflow) {
 		if ($max < $min) {
 			throw new InvalidArgumentException('Max needs to be larger than Min.');
 		}
@@ -227,7 +227,7 @@ class MeterHelper extends Helper {
 	 * @param bool $overflow
 	 * @return float
 	 */
-	protected function prepareMax($value, $max, $overflow) {
+	protected function prepareMax($value, $max, bool $overflow) {
 		if ($value <= $max) {
 			return $max;
 		}
@@ -251,7 +251,7 @@ class MeterHelper extends Helper {
 	 * @param bool $overflow
 	 * @return float
 	 */
-	protected function prepareMin($value, $min, $overflow) {
+	protected function prepareMin($value, $min, bool $overflow) {
 		if ($value > $min) {
 			return $min;
 		}

+ 4 - 4
src/View/Helper/ProgressHelper.php

@@ -73,7 +73,7 @@ class ProgressHelper extends Helper {
 	 * @param array<string, mixed> $attributes
 	 * @return string
 	 */
-	public function htmlProgressBar($value, array $options = [], array $attributes = []) {
+	public function htmlProgressBar($value, array $options = [], array $attributes = []): string {
 		$defaults = [
 			'fallbackHtml' => null,
 		];
@@ -101,7 +101,7 @@ class ProgressHelper extends Helper {
 	 * @param array<string, mixed> $attributes
 	 * @return string
 	 */
-	public function progressBar($value, $length, array $attributes = []) {
+	public function progressBar($value, int $length, array $attributes = []): string {
 		$bar = $this->draw($value, $length);
 
 		$attributes += [
@@ -119,7 +119,7 @@ class ProgressHelper extends Helper {
 	 * @throws \InvalidArgumentException
 	 * @return string
 	 */
-	public function draw($complete, $length) {
+	public function draw($complete, int $length): string {
 		if ($complete < 0.0 || $complete > 1.0) {
 			throw new InvalidArgumentException('Min/Max overflow for value `' . $complete . '` (0...1)');
 		}
@@ -174,7 +174,7 @@ class ProgressHelper extends Helper {
 	 * @param int $length
 	 * @return int
 	 */
-	protected function calculateBarLength($complete, $length) {
+	protected function calculateBarLength($complete, int $length): int {
 		$barLength = (int)round($length * $complete, 0);
 		if ($barLength === 0 && $complete > 0.0) {
 			$barLength = 1;

+ 1 - 1
src/View/Helper/TimeHelper.php

@@ -11,7 +11,7 @@ use Cake\View\View;
 /**
  * Wrapper for TimeHelper and TimeLib
  *
- * @mixin \Tools\Utility\DateTime
+ * @mixin \Tools\I18n\DateTime
  * @property \Cake\View\Helper\HtmlHelper $Html
  */
 class TimeHelper extends CakeTimeHelper {

+ 2 - 2
src/View/Helper/TimelineHelper.php

@@ -3,7 +3,7 @@
 namespace Tools\View\Helper;
 
 use Cake\View\Helper;
-use Tools\Utility\DateTime;
+use Tools\I18n\DateTime;
 
 /**
  * TimelineHelper for easy output of a timeline with multiple items.
@@ -106,7 +106,7 @@ class TimelineHelper extends Helper {
 	 *
 	 * @return string|null Javascript if $return is true
 	 */
-	public function finalize($return = false, array $scriptOptions = []) {
+	public function finalize(bool $return = false, array $scriptOptions = []): ?string {
 		$settings = $this->getConfig();
 		$timelineId = $settings['id'];
 		$data = $this->_format($this->_items);

+ 2 - 2
src/View/Helper/UrlTrait.php

@@ -61,7 +61,7 @@ trait UrlTrait {
 	}
 
 	/**
-	 * @return array
+	 * @return array<string, mixed>
 	 */
 	public function defaults(): array {
 		return [
@@ -89,7 +89,7 @@ trait UrlTrait {
 	 *
 	 * @return array
 	 */
-	protected function addPassed(array $url) {
+	protected function addPassed(array $url): array {
 		$pass = $this->_View->getRequest()->getParam('pass');
 		$url = array_merge($url, $pass);