Browse Source

Remove some deprecations. (#289)

* Remove some deprecations.

* Remove some deprecations.
Mark Scherer 2 years ago
parent
commit
20ff734464

+ 1 - 1
composer.json

@@ -27,7 +27,7 @@
 		"dereuromark/cakephp-shim": "^2.0.0"
 	},
 	"require-dev": {
-		"cakephp/chronos": "^2.0",
+		"cakephp/chronos": "^2.4",
 		"mobiledetect/mobiledetectlib": "^2.8",
 		"fig-r/psr2r-sniffer": "dev-master",
 		"yangqi/htmldom": "^1.0",

+ 6 - 6
src/Model/Table/Table.php

@@ -386,24 +386,24 @@ class Table extends ShimTable {
 
 			if (!empty($options['after'])) {
 				$compare = $compareValue->subSeconds($seconds);
-				if ($options['after']->gt($compare)) {
+				if ($options['after']->greaterThan($compare)) {
 					return false;
 				}
 				if (!empty($options['max'])) {
 					$after = $options['after']->addSeconds($options['max']);
-					if ($time->gt($after)) {
+					if ($time->greaterThan($after)) {
 						return false;
 					}
 				}
 			}
 			if (!empty($options['before'])) {
 				$compare = $compareValue->addSeconds($seconds);
-				if ($options['before']->lt($compare)) {
+				if ($options['before']->lessThan($compare)) {
 					return false;
 				}
 				if (!empty($options['max'])) {
 					$after = $options['before']->subSeconds($options['max']);
-					if ($time->lt($after)) {
+					if ($time->lessThan($after)) {
 						return false;
 					}
 				}
@@ -455,7 +455,7 @@ class Table extends ShimTable {
 				if (!is_object($after)) {
 					$after = new FrozenTime($after);
 				}
-				if ($after->gt($compare)) {
+				if ($after->greaterThan($compare)) {
 					return false;
 				}
 			}
@@ -466,7 +466,7 @@ class Table extends ShimTable {
 				if (!is_object($before)) {
 					$before = new FrozenTime($before);
 				}
-				if ($before->lt($compare)) {
+				if ($before->lessThan($compare)) {
 					return false;
 				}
 			}

+ 1 - 1
src/Utility/FrozenTime.php

@@ -567,7 +567,7 @@ class FrozenTime extends CakeFrozenTime {
 			}
 		}
 
-		$date = $date->timezone($options['timezone']);
+		$date = $date->setTimezone($options['timezone']);
 		$ret = $date->format($format);
 
 		if (!empty($options['oclock'])) {

+ 7 - 2
src/Utility/Mime.php

@@ -14,7 +14,7 @@ use Cake\Http\Response;
 class Mime extends Response {
 
 	/**
-	 * @var array
+	 * @var array<string, array>
 	 */
 	protected $_mimeTypesExt = [
 		'3dm' => 'x-world/x-3dmf',
@@ -699,6 +699,11 @@ class Mime extends Response {
 	];
 
 	/**
+	 * @var array<string, array>
+	 */
+	protected $_mimeTypesTmp = [];
+
+	/**
 	 * Override constructor
 	 *
 	 * @param array<string, mixed> $options
@@ -731,7 +736,7 @@ class Mime extends Response {
 	 * @return mixed string mapped mime type or false if $alias is not mapped
 	 */
 	public function getMimeTypeByAlias($alias, $primaryOnly = true, $coreHasPrecedence = false) {
-		if (empty($this->_mimeTypeTmp)) {
+		if (!$this->_mimeTypesTmp) {
 			$this->_mimeTypesTmp = $this->mimeTypes($coreHasPrecedence);
 		}
 		if (!isset($this->_mimeTypesTmp[$alias])) {

+ 1 - 1
src/Utility/Time.php

@@ -522,7 +522,7 @@ class Time extends CakeTime {
 			}
 		}
 
-		$date = $date->timezone($options['timezone']);
+		$date = $date->setTimezone($options['timezone']);
 		$ret = $date->format($format);
 
 		if (!empty($options['oclock'])) {

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

@@ -105,7 +105,7 @@ class CommonHelper extends Helper {
 		}
 
 		$content = (array)$content;
-		$return = '<meta name="' . $name . '" content="' . implode(', ', $content) . '" />';
+		$return = '<meta name="' . $name . '" content="' . implode(', ', $content) . '">';
 
 		return $return;
 	}
@@ -212,7 +212,7 @@ class CommonHelper extends Helper {
 	 */
 	public function metaRss($url, ?string $title = null): string {
 		$tags = [
-			'meta' => '<link rel="alternate" type="application/rss+xml" title="%s" href="%s"/>',
+			'meta' => '<link rel="alternate" type="application/rss+xml" title="%s" href="%s">',
 		];
 		if (!$title) {
 			$title = __d('tools', 'Subscribe to this feed');

+ 16 - 3
src/View/Helper/NumberHelper.php

@@ -2,6 +2,9 @@
 
 namespace Tools\View\Helper;
 
+use Cake\Core\App;
+use Cake\Core\Exception\CakeException;
+use Cake\I18n\Number;
 use Cake\Utility\Hash;
 use Cake\View\Helper\NumberHelper as CakeNumberHelper;
 use Cake\View\View;
@@ -19,13 +22,23 @@ class NumberHelper extends CakeNumberHelper {
 	 * - `engine` Class name to use to replace Number functionality.
 	 *            The class needs to be placed in the `Utility` directory.
 	 *
-	 * @param \Cake\View\View $View The View this helper is being attached to.
+	 * @param \Cake\View\View $view The View this helper is being attached to.
 	 * @param array<string, mixed> $config Configuration settings for the helper
 	 */
-	public function __construct(View $View, array $config = []) {
+	public function __construct(View $view, array $config = []) {
 		$config = Hash::merge(['engine' => 'Tools.Number'], $config);
 
-		parent::__construct($View, $config);
+		$engine = $config['engine'];
+		$config['engine'] = Number::class;
+		parent::__construct($view, $config);
+
+		$this->setConfig('engine', $engine);
+		$engineClass = App::className($engine, 'Utility');
+		if ($engineClass === null) {
+			throw new CakeException(sprintf('Class for %s could not be found', $engine));
+		}
+
+		$this->_engine = new $engineClass($config);
 	}
 
 }

+ 17 - 5
src/View/Helper/TextHelper.php

@@ -2,7 +2,9 @@
 
 namespace Tools\View\Helper;
 
-use Cake\Utility\Hash;
+use Cake\Core\App;
+use Cake\Core\Exception\CakeException;
+use Cake\Utility\Text;
 use Cake\View\Helper\TextHelper as CakeTextHelper;
 use Cake\View\View;
 use Tools\Utility\Number;
@@ -36,13 +38,23 @@ class TextHelper extends CakeTextHelper {
 	 * - `engine` Class name to use to replace Text functionality.
 	 *            The class needs to be placed in the `Utility` directory.
 	 *
-	 * @param \Cake\View\View $View the view object the helper is attached to.
+	 * @param \Cake\View\View $view the view object the helper is attached to.
 	 * @param array<string, mixed> $config Settings array Settings array
 	 */
-	public function __construct(View $View, array $config = []) {
-		$config = Hash::merge(['engine' => 'Tools.Text'], $config);
+	public function __construct(View $view, array $config = []) {
+		$config += ['engine' => 'Tools.Text'];
 
-		parent::__construct($View, $config);
+		$engine = $config['engine'];
+		$config['engine'] = Text::class;
+		parent::__construct($view, $config);
+
+		$this->setConfig('engine', $engine);
+		$engineClass = App::className($engine, 'Utility');
+		if ($engineClass === null) {
+			throw new CakeException(sprintf('Class for %s could not be found', $engine));
+		}
+
+		$this->_engine = new $engineClass($config);
 	}
 
 	/**

+ 13 - 13
tests/TestCase/View/Helper/CommonHelperTest.php

@@ -50,7 +50,7 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaName() {
 		$result = $this->Common->metaName('foo', [1, 2, 3]);
-		$expected = '<meta name="foo" content="1, 2, 3" />';
+		$expected = '<meta name="foo" content="1, 2, 3">';
 		$this->assertEquals($expected, $result);
 	}
 
@@ -61,7 +61,7 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaDescription() {
 		$result = $this->Common->metaDescription('foo', 'deu');
-		$expected = '<meta lang="deu" name="description" content="foo"/>';
+		$expected = '<meta lang="deu" name="description" content="foo">';
 		$this->assertEquals($expected, $result);
 	}
 
@@ -72,7 +72,7 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaKeywords() {
 		$result = $this->Common->metaKeywords('foo bar', 'deu');
-		$expected = '<meta lang="deu" name="keywords" content="foo bar"/>';
+		$expected = '<meta lang="deu" name="keywords" content="foo bar">';
 		$this->assertEquals($expected, $result);
 	}
 
@@ -83,7 +83,7 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaRss() {
 		$result = $this->Common->metaRss('/some/url', 'some title');
-		$expected = '<link rel="alternate" type="application/rss+xml" title="some title" href="/some/url"/>';
+		$expected = '<link rel="alternate" type="application/rss+xml" title="some title" href="/some/url">';
 		$this->assertEquals($expected, $result);
 	}
 
@@ -103,10 +103,10 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaCanonical() {
 		$is = $this->Common->metaCanonical('/some/url/param1');
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1') . '" rel="canonical"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1') . '" rel="canonical">', trim($is));
 
 		$is = $this->Common->metaCanonical('/some/url/param1', true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', ['fullBase' => true]) . '" rel="canonical"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', ['fullBase' => true]) . '" rel="canonical">', trim($is));
 	}
 
 	/**
@@ -114,19 +114,19 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaAlternate() {
 		$is = $this->Common->metaAlternate('/some/url/param1', 'de-de', true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', ['fullBase' => true]) . '" rel="alternate" hreflang="de-de"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', ['fullBase' => true]) . '" rel="alternate" hreflang="de-de">', trim($is));
 
 		$is = $this->Common->metaAlternate(['controller' => 'Some', 'action' => 'url'], 'de', true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de">', trim($is));
 
 		$is = $this->Common->metaAlternate(['controller' => 'Some', 'action' => 'url'], ['de', 'de-ch'], true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de"/>' . PHP_EOL . '<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de-ch"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de">' . PHP_EOL . '<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de-ch">', trim($is));
 
 		$is = $this->Common->metaAlternate(['controller' => 'Some', 'action' => 'url'], ['de' => ['ch', 'at'], 'en' => ['gb', 'us']], true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de-ch"/>' . PHP_EOL .
-			'<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de-at"/>' . PHP_EOL .
-			'<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="en-gb"/>' . PHP_EOL .
-			'<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="en-us"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de-ch">' . PHP_EOL .
+			'<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="de-at">' . PHP_EOL .
+			'<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="en-gb">' . PHP_EOL .
+			'<link href="' . $this->Common->Url->build('/some/url', ['fullBase' => true]) . '" rel="alternate" hreflang="en-us">', trim($is));
 	}
 
 	/**

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

@@ -173,11 +173,11 @@ class GravatarHelperTest extends TestCase {
 	 * @return void
 	 */
 	public function testImageTag() {
-		$expected = '<img src="http://www.gravatar.com/avatar/' . md5('example@gravatar.com') . '" alt=""/>';
+		$expected = '<img src="http://www.gravatar.com/avatar/' . md5('example@gravatar.com') . '" alt="">';
 		$result = $this->Gravatar->image('example@gravatar.com', ['ext' => false]);
 		$this->assertEquals($expected, $result);
 
-		$expected = '<img src="http://www.gravatar.com/avatar/' . md5('example@gravatar.com') . '" alt="Gravatar"/>';
+		$expected = '<img src="http://www.gravatar.com/avatar/' . md5('example@gravatar.com') . '" alt="Gravatar">';
 		$result = $this->Gravatar->image('example@gravatar.com', ['ext' => false, 'alt' => 'Gravatar']);
 		$this->assertEquals($expected, $result);
 	}

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

@@ -63,7 +63,7 @@ class QrCodeHelperTest extends TestCase {
 	public function testImage() {
 		$is = $this->QrCode->image('Foo Bar');
 
-		$expected = '<img src="http://chart.apis.google.com/chart?chl=Foo%20Bar&amp;cht=qr&amp;choe=UTF-8&amp;chs=74x74&amp;chld=" alt=""/>';
+		$expected = '<img src="http://chart.apis.google.com/chart?chl=Foo%20Bar&amp;cht=qr&amp;choe=UTF-8&amp;chs=74x74&amp;chld=" alt="">';
 		$this->assertSame($expected, $is);
 	}
 

+ 3 - 3
tests/TestCase/View/Helper/TreeHelperTest.php

@@ -470,7 +470,7 @@ TEXT;
 		$tree = $this->Table->find('threaded')->toArray();
 		$id = 6;
 		$nodes = $this->Table->find('path', ['for' => $id]);
-		$path = $nodes->extract('id')->toArray();
+		$path = $nodes->all()->extract('id')->toArray();
 
 		$output = $this->Tree->generate($tree, ['autoPath' => [6, 11], 'hideUnrelated' => true, 'treePath' => $path, 'callback' => [$this, '_myCallback']]); // Two-SubA
 
@@ -528,7 +528,7 @@ TEXT;
 
 		$id = 6; // Two-SubA
 		$nodes = $this->Table->find('path', ['for' => $id]);
-		$path = $nodes->extract('id')->toArray();
+		$path = $nodes->all()->extract('id')->toArray();
 
 		$output = $this->Tree->generate($tree, [
 			'autoPath' => [6, 11], 'hideUnrelated' => true, 'treePath' => $path,
@@ -620,7 +620,7 @@ TEXT;
 
 		$id = 6;
 		$nodes = $this->Table->find('path', ['for' => $id]);
-		$path = $nodes->extract('id')->toArray();
+		$path = $nodes->all()->extract('id')->toArray();
 
 		$output = $this->Tree->generate($tree, [
 			'autoPath' => [6, 11], 'treePath' => $path,