Merge pull request #10588 from creative-commoners/pulls/4/stop-using-depr

API Stop using deprecated API
This commit is contained in:
Sabina Talipova 2022-12-05 16:35:09 +13:00 committed by GitHub
commit 4e1b99b8c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 80 additions and 33 deletions

View File

@ -281,7 +281,7 @@ class Convert
*/ */
public static function json2array($val) public static function json2array($val)
{ {
Deprecation::notice('4.4.0', 'Use json_decode() instead'); Deprecation::notice('4.4.0', 'Use json_decode($val, true) instead');
return json_decode($val ?? '', true); return json_decode($val ?? '', true);
} }
@ -331,9 +331,11 @@ class Convert
* @param SimpleXMLElement $xml * @param SimpleXMLElement $xml
* *
* @return mixed * @return mixed
* @deprecated 4.11.0 Will be removed without equivalent functionality
*/ */
protected static function recursiveXMLToArray($xml) protected static function recursiveXMLToArray($xml)
{ {
Deprecation::notice('4.11.0', 'Will be removed without equivalent functionality');
$x = null; $x = null;
if ($xml instanceof SimpleXMLElement) { if ($xml instanceof SimpleXMLElement) {
$attributes = $xml->attributes(); $attributes = $xml->attributes();

View File

@ -183,7 +183,9 @@ class CsvBulkLoader extends BulkLoader
$lines = $this->config()->get("lines"); $lines = $this->config()->get("lines");
} }
$new = $this->getNewSplitFileName(); $new = Deprecation::withNoReplacement(function () {
return $this->getNewSplitFileName();
});
$to = fopen($new ?? '', 'w+'); $to = fopen($new ?? '', 'w+');
$from = fopen($path ?? '', 'r'); $from = fopen($path ?? '', 'r');
@ -209,7 +211,9 @@ class CsvBulkLoader extends BulkLoader
fclose($to); fclose($to);
// get a new temporary file name, to write the next lines to // get a new temporary file name, to write the next lines to
$new = $this->getNewSplitFileName(); $new = Deprecation::withNoReplacement(function () {
return $this->getNewSplitFileName();
});
$to = fopen($new ?? '', 'w+'); $to = fopen($new ?? '', 'w+');

View File

@ -228,16 +228,23 @@ class Deprecation
if (!self::isEnabled()) { if (!self::isEnabled()) {
return; return;
} }
$outputMessages = [];
// using a while loop with array_shift() to ensure that self::$userErrorMessageBuffer will have // using a while loop with array_shift() to ensure that self::$userErrorMessageBuffer will have
// have values removed from it before calling user_error() // have values removed from it before calling user_error()
while (count(self::$userErrorMessageBuffer)) { while (count(self::$userErrorMessageBuffer)) {
$arr = array_shift(self::$userErrorMessageBuffer); $arr = array_shift(self::$userErrorMessageBuffer);
$message = $arr['message']; $message = $arr['message'];
// often the same deprecation message appears dozens of times, which isn't helpful
// only need to show a single instance of each message
if (in_array($message, $outputMessages)) {
continue;
}
$calledInsideWithNoReplacement = $arr['calledInsideWithNoReplacement']; $calledInsideWithNoReplacement = $arr['calledInsideWithNoReplacement'];
if ($calledInsideWithNoReplacement && !self::$showNoReplacementNotices) { if ($calledInsideWithNoReplacement && !self::$showNoReplacementNotices) {
continue; continue;
} }
user_error($message, E_USER_DEPRECATED); user_error($message, E_USER_DEPRECATED);
$outputMessages[] = $message;
} }
} }

View File

