Browse Source

Remove deprecations.

mscherer 4 years ago
parent
commit
6726f58c22

+ 8 - 2
src/Controller/Component/CommonComponent.php

@@ -97,10 +97,16 @@ class CommonComponent extends Component {
 	/**
 	/**
 	 * List all direct actions of a controller
 	 * List all direct actions of a controller
 	 *
 	 *
-	 * @return array Actions
+	 * @return array<string> Actions
 	 */
 	 */
 	public function listActions() {
 	public function listActions() {
-		$parentClassMethods = get_class_methods(get_parent_class($this->controller));
+		/** @var string|null $parentClass */
+		$parentClass = get_parent_class($this->controller);
+		if (!$parentClass) {
+			return [];
+		}
+
+		$parentClassMethods = get_class_methods($parentClass);
 		$subClassMethods = get_class_methods($this->controller);
 		$subClassMethods = get_class_methods($this->controller);
 		$classMethods = array_diff($subClassMethods, $parentClassMethods);
 		$classMethods = array_diff($subClassMethods, $parentClassMethods);
 		foreach ($classMethods as $key => $classMethod) {
 		foreach ($classMethods as $key => $classMethod) {

+ 1 - 1
src/Model/Behavior/SluggedBehavior.php

@@ -329,7 +329,7 @@ class SluggedBehavior extends Behavior {
 				$slug = mb_strtolower($slug);
 				$slug = mb_strtolower($slug);
 			}
 			}
 			if (in_array($case, ['title', 'camel'])) {
 			if (in_array($case, ['title', 'camel'])) {
-				$words = explode($separator, $slug) ?: [];
+				$words = explode($separator, $slug);
 				foreach ($words as $i => &$word) {
 				foreach ($words as $i => &$word) {
 					$firstChar = mb_substr($word, 0, 1);
 					$firstChar = mb_substr($word, 0, 1);
 					$rest = mb_substr($word, 1, mb_strlen($word) - 1);
 					$rest = mb_substr($word, 1, mb_strlen($word) - 1);

+ 3 - 3
src/Utility/FrozenTime.php

@@ -851,7 +851,7 @@ class FrozenTime extends CakeFrozenTime {
 
 
 					break;
 					break;
 				case 'd':
 				case 'd':
-					$str = floor($seconds / 86400 % 30);
+					$str = floor((int)($seconds / 86400) % 30);
 
 
 					break;
 					break;
 				case 'H':
 				case 'H':
@@ -859,7 +859,7 @@ class FrozenTime extends CakeFrozenTime {
 
 
 					break;
 					break;
 				case 'h':
 				case 'h':
-					$str = floor($seconds / 3600 % 24);
+					$str = floor((int)($seconds / 3600) % 24);
 
 
 					break;
 					break;
 				case 'I':
 				case 'I':
@@ -867,7 +867,7 @@ class FrozenTime extends CakeFrozenTime {
 
 
 					break;
 					break;
 				case 'i':
 				case 'i':
-					$str = floor($seconds / 60 % 60);
+					$str = floor((int)($seconds / 60) % 60);
 
 
 					break;
 					break;
 				case 'S':
 				case 'S':

+ 2 - 2
src/Utility/Time.php

@@ -862,7 +862,7 @@ class Time extends CakeTime {
 
 
 					break;
 					break;
 				case 'h':
 				case 'h':
-					$str = floor($seconds / 3600 % 24);
+					$str = floor((int)($seconds / 3600) % 24);
 
 
 					break;
 					break;
 				case 'I':
 				case 'I':
@@ -870,7 +870,7 @@ class Time extends CakeTime {
 
 
 					break;
 					break;
 				case 'i':
 				case 'i':
-					$str = floor($seconds / 60 % 60);
+					$str = floor((int)($seconds / 60) % 60);
 
 
 					break;
 					break;
 				case 'S':
 				case 'S':

+ 11 - 7
src/Utility/Utility.php

@@ -51,6 +51,8 @@ class Utility {
 	 * Options
 	 * Options
 	 * - clean: true/false (defaults to true and removes empty tokens and whitespace)
 	 * - clean: true/false (defaults to true and removes empty tokens and whitespace)
 	 *
 	 *
+	 * @phpstan-param non-empty-string $separator
+	 *
 	 * @param string $data The data to tokenize
 	 * @param string $data The data to tokenize
 	 * @param string $separator The token to split the data on.
 	 * @param string $separator The token to split the data on.
 	 * @param array $options
 	 * @param array $options
@@ -65,7 +67,7 @@ class Utility {
 			return [];
 			return [];
 		}
 		}
 		$tokens = explode($separator, $data);
 		$tokens = explode($separator, $data);
-		if (empty($tokens) || !$options['clean']) {
+		if (!$options['clean']) {
 			return $tokens;
 			return $tokens;
 		}
 		}
 
 
@@ -98,7 +100,7 @@ class Utility {
 	 */
 	 */
 	public static function pregMatchAll($pattern, $subject, $flags = PREG_SET_ORDER, $offset = null) {
 	public static function pregMatchAll($pattern, $subject, $flags = PREG_SET_ORDER, $offset = null) {
 		$pattern = substr($pattern, 0, 1) . '(*UTF8)' . substr($pattern, 1);
 		$pattern = substr($pattern, 0, 1) . '(*UTF8)' . substr($pattern, 1);
-		preg_match_all($pattern, $subject, $matches, $flags, $offset);
+		preg_match_all($pattern, $subject, $matches, $flags, (int)$offset);
 
 
 		return $matches;
 		return $matches;
 	}
 	}
@@ -122,7 +124,7 @@ class Utility {
 	 */
 	 */
 	public static function pregMatch($pattern, $subject, $flags = null, $offset = null) {
 	public static function pregMatch($pattern, $subject, $flags = null, $offset = null) {
 		$pattern = substr($pattern, 0, 1) . '(*UTF8)' . substr($pattern, 1);
 		$pattern = substr($pattern, 0, 1) . '(*UTF8)' . substr($pattern, 1);
-		preg_match($pattern, $subject, $matches, $flags, $offset);
+		preg_match($pattern, $subject, $matches, (int)$flags, (int)$offset);
 
 
 		return $matches;
 		return $matches;
 	}
 	}
@@ -163,7 +165,7 @@ class Utility {
 			$ipaddr = env('REMOTE_ADDR');
 			$ipaddr = env('REMOTE_ADDR');
 		}
 		}
 
 
-		return trim($ipaddr);
+		return trim((string)$ipaddr);
 	}
 	}
 
 
 	/**
 	/**
@@ -449,7 +451,7 @@ class Utility {
 		}
 		}
 
 
 		if (is_string($value) || $value === null) {
 		if (is_string($value) || $value === null) {
-			return ($value === null && !$transformNullToString) ? $value : trim($value);
+			return ($value === null && !$transformNullToString) ? $value : trim((string)$value);
 		}
 		}
 
 
 		return $value;
 		return $value;
@@ -520,12 +522,14 @@ class Utility {
 	 *
 	 *
 	 * So `Some.Deep.Value` becomes `array('Some' => array('Deep' => array('Value')))`.
 	 * So `Some.Deep.Value` becomes `array('Some' => array('Deep' => array('Value')))`.
 	 *
 	 *
+	 * @phpstan-param non-empty-string $separator
+	 *
 	 * @param array $data
 	 * @param array $data
 	 * @param string $separator
 	 * @param string $separator
 	 * @param string|null $undefinedKey
 	 * @param string|null $undefinedKey
 	 * @return array
 	 * @return array
 	 */
 	 */
-	public static function expandList(array $data, $separator = '.', $undefinedKey = null) {
+	public static function expandList(array $data, string $separator = '.', ?string $undefinedKey = null): array {
 		$result = [];
 		$result = [];
 		foreach ($data as $value) {
 		foreach ($data as $value) {
 			$keys = explode($separator, $value);
 			$keys = explode($separator, $value);
@@ -565,7 +569,7 @@ class Utility {
 	 * @param string $separator
 	 * @param string $separator
 	 * @return array
 	 * @return array
 	 */
 	 */
-	public static function flattenList(array $data, $separator = '.') {
+	public static function flattenList(array $data, string $separator = '.'): array {
 		$result = [];
 		$result = [];
 		$stack = [];
 		$stack = [];
 		$path = null;
 		$path = null;

+ 5 - 5
tests/TestCase/Utility/FileLogTest.php

@@ -62,7 +62,7 @@ class FileLogTest extends TestCase {
 
 
 		$this->assertTrue($result);
 		$this->assertTrue($result);
 		$this->assertFileExists(static::TEST_FILEPATH_STRING);
 		$this->assertFileExists(static::TEST_FILEPATH_STRING);
-		$this->assertRegExp(
+		$this->assertMatchesRegularExpression(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: It works!/i',
 			'/^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),
 		);
 		);
@@ -109,7 +109,7 @@ class FileLogTest extends TestCase {
 		$this->assertTrue($result1);
 		$this->assertTrue($result1);
 		$this->assertFileExists(static::TEST_FILEPATH_ARRAY1);
 		$this->assertFileExists(static::TEST_FILEPATH_ARRAY1);
 		$fileContents = file_get_contents(static::TEST_FILEPATH_ARRAY1);
 		$fileContents = file_get_contents(static::TEST_FILEPATH_ARRAY1);
-		$this->assertRegExp(
+		$this->assertMatchesRegularExpression(
 			'/^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',
 			'/^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,
 		);
 		);
@@ -118,7 +118,7 @@ class FileLogTest extends TestCase {
 		$this->assertTrue($result2);
 		$this->assertTrue($result2);
 		$this->assertFileExists(static::TEST_FILEPATH_ARRAY2);
 		$this->assertFileExists(static::TEST_FILEPATH_ARRAY2);
 		$fileContents = file_get_contents(static::TEST_FILEPATH_ARRAY2);
 		$fileContents = file_get_contents(static::TEST_FILEPATH_ARRAY2);
-		$this->assertRegExp(
+		$this->assertMatchesRegularExpression(
 			'/^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',
 			'/^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,
 		);
 		);
@@ -144,7 +144,7 @@ class FileLogTest extends TestCase {
 
 
 		$this->assertTrue($result);
 		$this->assertTrue($result);
 		$this->assertFileExists(static::TEST_FILEPATH_OBJECT);
 		$this->assertFileExists(static::TEST_FILEPATH_OBJECT);
-		$this->assertRegExp(
+		$this->assertMatchesRegularExpression(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: TestApp.Model.Table.PostsTable Object/i',
 			'/^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),
 		);
 		);
@@ -166,7 +166,7 @@ class FileLogTest extends TestCase {
 
 
 		$this->assertTrue($result);
 		$this->assertTrue($result);
 		$this->assertFileExists(static::TEST_DEFAULT_FILEPATH_STRING);
 		$this->assertFileExists(static::TEST_DEFAULT_FILEPATH_STRING);
-		$this->assertRegExp(
+		$this->assertMatchesRegularExpression(
 			'/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: It works with default too!/i',
 			'/^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),
 		);
 		);

+ 5 - 5
tests/TestCase/View/Helper/GravatarHelperTest.php

@@ -112,7 +112,7 @@ class GravatarHelperTest extends TestCase {
 	 */
 	 */
 	public function testExtensions() {
 	public function testExtensions() {
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => true, 'default' => 'wavatar']);
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => true, 'default' => 'wavatar']);
-		$this->assertRegExp('/\.jpg(?:$|\?)/', $result);
+		$this->assertMatchesRegularExpression('/\.jpg(?:$|\?)/', $result);
 	}
 	}
 
 
 	/**
 	/**
@@ -122,7 +122,7 @@ class GravatarHelperTest extends TestCase {
 	 */
 	 */
 	public function testRating() {
 	public function testRating() {
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => true, 'default' => 'wavatar']);
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => true, 'default' => 'wavatar']);
-		$this->assertRegExp('/\.jpg(?:$|\?)/', $result);
+		$this->assertMatchesRegularExpression('/\.jpg(?:$|\?)/', $result);
 	}
 	}
 
 
 	/**
 	/**
@@ -133,7 +133,7 @@ class GravatarHelperTest extends TestCase {
 	public function testAlternateDefaultIcon() {
 	public function testAlternateDefaultIcon() {
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => false, 'default' => 'wavatar']);
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => false, 'default' => 'wavatar']);
 		[$url, $params] = explode('?', $result);
 		[$url, $params] = explode('?', $result);
-		$this->assertRegExp('/default=wavatar/', $params);
+		$this->assertMatchesRegularExpression('/default=wavatar/', $params);
 	}
 	}
 
 
 	/**
 	/**
@@ -143,7 +143,7 @@ class GravatarHelperTest extends TestCase {
 	 */
 	 */
 	public function testAlternateDefaultIconCorrection() {
 	public function testAlternateDefaultIconCorrection() {
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => false, 'default' => '12345']);
 		$result = $this->Gravatar->url('example@gravatar.com', ['ext' => false, 'default' => '12345']);
-		$this->assertRegExp('/[^\?]+/', $result);
+		$this->assertMatchesRegularExpression('/[^\?]+/', $result);
 	}
 	}
 
 
 	/**
 	/**
@@ -154,7 +154,7 @@ class GravatarHelperTest extends TestCase {
 	public function testSize() {
 	public function testSize() {
 		$result = $this->Gravatar->url('example@gravatar.com', ['size' => '120']);
 		$result = $this->Gravatar->url('example@gravatar.com', ['size' => '120']);
 		[$url, $params] = explode('?', $result);
 		[$url, $params] = explode('?', $result);
-		$this->assertRegExp('/size=120/', $params);
+		$this->assertMatchesRegularExpression('/size=120/', $params);
 	}
 	}
 
 
 	/**
 	/**

+ 4 - 4
tests/TestCase/View/Helper/TextHelperTest.php

@@ -207,22 +207,22 @@ class TextHelperTest extends TestCase {
 		$text = 'Text with a partial www.cakephp.org URL';
 		$text = 'Text with a partial www.cakephp.org URL';
 		$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
 		$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
 		$result = $this->Text->autoLinkUrls($text);
 		$result = $this->Text->autoLinkUrls($text);
-		$this->assertRegExp('#^' . $expected . '$#', $result);
+		$this->assertMatchesRegularExpression('#^' . $expected . '$#', $result);
 
 
 		$text = 'Text with a partial www.cakephp.org URL';
 		$text = 'Text with a partial www.cakephp.org URL';
 		$expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
 		$expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
 		$result = $this->Text->autoLinkUrls($text, [], ['class' => 'link']);
 		$result = $this->Text->autoLinkUrls($text, [], ['class' => 'link']);
-		$this->assertRegExp('#^' . $expected . '$#', $result);
+		$this->assertMatchesRegularExpression('#^' . $expected . '$#', $result);
 
 
 		$text = 'Text with a partial WWW.cakephp.org URL';
 		$text = 'Text with a partial WWW.cakephp.org URL';
 		$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
 		$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
 		$result = $this->Text->autoLinkUrls($text);
 		$result = $this->Text->autoLinkUrls($text);
-		$this->assertRegExp('#^' . $expected . '$#', $result);
+		$this->assertMatchesRegularExpression('#^' . $expected . '$#', $result);
 
 
 		$text = 'Text with a partial WWW.cakephp.org &copy; URL';
 		$text = 'Text with a partial WWW.cakephp.org &copy; URL';
 		$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> &copy; URL';
 		$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> &copy; URL';
 		$result = $this->Text->autoLinkUrls($text, ['escape' => false], ['escape' => false]);
 		$result = $this->Text->autoLinkUrls($text, ['escape' => false], ['escape' => false]);
-		$this->assertRegExp('#^' . $expected . '$#', $result);
+		$this->assertMatchesRegularExpression('#^' . $expected . '$#', $result);
 
 
 		$text = 'Text with a url www.cot.ag/cuIb2Q and more';
 		$text = 'Text with a url www.cot.ag/cuIb2Q and more';
 		$expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
 		$expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';