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)
{
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);
}
@ -331,9 +331,11 @@ class Convert
* @param SimpleXMLElement $xml
*
* @return mixed
* @deprecated 4.11.0 Will be removed without equivalent functionality
*/
protected static function recursiveXMLToArray($xml)
{
Deprecation::notice('4.11.0', 'Will be removed without equivalent functionality');
$x = null;
if ($xml instanceof SimpleXMLElement) {
$attributes = $xml->attributes();

View File

@ -183,7 +183,9 @@ class CsvBulkLoader extends BulkLoader
$lines = $this->config()->get("lines");
}
$new = $this->getNewSplitFileName();
$new = Deprecation::withNoReplacement(function () {
return $this->getNewSplitFileName();
});
$to = fopen($new ?? '', 'w+');
$from = fopen($path ?? '', 'r');
@ -209,7 +211,9 @@ class CsvBulkLoader extends BulkLoader
fclose($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+');

View File

@ -228,16 +228,23 @@ class Deprecation
if (!self::isEnabled()) {
return;
}
$outputMessages = [];
// using a while loop with array_shift() to ensure that self::$userErrorMessageBuffer will have
// have values removed from it before calling user_error()
while (count(self::$userErrorMessageBuffer)) {
$arr = array_shift(self::$userErrorMessageBuffer);
$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'];
if ($calledInsideWithNoReplacement && !self::$showNoReplacementNotices) {
continue;
}
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\Security;
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');
$fixture = Injector::inst()->create(YamlFixture::class, $fixtureFile);
$fixture->writeInto($this->getFixtureFactory());
Deprecation::withNoReplacement(function () use ($fixture) {
$fixture->writeInto($this->getFixtureFactory());
});
}
/**
@ -1008,7 +1011,9 @@ if (class_exists(IsEqualCanonicalizing::class)) {
$kernel = new TestKernel(BASE_PATH);
// PHPUnit 9 only logic to exclude old test still targeting PHPUNit 5.7
$kernel->setIgnoredCIConfigs([Module::CI_PHPUNIT_FIVE, Module::CI_UNKNOWN]);
Deprecation::withNoReplacement(function () use ($kernel) {
$kernel->setIgnoredCIConfigs([Module::CI_PHPUNIT_FIVE, Module::CI_UNKNOWN]);
});
if (class_exists(HTTPApplication::class)) {
// Mock request

View File

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

View File

@ -419,7 +419,9 @@ PHP
*/
public function testXML2Array()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$inputXML = <<<XML
<?xml version="1.0"?>
<!DOCTYPE results [
@ -449,6 +451,9 @@ XML
*/
public function testXML2ArrayEntityException()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$inputXML = <<<XML
<?xml version="1.0"?>
<!DOCTYPE results [
@ -469,6 +474,9 @@ XML
*/
public function testXML2ArrayMultipleEntitiesException()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$inputXML = <<<XML
<?xml version="1.0"?>
<!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);
$this->assertEquals(
'MyObject',
$obj->stat('mystaticProperty'),
$obj::config()->get('mystaticProperty'),
'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);
$this->assertEquals(
$subObj->stat('mystaticProperty'),
$subObj::config()->get('mystaticProperty'),
'MyObject',
'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);
$singleton1->set_stat('mystaticProperty', 'changed');
$this->assertEquals(
$singleton2->stat('mystaticProperty'),
$singleton2::config()->get('mystaticProperty'),
'changed',
'Statics setting is populated throughout singletons without explicitly clearing cache'
);
@ -159,7 +159,7 @@ class ObjectTest extends SapphireTest
$instance2 = new ObjectTest\MyObject();
$instance1->set_stat('mystaticProperty', 'changed');
$this->assertEquals(
$instance2->stat('mystaticProperty'),
$instance2::config()->get('mystaticProperty'),
'changed',
'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()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var LoggerInterface $logger */
$logger = $this->createMock(LoggerInterface::class);
@ -27,10 +30,8 @@ class MonologErrorHandlerTest extends SapphireTest
$handler->pushLogger($logger)->pushLogger($logger);
$this->assertCount(2, $handler->getLoggers(), 'Loggers are pushed to the stack');
if (!Deprecation::isEnabled()) {
$handler->setLogger($logger);
$this->assertCount(1, $handler->getLoggers(), 'setLogger resets stack and pushes');
}
$handler->setLogger($logger);
$this->assertCount(1, $handler->getLoggers(), 'setLogger resets stack and pushes');
$handler->setLoggers([]);
$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\Control\SimpleResourceURLGenerator;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\Deprecation;
use SilverStripe\View\SSViewer;
use SilverStripe\View\ThemeResourceLoader;
@ -302,7 +303,9 @@ class RequirementsTest extends SapphireTest
$backend->clear();
$backend->clearCombinedFiles();
$backend->setCombinedFilesFolder('_combinedfiles');
$backend->setMinifyCombinedFiles(false);
Deprecation::withNoReplacement(function () use ($backend) {
$backend->setMinifyCombinedFiles(false);
});
$backend->setCombinedFilesEnabled(true);
Requirements::flush();
}

View File

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