mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Merge pull request #33140 from mdeweerd/fix/deprecationhandler.isset
Fix: DeprecationHandler, correct isset(), ignore false phpstan positive
This commit is contained in:
commit
bc5f62d25b
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
/* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -142,7 +142,7 @@ trait DolDeprecationHandler
|
|||
if ($this->isDeprecatedReportingEnabled()) {
|
||||
trigger_error($msg, E_USER_DEPRECATED);
|
||||
}
|
||||
return isset($newProperty);
|
||||
return isset($this->$newProperty);
|
||||
} elseif ($this->isDynamicPropertiesEnabled()) {
|
||||
return isset($this->$name);
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ trait DolDeprecationHandler
|
|||
{
|
||||
// By default, if enableDynamicProperties is set, use that value.
|
||||
|
||||
if (property_exists($this, 'enableDynamicProperties')) {
|
||||
if (property_exists($this, 'enableDynamicProperties')) { // @phpstan-ignore-line
|
||||
// If the property exists, then we use it.
|
||||
return (bool) $this->enableDynamicProperties;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
/* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -72,6 +72,12 @@ class DolDeprecationHandlerTest extends CommonClassTest
|
|||
$this->handler = new class () {
|
||||
use DolDeprecationHandler;
|
||||
|
||||
/**
|
||||
* @var bool Configuration enabling throwing exceptions
|
||||
* for deprecated access.
|
||||
*/
|
||||
private $enableDeprecatedReporting = true;
|
||||
|
||||
/**
|
||||
* @var string Private var to check that magic
|
||||
* is triggered.
|
||||
|
|
@ -256,7 +262,15 @@ class DolDeprecationHandlerTest extends CommonClassTest
|
|||
*/
|
||||
public function testDeprecatedPropertyUnset()
|
||||
{
|
||||
$this->handler->newProperty = "TestUnset";
|
||||
// Initially the new property should be unset
|
||||
$this->assertFalse(isset($this->handler->newProperty));
|
||||
|
||||
// Then we set the new property, so it should be set
|
||||
$this->handler->newProperty = "ValueIsSet";
|
||||
$this->assertTrue(isset($this->handler->newProperty));
|
||||
|
||||
// Then we set the new property using the old name,
|
||||
// so it should be unset.
|
||||
unset($this->handler->oldProperty);
|
||||
$this->assertFalse(isset($this->handler->newProperty));
|
||||
}
|
||||
|
|
@ -288,7 +302,7 @@ class DolDeprecationHandlerTest extends CommonClassTest
|
|||
$this->expectExceptionMessage("Undefined property 'privateVarShouldTrigger'");
|
||||
$this->handler->privateVarShouldTrigger;
|
||||
|
||||
$this->expectExceptionMessage("Accessing deprecated property 'privateDeprecated'. Use 'newProperty' instead.");
|
||||
$this->expectExceptionMessage("Accessing deprecated property 'privateDeprecated'");
|
||||
$this->handler->privateDeprecated;
|
||||
|
||||
// Restore error_reporting
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user