@ -49,6 +49,7 @@ use SilverStripe\Security\Member;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
use SilverStripe\Dev\Deprecation;
/* ------------------------------------------------- /* -------------------------------------------------
* *
@ -568,7 +569,9 @@ if (class_exists(IsEqualCanonicalizing::class)) {
{ {
Deprecation::notice('4.0.1', 'Use FixtureTestState instead'); Deprecation::notice('4.0.1', 'Use FixtureTestState instead');
$fixture = Injector::inst()->create(YamlFixture::class, $fixtureFile); $fixture = Injector::inst()->create(YamlFixture::class, $fixtureFile);
Deprecation::withNoReplacement(function () use ($fixture) {
$fixture->writeInto($this->getFixtureFactory()); $fixture->writeInto($this->getFixtureFactory());
});
} }
/** /**
@ -1008,7 +1011,9 @@ if (class_exists(IsEqualCanonicalizing::class)) {
$kernel = new TestKernel(BASE_PATH); $kernel = new TestKernel(BASE_PATH);
// PHPUnit 9 only logic to exclude old test still targeting PHPUNit 5.7 // PHPUnit 9 only logic to exclude old test still targeting PHPUNit 5.7
Deprecation::withNoReplacement(function () use ($kernel) {
$kernel->setIgnoredCIConfigs([Module::CI_PHPUNIT_FIVE, Module::CI_UNKNOWN]); $kernel->setIgnoredCIConfigs([Module::CI_PHPUNIT_FIVE, Module::CI_UNKNOWN]);
});
if (class_exists(HTTPApplication::class)) { if (class_exists(HTTPApplication::class)) {
// Mock request // Mock request

View File

@ -834,7 +834,9 @@ class Member extends DataObject
public static function create_new_password() public static function create_new_password()
{ {
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it'); Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
$words = Security::config()->uninherited('word_list'); $words = Deprecation::withNoReplacement(function () {
return Security::config()->uninherited('word_list');
});
if ($words && file_exists($words ?? '')) { if ($words && file_exists($words ?? '')) {
$words = file($words ?? ''); $words = file($words ?? '');

View File

@ -143,6 +143,7 @@ class Requirements_Backend
* Use the injected minification service to minify any javascript file passed to {@link combine_files()}. * Use the injected minification service to minify any javascript file passed to {@link combine_files()}.
* *
* @var bool * @var bool
* @deprecated 4.0.1 Will be removed without equivalent functionality
*/ */
protected $minifyCombinedFiles = false; protected $minifyCombinedFiles = false;
@ -212,6 +213,7 @@ class Requirements_Backend
/** /**
* @var Requirements_Minifier * @var Requirements_Minifier
* @deprecated 4.0.1 Will be removed without equivalent functionality
*/ */
protected $minifier = null; protected $minifier = null;
@ -251,9 +253,11 @@ class Requirements_Backend
* Set a new minification service for this backend * Set a new minification service for this backend
* *
* @param Requirements_Minifier $minifier * @param Requirements_Minifier $minifier
* @deprecated 4.0.1 Will be removed without equivalent functionality
*/ */
public function setMinifier(Requirements_Minifier $minifier = null) public function setMinifier(Requirements_Minifier $minifier = null)
{ {
Deprecation::notice('4.0.1', 'Will be removed without equivalent functionality');
$this->minifier = $minifier; $this->minifier = $minifier;
} }
@ -389,9 +393,11 @@ class Requirements_Backend
* Check if minify files should be combined * Check if minify files should be combined
* *
* @return bool * @return bool
* @deprecated 4.0.1 Will be removed without equivalent functionality
*/ */
public function getMinifyCombinedFiles() public function getMinifyCombinedFiles()
{ {
Deprecation::notice('4.0.1', 'Will be removed without equivalent functionality');
return $this->minifyCombinedFiles; return $this->minifyCombinedFiles;
} }
@ -400,9 +406,11 @@ class Requirements_Backend
* *
* @param bool $minify * @param bool $minify
* @return $this * @return $this
* @deprecated 4.0.1 Will be removed without equivalent functionality
*/ */
public function setMinifyCombinedFiles($minify) public function setMinifyCombinedFiles($minify)
{ {
Deprecation::notice('4.0.1', 'Will be removed without equivalent functionality');
$this->minifyCombinedFiles = $minify; $this->minifyCombinedFiles = $minify;
return $this; return $this;
} }
@ -1381,15 +1389,16 @@ class Requirements_Backend
$combinedFileID = File::join_paths($this->getCombinedFilesFolder(), $combinedFile); $combinedFileID = File::join_paths($this->getCombinedFilesFolder(), $combinedFile);
// Send file combination request to the backend, with an optional callback to perform regeneration // Send file combination request to the backend, with an optional callback to perform regeneration
$minify = Deprecation::withNoReplacement(function () {
$minify = $this->getMinifyCombinedFiles(); $minify = $this->getMinifyCombinedFiles();
if ($minify && !$this->minifier) { if ($minify && !$this->minifier) {
throw new Exception( throw new Exception(
sprintf( sprintf(
<<<MESSAGE <<<MESSAGE
Cannot minify files without a minification service defined. Cannot minify files without a minification service defined.
Set %s::minifyCombinedFiles to false, or inject a %s service on Set %s::minifyCombinedFiles to false, or inject a %s service on
%s.properties.minifier %s.properties.minifier
MESSAGE MESSAGE
, ,
__CLASS__, __CLASS__,
Requirements_Minifier::class, Requirements_Minifier::class,
@ -1397,6 +1406,8 @@ MESSAGE
) )
); );
} }
return $minify;
});
$combinedURL = $this $combinedURL = $this
->getAssetHandler() ->getAssetHandler()
@ -1416,6 +1427,7 @@ MESSAGE
$fileContent = $this->resolveCSSReferences($fileContent, $file); $fileContent = $this->resolveCSSReferences($fileContent, $file);
} }
// Use configured minifier // Use configured minifier
// @deprecated
if ($minify) { if ($minify) {
$fileContent = $this->minifier->minify($fileContent, $type, $file); $fileContent = $this->minifier->minify($fileContent, $type, $file);
} }

