mscherer 4 years ago
parent
commit
b98f743e77

+ 2 - 2
src/Command/InflectCommand.php

@@ -22,7 +22,7 @@ class InflectCommand extends Command {
 	/**
 	 * Valid inflection rules
 	 *
-	 * @var string[]
+	 * @var array<string>
 	 */
 	protected $validActions = [
 		'pluralize', 'singularize', 'camelize',
@@ -33,7 +33,7 @@ class InflectCommand extends Command {
 	/**
 	 * Valid inflection rules
 	 *
-	 * @var string[]
+	 * @var array<string>
 	 */
 	protected $validCommands = [
 		'pluralize', 'singularize', 'camelize',

+ 4 - 4
src/Controller/Component/CommonComponent.php

@@ -79,11 +79,11 @@ class CommonComponent extends Component {
 	 * - query string
 	 * - provided default
 	 *
-	 * @param string|array $default
-	 * @param string|array|null $data
+	 * @param array|string $default
+	 * @param array|string|null $data
 	 * @param string $key
 	 *
-	 * @return string|array
+	 * @return array|string
 	 */
 	public function getSafeRedirectUrl($default, $data = null, $key = 'redirect') {
 		$redirectUrl = $data ?: ($this->controller->getRequest()->getData($key) ?: $this->controller->getRequest()->getQuery($key));
@@ -144,7 +144,7 @@ class CommonComponent extends Component {
 	public function getPassedParam($var, $default = null) {
 		$passed = $this->controller->getRequest()->getParam('pass');
 
-		return isset($passed[$var]) ? $passed[$var] : $default;
+		return $passed[$var] ?? $default;
 	}
 
 	/**

+ 3 - 3
src/Controller/Component/UrlComponent.php

@@ -39,7 +39,7 @@ class UrlComponent extends Component {
 	 *
 	 * Can only add defaults for array URLs.
 	 *
-	 * @param string|array|null $url URL.
+	 * @param array|string|null $url URL.
 	 * @param bool $full If true, the full base URL will be prepended to the result
 	 * @return string Full translated URL with base path.
 	 */
@@ -56,7 +56,7 @@ class UrlComponent extends Component {
 	 *
 	 * Can only add query strings for array URLs.
 	 *
-	 * @param string|array|null $url URL.
+	 * @param array|string|null $url URL.
 	 * @param bool $full If true, the full base URL will be prepended to the result
 	 * @return string Full translated URL with base path.
 	 */
@@ -75,7 +75,7 @@ class UrlComponent extends Component {
 	 *
 	 * - `fullBase`: If true, the full base URL will be prepended to the result
 	 *
-	 * @param string|array|null $url Either a relative string url like `/products/view/23` or
+	 * @param array|string|null $url Either a relative string url like `/products/view/23` or
 	 *    an array of URL parameters. Using an array for URLs will allow you to leverage
 	 *    the reverse routing features of CakePHP.
 	 * @param array $options Array of options

+ 1 - 1
src/Controller/Controller.php

@@ -16,7 +16,7 @@ class Controller extends ShimController {
 	 *
 	 * @override To support defaults like limit etc.
 	 *
-	 * @param \Cake\ORM\Table|string|\Cake\ORM\Query|null $object Table to paginate
+	 * @param \Cake\ORM\Table|\Cake\ORM\Query|string|null $object Table to paginate
 	 *   (e.g: Table instance, 'TableName' or a Query object)
 	 * @param array $settings Settings
 	 *

+ 3 - 3
src/Error/ErrorHandlerTrait.php

@@ -32,7 +32,7 @@ trait ErrorHandlerTrait {
 	 * List of exceptions that are actually be treated as external 404s.
 	 * They should not go into the normal error log, but a separate 404 one.
 	 *
-	 * @var string[]
+	 * @var array<string>
 	 */
 	protected static $blacklist = [
 		InvalidPrimaryKeyException::class,
@@ -59,7 +59,7 @@ trait ErrorHandlerTrait {
 	/**
 	 * By design, these exceptions are also 404 with a valid internal referer.
 	 *
-	 * @var string[]
+	 * @var array<string>
 	 */
 	protected static $evenWithReferer = [
 		AuthSecurityException::class,
@@ -98,7 +98,7 @@ trait ErrorHandlerTrait {
 
 	/**
 	 * @param string $class
-	 * @param string[] $blacklist
+	 * @param array<string> $blacklist
 	 * @return bool
 	 */
 	protected function isBlacklisted(string $class, array $blacklist): bool {

+ 4 - 4
src/Mailer/Message.php

@@ -54,7 +54,7 @@ class Message extends CakeMessage {
 	/**
 	 * Overwrite to allow mimetype detection
 	 *
-	 * @param string|array $attachments String with the filename or array with filenames
+	 * @param array|string $attachments String with the filename or array with filenames
 	 * @throws \InvalidArgumentException
 	 * @return $this
 	 */
@@ -267,7 +267,7 @@ class Message extends CakeMessage {
 
 		$options['data'] = $content;
 		$options['mimetype'] = $mimeType;
-		$options['contentId'] = $contentId ? $contentId : str_replace('-', '', Text::uuid()) . '@' . $this->getDomain();
+		$options['contentId'] = $contentId ?: str_replace('-', '', Text::uuid()) . '@' . $this->getDomain();
 		$file = [$filename => $options];
 		$this->addAttachments($file);
 		if ($contentId === null) {
@@ -285,7 +285,7 @@ class Message extends CakeMessage {
 	 *
 	 * @param string $file
 	 * @param string $name
-	 * @return bool|string CID of the found file or false if no such attachment can be found
+	 * @return string|bool CID of the found file or false if no such attachment can be found
 	 */
 	protected function _isEmbeddedAttachment($file, $name) {
 		foreach ($this->getAttachments() as $filename => $fileInfo) {
@@ -306,7 +306,7 @@ class Message extends CakeMessage {
 	 *
 	 * @param string $content
 	 * @param string $name
-	 * @return bool|string CID of the found file or false if no such attachment can be found
+	 * @return string|bool CID of the found file or false if no such attachment can be found
 	 */
 	protected function _isEmbeddedBlobAttachment($content, $name) {
 		foreach ($this->getAttachments() as $filename => $fileInfo) {

+ 2 - 2
src/Model/Entity/EnumTrait.php

@@ -9,10 +9,10 @@ trait EnumTrait {
 	 * Now also supports reordering/filtering
 	 *
 	 * @link https://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/
-	 * @param int|string|array|null $value Integer or array of keys or NULL for complete array result
+	 * @param array|string|int|null $value Integer or array of keys or NULL for complete array result
 	 * @param array $options Options
 	 * @param string|null $default Default value
-	 * @return string|array|null
+	 * @return array|string|null
 	 */
 	public static function enum($value, array $options, $default = null) {
 		if ($value !== null && !is_array($value)) {

+ 1 - 1
src/Utility/FileLog.php

@@ -44,7 +44,7 @@ class FileLog {
 	/**
 	 * Log data into custom file
 	 *
-	 * @param array|string|object $data Data to store
+	 * @param object|array|string $data Data to store
 	 * @param string|null $filename Filename of log file
 	 * @param bool $traceKey Add trace string key into log data
 	 * @return bool Success

+ 3 - 3
src/Utility/L10n.php

@@ -270,8 +270,8 @@ class L10n {
 	/**
 	 * Attempts to find locale for language, or language for locale
 	 *
-	 * @param string|array|null $mixed 2/3 char string (language/locale), array of those strings, or null
-	 * @return string|array|false string language/locale, array of those values, whole map as an array,
+	 * @param array|string|null $mixed 2/3 char string (language/locale), array of those strings, or null
+	 * @return array|string|false string language/locale, array of those values, whole map as an array,
 	 *    or false when language/locale doesn't exist
 	 */
 	public function map($mixed = null) {
@@ -303,7 +303,7 @@ class L10n {
 	/**
 	 * Attempts to find catalog record for requested language
 	 *
-	 * @param string|array|null $language String requested language, array of requested languages, or null for whole catalog
+	 * @param array|string|null $language String requested language, array of requested languages, or null for whole catalog
 	 * @return array|false array catalog record for requested language, array of catalog records, whole catalog,
 	 *    or false when language doesn't exist
 	 */

+ 2 - 2
src/Utility/Language.php

@@ -90,7 +90,7 @@ class Language {
 	/**
 	 * Compares two parsed arrays of language tags and find the matches
 	 *
-	 * @param string[] $accepted
+	 * @param array<string> $accepted
 	 * @param array $available
 	 * @return string|null
 	 */
@@ -111,7 +111,7 @@ class Language {
 	/**
 	 * Compares two parsed arrays of language tags and find the matches
 	 *
-	 * @param string[] $accepted
+	 * @param array<string> $accepted
 	 * @param array $available
 	 * @return array
 	 */

+ 1 - 1
src/Utility/Mime.php

@@ -750,7 +750,7 @@ class Mime extends Response {
 	 *
 	 * e.g `mapType('application/pdf'); // returns 'pdf'`
 	 *
-	 * @param string|array $ctype Either a string content type to map, or an array of types.
+	 * @param array|string $ctype Either a string content type to map, or an array of types.
 	 * @return mixed Aliases for the types provided.
 	 */
 	public function mapType($ctype) {

+ 3 - 3
src/Utility/Text.php

@@ -184,7 +184,7 @@ class Text extends CakeText {
 	 * Explode a string of given tags into an array.
 	 *
 	 * @param string $tags
-	 * @return string[]
+	 * @return array<string>
 	 */
 	public function explodeTags($tags) {
 		// This regexp allows the following types of user input:
@@ -210,7 +210,7 @@ class Text extends CakeText {
 	/**
 	 * Implode an array of tags into a string.
 	 *
-	 * @param string[] $tags
+	 * @param array<string> $tags
 	 * @return string
 	 */
 	public function implodeTags(array $tags) {
@@ -253,7 +253,7 @@ class Text extends CakeText {
 	 * @param string $text
 	 * @param array $options
 	 * - min_char, max_char, case_sensititive, ...
-	 * @return string[]
+	 * @return array<string>
 	 */
 	public function words($text, array $options = []) {
 		$text = str_replace([PHP_EOL, "\t"], ' ', $text);

+ 4 - 4
src/Utility/Utility.php

@@ -133,7 +133,7 @@ class Utility {
 	 *
 	 * @param string $str
 	 * @param int $length
-	 * @return string[] Result
+	 * @return array<string> Result
 	 */
 	public static function strSplit($str, $length = 1) {
 		if ($length < 1) {
@@ -231,7 +231,7 @@ class Utility {
 	 * Removes http:// or other protocols from the link.
 	 *
 	 * @param string $url
-	 * @param string[] $protocols Defaults to http and https. Pass empty array for all.
+	 * @param array<string> $protocols Defaults to http and https. Pass empty array for all.
 	 * @return string strippedUrl
 	 */
 	public static function stripProtocol($url, $protocols = ['http', 'https']) {
@@ -458,7 +458,7 @@ class Utility {
 	/**
 	 * Applies h() recursively
 	 *
-	 * @param string|array $value
+	 * @param array|string $value
 	 * @return array|string
 	 */
 	public static function specialcharsDeep($value) {
@@ -470,7 +470,7 @@ class Utility {
 	/**
 	 * Main deep method
 	 *
-	 * @param string|callable $function Callable or function name.
+	 * @param callable|string $function Callable or function name.
 	 * @param mixed $value
 	 * @return array|string
 	 */

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

@@ -67,7 +67,7 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience method for clean ROBOTS allowance
 	 *
-	 * @param string|string[]|null $type - private/public or array of index/follow/archtive,...
+	 * @param array<string>|string|null $type - private/public or array of index/follow/archtive,...
 	 * @return string HTML
 	 */
 	public function metaRobots($type = null): string {
@@ -96,7 +96,7 @@ class CommonHelper extends Helper {
 	 * Convenience method for clean meta name tags
 	 *
 	 * @param string|null $name Author, date, generator, revisit-after, language
-	 * @param string|array|null $content If array, it will be separated by commas
+	 * @param array|string|null $content If array, it will be separated by commas
 	 * @return string HTML Markup
 	 */
 	public function metaName(?string $name = null, $content = null): string {
@@ -131,7 +131,7 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience method to output meta keywords
 	 *
-	 * @param string|array|null $keywords
+	 * @param array|string|null $keywords
 	 * @param string|null $language (iso2: de, en-us, ...)
 	 * @param bool $escape
 	 * @return string HTML Markup
@@ -159,7 +159,7 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience function for "canonical" SEO links
 	 *
-	 * @param string|array|null $url
+	 * @param array|string|null $url
 	 * @param bool $full
 	 * @return string HTML Markup
 	 */
@@ -173,8 +173,8 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience method for "alternate" SEO links
 	 *
-	 * @param string|array $url
-	 * @param string|array $lang (lang(iso2) or array of langs)
+	 * @param array|string $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
 	 * - de-ch
@@ -206,7 +206,7 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience method for META Tags
 	 *
-	 * @param string|array $url
+	 * @param array|string $url
 	 * @param string|null $title
 	 * @return string HTML Markup
 	 */

+ 11 - 0
src/View/Helper/MeterHelper.php

@@ -21,8 +21,19 @@ use Tools\Utility\Number;
  */
 class MeterHelper extends Helper {
 
+	/**
+	 * @var int
+	 */
 	public const LENGTH_MIN = 3;
+
+	/**
+	 * @var string
+	 */
 	public const CHAR_EMPTY = '░';
+
+	/**
+	 * @var string
+	 */
 	public const CHAR_FULL = '█';
 
 	/**

+ 11 - 0
src/View/Helper/ProgressHelper.php

@@ -22,8 +22,19 @@ use Tools\Utility\Number;
  */
 class ProgressHelper extends Helper {
 
+	/**
+	 * @var int
+	 */
 	public const LENGTH_MIN = 3;
+
+	/**
+	 * @var string
+	 */
 	public const CHAR_EMPTY = '░';
+
+	/**
+	 * @var string
+	 */
 	public const CHAR_FULL = '█';
 
 	/**

+ 32 - 1
src/View/Helper/QrCodeHelper.php

@@ -28,13 +28,44 @@ use Cake\View\View;
  */
 class QrCodeHelper extends Helper {
 
+	/**
+	 * @var int
+	 */
 	public const MIN_SIZE = 58; # not readable anymore below this value
+
+	/**
+	 * @var int
+	 */
 	public const MAX_SIZE = 540; # max of 300000 pixels
+
+	/**
+	 * @var int
+	 */
 	public const DEFAULT_SIZE = 74; # 2x size
+
+	/**
+	 * @var string
+	 */
 	public const DEFAULT_LEVEL = 'L'; # highest correction level
+
+	/**
+	 * @var int
+	 */
 	public const SIZE_L = 58;
+
+	/**
+	 * @var int
+	 */
 	public const SIZE_M = 66;
+
+	/**
+	 * @var int
+	 */
 	public const SIZE_Q = 66;
+
+	/**
+	 * @var int
+	 */
 	public const SIZE_H = 74;
 
 	/**
@@ -127,7 +158,7 @@ class QrCodeHelper extends Helper {
 	 * Format a text in a specific format
 	 * - url, sms, tel, email, market, geo
 	 *
-	 * @param string|array $text
+	 * @param array|string $text
 	 * @param string|null $type
 	 * @return string formattedText
 	 */

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

@@ -31,7 +31,7 @@ trait UrlTrait {
 	 *
 	 * Can only add defaults for array URLs.
 	 *
-	 * @param string|array|null $url URL.
+	 * @param array|string|null $url URL.
 	 * @param array $options
 	 * @return string Full translated URL with base path.
 	 */
@@ -48,7 +48,7 @@ trait UrlTrait {
 	 *
 	 * Can only add query strings for array URLs.
 	 *
-	 * @param string|array|null $url URL.
+	 * @param array|string|null $url URL.
 	 * @param array $options
 	 * @return string Full translated URL with base path.
 	 */

+ 3 - 3
src/View/Widget/DatalistWidget.php

@@ -41,13 +41,13 @@ class DatalistWidget extends SelectBoxWidget {
 			$options = str_replace(
 				'value',
 				'data-value',
-				$options
+				$options,
 			);
 		}
 
 		$name = $data['name'];
 		$id = $data['id'] ?: Text::slug($name);
-		$default = isset($data['val']) ? $data['val'] : null;
+		$default = $data['val'] ?? null;
 
 		$inputData = $data['input'] + [
 			'id' => $id,
@@ -73,7 +73,7 @@ class DatalistWidget extends SelectBoxWidget {
 				'datalistAttrs' => $datalistAttrs,
 				'content' => implode('', $options),
 				'id' => $id,
-			]
+			],
 		);
 	}
 

+ 1 - 1
tests/TestCase/Model/Table/TokensTableTest.php

@@ -8,7 +8,7 @@ use Tools\Model\Table\TokensTable;
 class TokensTableTest extends TestCase {
 
 	/**
-	 * @var string[]
+	 * @var array<string>
 	 */
 	protected $fixtures = [
 		'plugin.Tools.Tokens',

+ 12 - 8
tests/TestCase/Utility/FileLogTest.php

@@ -33,6 +33,10 @@ class FileLogTest extends TestCase {
 	 */
 	private const TEST_FILENAME_ARRAY1 = 'array_file1';
 	private const TEST_FILEPATH_ARRAY1 = LOGS . self::TEST_FILENAME_ARRAY1 . '.log';
+
+	/**
+	 * @var string
+	 */
 	private const TEST_FILENAME_ARRAY2 = 'array_file2';
 	private const TEST_FILEPATH_ARRAY2 = LOGS . self::TEST_FILENAME_ARRAY2 . '.log';
 
@@ -69,7 +73,7 @@ class FileLogTest extends TestCase {
 		$this->assertFileExists(static::TEST_FILEPATH_STRING);
 		$this->assertRegExp(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: It works!/i',
-			file_get_contents(static::TEST_FILEPATH_STRING)
+			file_get_contents(static::TEST_FILEPATH_STRING),
 		);
 
 		unlink(static::TEST_FILEPATH_STRING);
@@ -96,7 +100,7 @@ class FileLogTest extends TestCase {
 					'email' => 'john.doe@example.com',
 				],
 			],
-			static::TEST_FILENAME_ARRAY1
+			static::TEST_FILENAME_ARRAY1,
 		);
 
 		$result2 = FileLog::write(
@@ -107,7 +111,7 @@ class FileLogTest extends TestCase {
 					'email' => 'jane.doe@example.com',
 				],
 			],
-			static::TEST_FILENAME_ARRAY2
+			static::TEST_FILENAME_ARRAY2,
 		);
 
 		// Assert for `TEST_FILENAME_ARRAY1`
@@ -116,7 +120,7 @@ class FileLogTest extends TestCase {
 		$fileContents = file_get_contents(static::TEST_FILEPATH_ARRAY1);
 		$this->assertRegExp(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: Array([\s\S]*)\(([\s\S]*)[user]([\s\S]*)\[id\] => 1/i',
-			$fileContents
+			$fileContents,
 		);
 
 		// Assert for `TEST_FILENAME_ARRAY2`
@@ -125,7 +129,7 @@ class FileLogTest extends TestCase {
 		$fileContents = file_get_contents(static::TEST_FILEPATH_ARRAY2);
 		$this->assertRegExp(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: Array([\s\S]*)\(([\s\S]*)[user]([\s\S]*)\[id\] => 2/i',
-			$fileContents
+			$fileContents,
 		);
 
 		unlink(static::TEST_FILEPATH_ARRAY1);
@@ -144,14 +148,14 @@ class FileLogTest extends TestCase {
 
 		$result = FileLog::write(
 			$this->getTableLocator()->get('Posts'),
-			static::TEST_FILENAME_OBJECT
+			static::TEST_FILENAME_OBJECT,
 		);
 
 		$this->assertTrue($result);
 		$this->assertFileExists(static::TEST_FILEPATH_OBJECT);
 		$this->assertRegExp(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: TestApp.Model.Table.PostsTable Object/i',
-			file_get_contents(static::TEST_FILEPATH_OBJECT)
+			file_get_contents(static::TEST_FILEPATH_OBJECT),
 		);
 
 		unlink(static::TEST_FILEPATH_OBJECT);
@@ -173,7 +177,7 @@ class FileLogTest extends TestCase {
 		$this->assertFileExists(static::TEST_DEFAULT_FILEPATH_STRING);
 		$this->assertRegExp(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: It works with default too!/i',
-			file_get_contents(static::TEST_DEFAULT_FILEPATH_STRING)
+			file_get_contents(static::TEST_DEFAULT_FILEPATH_STRING),
 		);
 
 		unlink(static::TEST_DEFAULT_FILEPATH_STRING);

+ 1 - 1
tests/TestCase/View/Helper/ObfuscateHelperTest.php

@@ -97,7 +97,7 @@ class ObfuscateHelperTest extends TestCase {
 			$res = $this->Obfuscate->wordCensor($value, ['Arsch', 'Ficken', 'Bitch']);
 
 			//debug('\''.h($value).'\' becomes \''.h($res).'\'', null, false);
-			$this->assertEquals($expected === null ? $value : $expected, $res);
+			$this->assertEquals($expected ?? $value, $res);
 		}
 	}
 

+ 7 - 0
tests/TestCase/View/Helper/QrCodeHelperTest.php

@@ -12,7 +12,14 @@ use Tools\View\Helper\QrCodeHelper;
  */
 class QrCodeHelperTest extends TestCase {
 
+	/**
+	 * @var string
+	 */
 	public const QR_TEST_STRING = 'Some Text to Translate';
+
+	/**
+	 * @var string
+	 */
 	public const QR_TEST_STRING_UTF = 'Some äöü Test String with $ and @ etc';
 
 	/**

+ 19 - 0
tests/test_app/Model/Entity/BitmaskedComment.php

@@ -21,10 +21,29 @@ class BitmaskedComment extends Entity {
 		return parent::enum($value, $options);
 	}
 
+	/**
+	 * @var int
+	 */
 	public const STATUS_NONE = 0;
+
+	/**
+	 * @var int
+	 */
 	public const STATUS_ACTIVE = 1;
+
+	/**
+	 * @var int
+	 */
 	public const STATUS_PUBLISHED = 2;
+
+	/**
+	 * @var int
+	 */
 	public const STATUS_APPROVED = 4;
+
+	/**
+	 * @var int
+	 */
 	public const STATUS_FLAGGED = 8;
 
 }

+ 1 - 1
tests/test_app/Model/Entity/SluggedArticle.php

@@ -7,7 +7,7 @@ use Cake\ORM\Entity;
 class SluggedArticle extends Entity {
 
 	/**
-	 * @var string[]
+	 * @var array<string>
 	 */
 	protected $_virtual = [
 		'special',