Skip to content

Commit ab8ed1c

Browse files
committed
:octocat: PHP 8.4+
1 parent a0a487c commit ab8ed1c

7 files changed

Lines changed: 33 additions & 58 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ jobs:
3131
fail-fast: true
3232
matrix:
3333
php-version:
34-
- "8.1"
35-
- "8.2"
36-
- "8.3"
3734
- "8.4"
38-
# - "8.5"
35+
- "8.5"
3936

4037
steps:
4138
- name: "Checkout"
@@ -105,9 +102,6 @@ jobs:
105102
- ubuntu-latest
106103
- windows-latest
107104
php-version:
108-
- "8.1"
109-
- "8.2"
110-
- "8.3"
111105
- "8.4"
112106
- "8.5"
113107

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ A container class for settings objects - decouple configuration logic from your
3535
```json
3636
{
3737
"require": {
38-
"php": "^8.1",
38+
"php": "^8.4",
3939
"chillerlan/php-settings-container": "dev-main"
4040
}
4141
}

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
"source": "https://github.com/chillerlan/php-settings-container"
2121
},
2222
"require": {
23-
"php": "^8.1",
23+
"php": "^8.4",
2424
"ext-json": "*"
2525
},
2626
"require-dev": {
27-
"phan/phan": "^5.5.2",
27+
"phan/phan": "^6.0.2",
2828
"phpmd/phpmd": "^2.15",
29-
"phpstan/phpstan": "^2.1.31",
30-
"phpstan/phpstan-deprecation-rules": "^2.0.3",
31-
"phpunit/phpunit": "^10.5",
32-
"slevomat/coding-standard": "^8.22",
29+
"phpstan/phpstan": "^2.1.41",
30+
"phpstan/phpstan-deprecation-rules": "^2.0.4",
31+
"phpunit/phpunit": "^13.0",
32+
"slevomat/coding-standard": "^8.28",
3333
"squizlabs/php_codesniffer": "^4.0"
3434
},
3535
"autoload": {

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
cacheResultFile=".build/phpunit.result.cache"
5+
cacheDirectory=".build/phpunit-cache"
66
colors="true"
77
>
88
<testsuites>

src/Attributes/ThrowOnInvalidProperty.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
use Attribute;
1515

1616
/**
17-
* Tells the magic get/set methods whether to throw when a properety is inaccessible
17+
* Tells the magic get/set methods whether to throw when a property is inaccessible
1818
*
1919
* @see \chillerlan\Settings\SettingsContainerAbstract::throwOnInvalidProperty()
2020
*/
2121
#[Attribute(Attribute::TARGET_CLASS)]
22-
final class ThrowOnInvalidProperty{
22+
final readonly class ThrowOnInvalidProperty{
2323

2424
public function __construct(
25-
public readonly bool $throwOnInvalid,
25+
public bool $throwOnInvalid,
2626
){}
2727

2828
}

src/SettingsContainerAbstract.php

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace chillerlan\Settings;
1313

1414
use chillerlan\Settings\Attributes\ThrowOnInvalidProperty;
15-
use InvalidArgumentException, JsonException, ReflectionException, ReflectionObject,
15+
use InvalidArgumentException, JsonException, PropertyHookType, ReflectionException, ReflectionObject,
1616
ReflectionProperty, ReflectionAttribute, RuntimeException;
1717
use function is_object, json_decode, json_encode, json_last_error_msg,
1818
method_exists, property_exists, serialize, sprintf, unserialize;
19-
use const JSON_THROW_ON_ERROR, PHP_VERSION_ID;
19+
use const JSON_THROW_ON_ERROR;
2020

2121
abstract class SettingsContainerAbstract implements SettingsContainerInterface{
2222

23-
protected const SET_PREFIX = 'set_';
24-
protected const GET_PREFIX = 'get_';
23+
protected const string SET_PREFIX = 'set_';
24+
protected const string GET_PREFIX = 'get_';
2525

2626
/**
2727
* SettingsContainerAbstract constructor.
@@ -42,7 +42,7 @@ public function __construct(iterable|null $properties = null){
4242
* (remember pre-php5 classname constructors? yeah, basically this.)
4343
*/
4444
protected function construct():void{
45-
$traits = (new ReflectionObject($this))->getTraits();
45+
$traits = new ReflectionObject($this)->getTraits();
4646

4747
foreach($traits as $trait){
4848
$method = $trait->getShortName();
@@ -109,44 +109,34 @@ public function __toString():string{
109109
}
110110

111111
/**
112-
* @internal Checks if a property is private
112+
* Checks if a property is private
113113
*/
114114
final protected function isPrivate(string $property):bool{
115-
return (new ReflectionProperty($this, $property))->isPrivate();
115+
return new ReflectionProperty($this, $property)->isPrivate();
116116
}
117117

118118
/**
119-
* @internal Checks if a property has a "set" hook
119+
* Checks if a property has a "set" hook
120120
*/
121121
final protected function hasSetHook(string $property):bool{
122-
123-
if(PHP_VERSION_ID < 80400){
124-
return false;
125-
}
126-
/** @phan-suppress-next-line PhanUndeclaredMethod, PhanUndeclaredClassConstant */
127-
return (new ReflectionProperty($this, $property))->hasHook(\PropertyHookType::Set);
122+
return new ReflectionProperty($this, $property)->hasHook(PropertyHookType::Set);
128123
}
129124

130125
/**
131-
* @internal Checks if a property has a "get" hook
126+
* Checks if a property has a "get" hook
132127
*/
133128
final protected function hasGetHook(string $property):bool{
134-
135-
if(PHP_VERSION_ID < 80400){
136-
return false;
137-
}
138-
/** @phan-suppress-next-line PhanUndeclaredMethod, PhanUndeclaredClassConstant */
139-
return (new ReflectionProperty($this, $property))->hasHook(\PropertyHookType::Get);
129+
return new ReflectionProperty($this, $property)->hasHook(PropertyHookType::Get);
140130
}
141131

142132
/**
143-
* @internal Checks for the attribute "ThrowOnInvalidProperty", used in the magic get/set
133+
* Checks for the attribute "ThrowOnInvalidProperty", used in the magic get/set
144134
*
145135
* @see \chillerlan\Settings\Attributes\ThrowOnInvalidProperty
146136
*/
147137
final protected function throwOnInvalidProperty():bool{
148138

149-
$attributes = (new ReflectionObject($this))
139+
$attributes = new ReflectionObject($this)
150140
->getAttributes(ThrowOnInvalidProperty::class, ReflectionAttribute::IS_INSTANCEOF)
151141
;
152142

@@ -161,7 +151,7 @@ final protected function throwOnInvalidProperty():bool{
161151

162152
public function toArray():array{
163153

164-
$properties = (new ReflectionObject($this))
154+
$properties = new ReflectionObject($this)
165155
->getProperties(~(ReflectionProperty::IS_STATIC | ReflectionProperty::IS_READONLY | ReflectionProperty::IS_PRIVATE))
166156
;
167157

@@ -240,10 +230,8 @@ public function unserialize(string $data):void{
240230
$data = [];
241231

242232
foreach($properties as $reflectionProperty){
243-
$data[$reflectionProperty->name] = (PHP_VERSION_ID < 80400)
244-
? $reflectionProperty->getValue($obj)
245-
/** @phan-suppress-next-line PhanUndeclaredMethod */
246-
: $reflectionProperty->getRawValue($obj);
233+
// bypass existing property hooks
234+
$data[$reflectionProperty->name] = $reflectionProperty->getRawValue($obj);
247235
}
248236

249237
$this->__unserialize($data);
@@ -257,18 +245,15 @@ public function unserialize(string $data):void{
257245
*/
258246
public function __serialize():array{
259247

260-
$properties = (new ReflectionObject($this))
248+
$properties = new ReflectionObject($this)
261249
->getProperties(~(ReflectionProperty::IS_STATIC | ReflectionProperty::IS_READONLY))
262250
;
263251

264252
$data = [];
265253

266254
foreach($properties as $reflectionProperty){
267-
// bypass existing property hooks for PHP >= 8.4
268-
$data[$reflectionProperty->name] = (PHP_VERSION_ID < 80400)
269-
? $reflectionProperty->getValue($this)
270-
/** @phan-suppress-next-line PhanUndeclaredMethod */
271-
: $reflectionProperty->getRawValue($this);
255+
// bypass existing property hooks
256+
$data[$reflectionProperty->name] = $reflectionProperty->getRawValue($this);
272257
}
273258

274259
return $data;
@@ -291,11 +276,8 @@ public function __unserialize(array $data):void{
291276
continue; // @codeCoverageIgnore
292277
}
293278

294-
(PHP_VERSION_ID < 80400)
295-
? $reflectionProperty->setValue($this, $value)
296-
/** @phan-suppress-next-line PhanUndeclaredMethod */
297-
: $reflectionProperty->setRawValue($this, $value);
298-
279+
// bypass existing property hooks
280+
$reflectionProperty->setRawValue($this, $value);
299281
}
300282
// @codeCoverageIgnoreStart
301283
catch(ReflectionException){

tests/PropertyHooksTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
/**
2020
* Tests to ensure that properties with hooks (PHP 8.4+) produce the same results as the custom get/set methods
2121
*/
22-
#[RequiresPhp('>= 8.4')]
2322
final class PropertyHooksTest extends TestCase{
2423

2524
#[Test]

0 commit comments

Comments
 (0)