View File

@ -74,7 +74,7 @@ class SSViewer implements Flushable
* The used "theme", which usually consists of templates, images and stylesheets. * The used "theme", which usually consists of templates, images and stylesheets.
* Only used when {@link $theme_enabled} is set to TRUE, and $themes is empty * Only used when {@link $theme_enabled} is set to TRUE, and $themes is empty
* *
* @deprecated 4.0.0:5.0.0 * @deprecated 4.0.0 Use themes config instead
* @config * @config
* @var string * @var string
*/ */

View File

@ -419,7 +419,9 @@ PHP
*/ */
public function testXML2Array() public function testXML2Array()
{ {
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$inputXML = <<<XML $inputXML = <<<XML
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE results [ <!DOCTYPE results [
@ -449,6 +451,9 @@ XML
*/ */
public function testXML2ArrayEntityException() public function testXML2ArrayEntityException()
{ {
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$inputXML = <<<XML $inputXML = <<<XML
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE results [ <!DOCTYPE results [
@ -469,6 +474,9 @@ XML
*/ */
public function testXML2ArrayMultipleEntitiesException() public function testXML2ArrayMultipleEntitiesException()
{ {
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$inputXML = <<<XML $inputXML = <<<XML
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE results [<!ENTITY long "SOME_SUPER_LONG_STRING"><!ENTITY short "SHORT_STRING">]> <!DOCTYPE results [<!ENTITY long "SOME_SUPER_LONG_STRING"><!ENTITY short "SHORT_STRING">]>

View File

@ -117,7 +117,7 @@ class ObjectTest extends SapphireTest
$obj = singleton(MyObject::class); $obj = singleton(MyObject::class);
$this->assertEquals( $this->assertEquals(
'MyObject', 'MyObject',
$obj->stat('mystaticProperty'), $obj::config()->get('mystaticProperty'),
'Uninherited statics through stat() on a singleton behave the same as built-in PHP statics' 'Uninherited statics through stat() on a singleton behave the same as built-in PHP statics'
); );
} }
@ -129,7 +129,7 @@ class ObjectTest extends SapphireTest
} }
$subObj = singleton(MyObject::class); $subObj = singleton(MyObject::class);
$this->assertEquals( $this->assertEquals(
$subObj->stat('mystaticProperty'), $subObj::config()->get('mystaticProperty'),
'MyObject', 'MyObject',
'Statics defined on a parent class are available through stat() on a subclass' 'Statics defined on a parent class are available through stat() on a subclass'
); );
@ -144,7 +144,7 @@ class ObjectTest extends SapphireTest
$singleton2 = singleton(MyObject::class); $singleton2 = singleton(MyObject::class);
$singleton1->set_stat('mystaticProperty', 'changed'); $singleton1->set_stat('mystaticProperty', 'changed');
$this->assertEquals( $this->assertEquals(
$singleton2->stat('mystaticProperty'), $singleton2::config()->get('mystaticProperty'),
'changed', 'changed',
'Statics setting is populated throughout singletons without explicitly clearing cache' 'Statics setting is populated throughout singletons without explicitly clearing cache'
); );
@ -159,7 +159,7 @@ class ObjectTest extends SapphireTest
$instance2 = new ObjectTest\MyObject(); $instance2 = new ObjectTest\MyObject();
$instance1->set_stat('mystaticProperty', 'changed'); $instance1->set_stat('mystaticProperty', 'changed');
$this->assertEquals( $this->assertEquals(
$instance2->stat('mystaticProperty'), $instance2::config()->get('mystaticProperty'),
'changed', 'changed',
'Statics setting through set_stat() is populated throughout instances without explicitly clearing cache' 'Statics setting through set_stat() is populated throughout instances without explicitly clearing cache'
); );

View File

@ -20,6 +20,9 @@ class MonologErrorHandlerTest extends SapphireTest
public function testSetLoggerResetsStack() public function testSetLoggerResetsStack()
{ {
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var LoggerInterface $logger */ /** @var LoggerInterface $logger */
$logger = $this->createMock(LoggerInterface::class); $logger = $this->createMock(LoggerInterface::class);
@ -27,10 +30,8 @@ class MonologErrorHandlerTest extends SapphireTest
$handler->pushLogger($logger)->pushLogger($logger); $handler->pushLogger($logger)->pushLogger($logger);
$this->assertCount(2, $handler->getLoggers(), 'Loggers are pushed to the stack'); $this->assertCount(2, $handler->getLoggers(), 'Loggers are pushed to the stack');
if (!Deprecation::isEnabled()) {
$handler->setLogger($logger); $handler->setLogger($logger);
$this->assertCount(1, $handler->getLoggers(), 'setLogger resets stack and pushes'); $this->assertCount(1, $handler->getLoggers(), 'setLogger resets stack and pushes');
}
$handler->setLoggers([]); $handler->setLoggers([]);
$this->assertCount(0, $handler->getLoggers(), 'setLoggers overwrites all configured loggers'); $this->assertCount(0, $handler->getLoggers(), 'setLoggers overwrites all configured loggers');

View File

@ -14,6 +14,7 @@ use SilverStripe\View\Requirements_Backend;
use SilverStripe\Core\Manifest\ResourceURLGenerator; use SilverStripe\Core\Manifest\ResourceURLGenerator;
use SilverStripe\Control\SimpleResourceURLGenerator; use SilverStripe\Control\SimpleResourceURLGenerator;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\Deprecation;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
use SilverStripe\View\ThemeResourceLoader; use SilverStripe\View\ThemeResourceLoader;
@ -302,7 +303,9 @@ class RequirementsTest extends SapphireTest
$backend->clear(); $backend->clear();
$backend->clearCombinedFiles(); $backend->clearCombinedFiles();
$backend->setCombinedFilesFolder('_combinedfiles'); $backend->setCombinedFilesFolder('_combinedfiles');
Deprecation::withNoReplacement(function () use ($backend) {
$backend->setMinifyCombinedFiles(false); $backend->setMinifyCombinedFiles(false);
});
$backend->setCombinedFilesEnabled(true); $backend->setCombinedFilesEnabled(true);
Requirements::flush(); Requirements::flush();
} }

View File

@ -277,6 +277,9 @@ class SSViewerTest extends SapphireTest
public function testRequirementsMinification() public function testRequirementsMinification()
{ {
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var Requirements_Backend $testBackend */ /** @var Requirements_Backend $testBackend */
$testBackend = Injector::inst()->create(Requirements_Backend::class); $testBackend = Injector::inst()->create(Requirements_Backend::class);
$testBackend->setSuffixRequirements(false); $testBackend->setSuffixRequirements(false);