Skip to content

Commit 2b9baab

Browse files
committed
:octocat: PHP 8.1+
1 parent 1beb7df commit 2b9baab

File tree

11 files changed

+32
-47
lines changed

11 files changed

+32
-47
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ jobs:
3030
- name: "Install PHP"
3131
uses: shivammathur/setup-php@v2
3232
with:
33-
php-version: "7.4"
33+
php-version: "8.1"
3434
tools: pecl
3535
coverage: none
3636
extensions: ast, json
3737

3838
- name: "Update dependencies with composer"
39-
run: composer update --no-interaction --no-ansi --no-progress --no-suggest
39+
uses: ramsey/composer-install@v2
4040

4141
- name: "Run phan"
4242
run: php vendor/bin/phan
4343

44+
4445
build-docs:
4546
name: "Build and publish Docs"
4647

@@ -68,6 +69,7 @@ jobs:
6869
folder: docs
6970
clean: true
7071

72+
7173
tests:
7274
name: "Unit Tests"
7375

@@ -80,9 +82,9 @@ jobs:
8082
- ubuntu-latest
8183
- windows-latest
8284
php-version:
83-
- "7.4"
8485
- "8.0"
8586
- "8.1"
87+
- "8.2"
8688

8789
steps:
8890
- name: "Checkout"
@@ -96,7 +98,7 @@ jobs:
9698
extensions: json
9799

98100
- name: "Install dependencies with composer"
99-
run: composer update --no-ansi --no-interaction --no-progress --no-suggest
101+
uses: ramsey/composer-install@v2
100102

101103
- name: "Run tests with phpunit"
102104
run: php vendor/phpunit/phpunit/phpunit --configuration=phpunit.xml

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build:
55
override:
66
- php-scrutinizer-run
77
environment:
8-
php: 8.0.0
8+
php: 8.1.0
99

1010
filter:
1111
excluded_paths:

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# chillerlan/php-settings-container
22

