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
|
<?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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -142,7 +142,7 @@ trait DolDeprecationHandler
|
||||||
if ($this->isDeprecatedReportingEnabled()) {
|
if ($this->isDeprecatedReportingEnabled()) {
|
||||||
trigger_error($msg, E_USER_DEPRECATED);
|
trigger_error($msg, E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
return isset($newProperty);
|
return isset($this->$newProperty);
|
||||||
} elseif ($this->isDynamicPropertiesEnabled()) {
|
} elseif ($this->isDynamicPropertiesEnabled()) {
|
||||||
return isset($this->$name);
|
return isset($this->$name);
|
||||||
}
|
}
|
||||||
|
|
@ -203,7 +203,7 @@ trait DolDeprecationHandler
|
||||||
{
|
{
|
||||||
// By default, if enableDynamicProperties is set, use that value.
|
// 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.
|
// If the property exists, then we use it.
|
||||||
return (bool) $this->enableDynamicProperties;
|
return (bool) $this->enableDynamicProperties;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?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
|
* 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
|
* 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 () {
|
$this->handler = new class () {
|
||||||
use DolDeprecationHandler;
|
use DolDeprecationHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool Configuration enabling throwing exceptions
|
||||||
|
* for deprecated access.
|
||||||
|
*/
|
||||||
|
private $enableDeprecatedReporting = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Private var to check that magic
|
* @var string Private var to check that magic
|
||||||
* is triggered.
|
* is triggered.
|
||||||
|
|
@ -256,7 +262,15 @@ class DolDeprecationHandlerTest extends CommonClassTest
|
||||||
*/
|
*/
|
||||||
public function testDeprecatedPropertyUnset()
|
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);
|
unset($this->handler->oldProperty);
|
||||||
$this->assertFalse(isset($this->handler->newProperty));
|
$this->assertFalse(isset($this->handler->newProperty));
|
||||||
}
|
}
|
||||||
|
|
@ -288,7 +302,7 @@ class DolDeprecationHandlerTest extends CommonClassTest
|
||||||
$this->expectExceptionMessage("Undefined property 'privateVarShouldTrigger'");
|
$this->expectExceptionMessage("Undefined property 'privateVarShouldTrigger'");
|
||||||
$this->handler->privateVarShouldTrigger;
|
$this->handler->privateVarShouldTrigger;
|
||||||
|
|
||||||
$this->expectExceptionMessage("Accessing deprecated property 'privateDeprecated'. Use 'newProperty' instead.");
|
$this->expectExceptionMessage("Accessing deprecated property 'privateDeprecated'");
|
||||||
$this->handler->privateDeprecated;
|
$this->handler->privateDeprecated;
|
||||||
|
|
||||||
// Restore error_reporting
|
// Restore error_reporting
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user