3-
A container class for immutable settings objects. Not a DI container. PHP 7.4+
3+
A container class for immutable settings objects. Not a DI container. PHP 8.1+
44
- [`SettingsContainerInterface`](https://github.com/chillerlan/php-settings-container/blob/main/src/SettingsContainerInterface.php) provides immutable properties with magic getter & setter and some fancy - decouple configuration logic from your application!
55

66
[![PHP Version Support][php-badge]][php]
@@ -35,7 +35,7 @@ A container class for immutable settings objects. Not a DI container. PHP 7.4+
3535
```json
3636
{
3737
"require": {
38-
"php": "^7.4 || ^8.0",
38+
"php": "^8.1",
3939
"chillerlan/php-settings-container": "dev-main"
4040
}
4141
}
@@ -50,13 +50,6 @@ It takes an `iterable` as the only constructor argument and calls a method with
5050

5151
### Simple usage
5252
```php
53-
class MyContainer extends SettingsContainerAbstract{
54-
protected $foo;
55-
protected $bar;
56-
}
57-
```
58-
Typed properties in PHP 7.4+:
59-
```php
6053
class MyContainer extends SettingsContainerAbstract{
6154
protected string $foo;
6255
protected string $bar;
@@ -91,8 +84,8 @@ var_dump($container->nope); // -> null
9184
### Advanced usage
9285
```php
9386
trait SomeOptions{
94-
protected $foo;
95-
protected $what;
87+
protected string $foo;
88+
protected string $what;
9689

9790
// this method will be called in SettingsContainerAbstract::construct()
9891
// after the properties have been set
@@ -108,7 +101,7 @@ trait SomeOptions{
108101
}
109102

110103
trait MoreOptions{
111-
protected $bar = 'whatever'; // provide default values
104+
protected string $bar = 'whatever'; // provide default values
112105
}
113106
```
114107

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
"source": "https://github.com/chillerlan/php-settings-container"
2121
},
2222
"require": {
23-
"php": "^7.4 || ^8.0",
23+
"php": "^8.1",
2424
"ext-json": "*"
2525
},
2626
"require-dev": {
27-
"phan/phan": "^5.3",
27+
"phan/phan": "^5.4",
2828
"phpunit/phpunit": "^9.5"
2929
},
3030
"autoload": {

examples/advanced.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait SomeOptions{
1717
protected string $foo = '';
1818

1919
// this method will be called in SettingsContainerAbstract::__construct() after the properties have been set
20-
protected function SomeOptions(){
20+
protected function SomeOptions():void{
2121
// just some constructor stuff...
2222
$this->foo = strtoupper($this->foo);
2323
}

examples/simple.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
require_once __DIR__.'/../vendor/autoload.php';
1414

1515
class MyContainer extends SettingsContainerAbstract{
16-
protected $foo;
17-
protected $bar;
16+
protected string $foo;
17+
protected string $bar;
1818
}
1919

2020
/** @var \chillerlan\Settings\SettingsContainerInterface $container */

src/SettingsContainerAbstract.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function construct():void{
4949
/**
5050
* @inheritdoc
5151
*/
52-
public function __get(string $property){
52+
public function __get(string $property):mixed{
5353

5454
if(!property_exists($this, $property) || $this->isPrivate($property)){
5555
return null;
@@ -67,7 +67,7 @@ public function __get(string $property){
6767
/**
6868
* @inheritdoc
6969
*/
70-
public function __set(string $property, $value):void{
70+
public function __set(string $property, mixed $value):void{
7171

7272
if(!property_exists($this, $property) || $this->isPrivate($property)){
7373
return;
@@ -153,9 +153,9 @@ public function fromJSON(string $json):SettingsContainerInterface{
153153

154154
/**
155155
* @inheritdoc
156+
* @noinspection PhpMixedReturnTypeCanBeReducedInspection
156157
*/
157-
#[\ReturnTypeWillChange]
158-
public function jsonSerialize():array{
158+
public function jsonSerialize():mixed{
159159
return $this->toArray();
160160
}
161161

src/SettingsContainerInterface.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ interface SettingsContainerInterface extends JsonSerializable{
2222
*
2323
* @return mixed|null
2424
*/
25-
public function __get(string $property);
25+
public function __get(string $property):mixed;
2626

2727
/**
2828
* Set $property to $value while avoiding private and non-existing properties
29-
*
30-
* @param string $property
31-
* @param mixed $value
3229
*/
33-
public function __set(string $property, $value):void;
30+
public function __set(string $property, mixed $value):void;
3431

3532
/**
3633
* Checks if $property is set (aka. not null), excluding private properties

tests/ContainerTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class ContainerTest extends TestCase{
1818

19-
public function testConstruct(){
19+
public function testConstruct():void{
2020
$container = new TestContainer([
2121
'test1' => 'test1',
2222
'test2' => true,
@@ -32,7 +32,7 @@ public function testConstruct(){
3232
$this::assertSame('success', $container->testConstruct);
3333
}
3434

35-
public function testGet(){
35+
public function testGet():void{
3636
$container = new TestContainer;
3737

3838
$this::assertSame('foo', $container->test1);
@@ -57,7 +57,7 @@ public function testGet(){
5757
$this::assertSame('null', $container->test6);
5858
}
5959

60-
public function testSet(){
60+
public function testSet():void{
6161
$container = new TestContainer;
6262
$container->test1 = 'bar';
6363
$container->test2 = false;
@@ -76,7 +76,7 @@ public function testSet(){
7676
$this::assertSame('bar_test5', $container->test5);
7777
}
7878

79-
public function testToArray(){
79+
public function testToArray():void{
8080
$container = new TestContainer([
8181
'test1' => 'no',
8282
'test2' => true,
@@ -93,7 +93,7 @@ public function testToArray(){
9393
], $container->toArray());
9494
}
9595

96-
public function testToJSON(){
96+
public function testToJSON():void{
9797
$container = (new TestContainer)->fromJSON('{"test1":"no","test2":true,"testConstruct":"success"}');
9898

9999
$expected = '{"test1":"no","test2":true,"testConstruct":"success","test4":null,"test5":null,"test6":null}';
@@ -102,12 +102,13 @@ public function testToJSON(){
102102
$this::assertSame($expected, (string)$container);
103103
}
104104

105-
public function testFromJsonException(){
105+
public function testFromJsonException():void{
106106
$this->expectException(JsonException::class);
107107
(new TestContainer)->fromJSON('-');
108108

109109
}
110-
public function testFromJsonTypeError(){
110+
111+
public function testFromJsonTypeError():void{
111112
$this->expectException(TypeError::class);
112113
(new TestContainer)->fromJSON('2');
113114
}

tests/TestContainer.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212

1313
use chillerlan\Settings\SettingsContainerAbstract;
1414

15-
/**
16-
* @property $test1
17-
* @property $test2
18-
* @property $test3
19-
* @property $test4
20-
* @property $test5
21-
* @property $test6
22-
*/
2315
class TestContainer extends SettingsContainerAbstract{
2416
use TestOptionsTrait;
2517

0 commit comments

Comments
 (0)