Skip to content

Commit 127b939

Browse files
authored
Symfony 8 support (#12)
* Update workflows to PHP 8.2+ and Symfony 8 * Fix to Symfony Cache/Redis incompability * Rector updates for PHP7.4 * Rector PHP 8.0 updates * Rector PHP8.1 * Trying to fix issue with Redis 6.1 / Symfony 7.4 - See symfony/symfony#63087 * Coding standards * feat: Symfony 8 support
1 parent 30ff134 commit 127b939

58 files changed

Lines changed: 178 additions & 267 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/php.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
php: ['8.1', '8.2', '8.3']
18-
symfony: ['6.4', '7.1']
17+
php: [ '8.2', '8.3', '8.4', '8.5' ]
18+
symfony: [ '7.4', '8.0', '8.1' ]
1919
exclude:
20-
- php: '8.1'
21-
symfony: '7.1'
20+
- php: '8.2'
21+
symfony: '8.0'
22+
- php: '8.2'
23+
symfony: '8.1'
24+
- php: '8.3'
25+
symfony: '8.0'
26+
- php: '8.3'
27+
symfony: '8.1'
2228

2329
runs-on: ubuntu-latest
2430

@@ -27,15 +33,17 @@ jobs:
2733
steps:
2834
# https://github.com/marketplace/actions/checkout
2935
- name: Checkout
30-
uses: actions/checkout@v4
36+
uses: actions/checkout@v6
3137

3238
# https://github.com/marketplace/actions/setup-php-action
3339
- name: Setup PHP
3440
uses: shivammathur/setup-php@v2
3541
with:
3642
php-version: ${{ matrix.php }}
37-
extensions: mbstring, intl
43+
extensions: mbstring, intl, :redis, redis-6.3.0
3844
ini-values: post_max_size=256M, max_execution_time=180
45+
env:
46+
fail-fast: true
3947

4048
- name: Check PHP version
4149
run: php -v
@@ -48,10 +56,10 @@ jobs:
4856

4957
- name: Install Symfony ${{ matrix.symfony }} packages
5058
run: |
51-
composer update symfony/http-client:${{ matrix.symfony }}
52-
composer update symfony/cache:${{ matrix.symfony }}
53-
composer update symfony/stopwatch:${{ matrix.symfony }}
54-
composer update symfony/property-access:${{ matrix.symfony }}
59+
composer update symfony/http-client:^${{ matrix.symfony }}
60+
composer update symfony/cache:^${{ matrix.symfony }}
61+
composer update symfony/stopwatch:^${{ matrix.symfony }}
62+
composer update symfony/property-access:^${{ matrix.symfony }}
5563
5664
- name: Lint PHP files
5765
run: |

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ Please note this software is in development, usage may change before the 1.0 rel
2222

2323
## Requirements
2424

25-
* PHP 8.1+
25+
* PHP 8.2+
26+
* Supports Symfony 7.4+
2627
* [Composer](https://getcomposer.org/)
2728

2829
## Installation
2930

3031
Install via Composer:
3132

3233
```
33-
composer require strata/data:^0.9
34+
composer require strata/data
3435
```
3536

3637
## Thanks to

composer.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^8.1",
13+
"php": "^8.2",
1414
"erusev/parsedown-extra": "^0.8",
1515
"laminas/laminas-feed": "^2.22",
1616
"league/commonmark": "^2.4",
1717
"spatie/yaml-front-matter": "^2.0",
18-
"symfony/http-client": "^6.4|^7.1",
19-
"symfony/cache": "^6.4|^7.1",
20-
"symfony/stopwatch": "^6.4|^7.1",
21-
"symfony/property-access": "^6.4|^7.1",
22-
"symfony/monolog-bundle": "^3.7"
18+
"symfony/event-dispatcher": "^7.4|^8.0",
19+
"symfony/http-client": "^7.4|^8.0",
20+
"symfony/http-foundation": "^7.4|^8.0",
21+
"symfony/cache": "^7.4|^8.0",
22+
"symfony/stopwatch": "^7.4|^8.0",
23+
"symfony/property-access": "^7.4|^8.0"
2324
},
2425
"autoload": {
2526
"psr-4": {
@@ -30,10 +31,12 @@
3031
]
3132
},
3233
"require-dev": {
33-
"phpunit/phpunit": "^10.5",
34-
"squizlabs/php_codesniffer": "^3.10",
35-
"phpstan/phpstan": "^1.11",
36-
"roave/security-advisories": "dev-latest"
34+
"phpunit/phpunit": "^11.5",
35+
"squizlabs/php_codesniffer": "^4.0",
36+
"phpstan/phpstan": "^2.0",
37+
"phpstan/phpstan-deprecation-rules": "^2.0",
38+
"roave/security-advisories": "dev-latest",
39+
"rector/rector": "^2.4"
3740
},
3841
"scripts": {
3942
"phpcs": [
@@ -59,7 +62,7 @@
5962
"extra": {
6063
"symfony": {
6164
"allow-contrib": false,
62-
"require": "7.2.*"
65+
"require": "8.0.*"
6366
}
6467
}
6568
}

rector.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
declare(strict_types=1);
44

5-
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
65
use Rector\Config\RectorConfig;
7-
use Rector\Set\ValueObject\LevelSetList;
8-
9-
return static function (RectorConfig $rectorConfig): void {
10-
$rectorConfig->paths([
11-
__DIR__ . '/src',
12-
//__DIR__ . '/tests',
13-
]);
14-
15-
// register a single rule
16-
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
17-
18-
// define sets of rules
19-
$rectorConfig->sets([
20-
LevelSetList::UP_TO_PHP_81
6+
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
7+
8+
return RectorConfig::configure()
9+
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
10+
->withPhpSets(php82: true)
11+
->withPreparedSets(symfonyCodeQuality: true)
12+
->withComposerBased(symfony: true)
13+
->withSkip([
14+
ReadOnlyPropertyRector::class
2115
]);
22-
};

src/Cache/DataCache.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
class DataCache implements CacheItemPoolInterface, TagAwareAdapterInterface, PruneableInterface
2727
{
28-
private CacheItemPoolInterface $cache;
2928
protected array $tags = [];
3029
protected int $lifetime;
3130

@@ -35,12 +34,11 @@ class DataCache implements CacheItemPoolInterface, TagAwareAdapterInterface, Pru
3534
* @param CacheItemPoolInterface $cache
3635
* @param ?int $defaultLifetime Default cache lifetime for data cache, defaults to 1 hour if not set
3736
*/
38-
public function __construct(CacheItemPoolInterface $cache, ?int $defaultLifetime = null)
37+
public function __construct(private CacheItemPoolInterface $cache, ?int $defaultLifetime = null)
3938
{
4039
if ($defaultLifetime === null) {
4140
$defaultLifetime = CacheLifetime::HOUR;
4241
}
43-
$this->cache = $cache;
4442
$this->setLifetime($defaultLifetime);
4543
}
4644

@@ -92,7 +90,7 @@ public function isPruneable(): bool
9290
public function setTags(array $tags)
9391
{
9492
if (!$this->isTaggable()) {
95-
throw new CacheException(sprintf('Tags are not supported by your cache adapter %s', get_class($this->cache)));
93+
throw new CacheException(sprintf('Tags are not supported by your cache adapter %s', $this->cache::class));
9694
}
9795
$this->tags = $tags;
9896
return $this;

src/Cache/DataHistory.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818
class DataHistory
1919
{
2020
const CACHE_KEY_PREFIX = 'history_';
21-
22-
private CacheItemPoolInterface $cache;
23-
private int $cacheLifetime;
2421
private int $maxHistoryDays = 30;
2522
private array $historyItems = [];
2623

2724
/**
2825
* Constructor
2926
*
3027
* @param CacheItemPoolInterface $cache PSR-6 cache
31-
* @param int $lifetime Default cache lifetime for data cache, defaults to 2 months if not set
28+
* @param int $cacheLifetime Default cache lifetime for data cache, defaults to 2 months if not set
3229
*/
33-
public function __construct(CacheItemPoolInterface $cache, int $lifetime = 2 * CacheLifetime::MONTH)
30+
public function __construct(private CacheItemPoolInterface $cache, private int $cacheLifetime = 2 * CacheLifetime::MONTH)
3431
{
35-
$this->cache = $cache;
36-
$this->cacheLifetime = $lifetime;
3732
}
3833

3934
/**
@@ -120,16 +115,12 @@ public function getLastItem($key, string $field = null)
120115
return $item;
121116
}
122117

123-
switch ($field) {
124-
case 'updated':
125-
return $item['updated'];
126-
case 'content_hash':
127-
return $item['content_hash'];
128-
case 'metadata':
129-
return $item['metadata'];
130-
default:
131-
throw new CacheException(sprintf('Cannot return history field "%s" since not set', $field));
132-
}
118+
return match ($field) {
119+
'updated' => $item['updated'],
120+
'content_hash' => $item['content_hash'],
121+
'metadata' => $item['metadata'],
122+
default => throw new CacheException(sprintf('Cannot return history field "%s" since not set', $field)),
123+
};
133124
}
134125

135126
/**

src/Collection.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,29 @@ public function getPagination(): Pagination
5252
/**
5353
* Whether a offset exists
5454
* @link https://php.net/manual/en/arrayaccess.offsetexists.php
55-
* @param mixed $offset
5655
* @return bool true on success or false on failure.
5756
*/
58-
public function offsetExists($offset): bool
57+
public function offsetExists(mixed $offset): bool
5958
{
6059
return isset($this->collection[$offset]);
6160
}
6261

6362
/**
6463
* Offset to retrieve
6564
* @link https://php.net/manual/en/arrayaccess.offsetget.php
66-
* @param mixed $offset
6765
* @return mixed Can return all value types.
6866
*/
69-
public function offsetGet($offset): mixed
67+
public function offsetGet(mixed $offset): mixed
7068
{
71-
return isset($this->collection[$offset]) ? $this->collection[$offset] : null;
69+
return $this->collection[$offset] ?? null;
7270
}
7371

7472
/**
7573
* Offset to set
7674
* @link https://php.net/manual/en/arrayaccess.offsetset.php
77-
* @param mixed $offset
78-
* @param mixed $value
7975
* @return void
8076
*/
81-
public function offsetSet($offset, $value): void
77+
public function offsetSet(mixed $offset, mixed $value): void
8278
{
8379
if (is_null($offset)) {
8480
$this->collection[] = $value;
@@ -90,10 +86,9 @@ public function offsetSet($offset, $value): void
9086
/**
9187
* Offset to unset
9288
* @link https://php.net/manual/en/arrayaccess.offsetunset.php
93-
* @param mixed $offset
9489
* @return void
9590
*/
96-
public function offsetUnset($offset): void
91+
public function offsetUnset(mixed $offset): void
9792
{
9893
unset($this->collection[$offset]);
9994
}

src/DataProviderCommonTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function setBaseUri(string $baseUri)
4444
public function getBaseUri(): string
4545
{
4646
if (empty($this->baseUri)) {
47-
throw new BaseUriException(sprintf('Base URI not set, please set via %s::setBaseUri()', get_class($this)));
47+
throw new BaseUriException(sprintf('Base URI not set, please set via %s::setBaseUri()', $this::class));
4848
}
4949

5050
return $this->baseUri;

src/DataProviderInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ public function getDefaultDecoder(): ?DecoderInterface;
7373
/**
7474
* Decode response
7575
*
76-
* @param mixed $response
7776
* @param DecoderInterface|null $decoder Optional decoder, if not set uses getDefaultDecoder()
7877
* @return mixed
7978
*/
80-
public function decode($response, ?DecoderInterface $decoder = null);
79+
public function decode(mixed $response, ?DecoderInterface $decoder = null);
8180

8281
/**
8382
* Is the cache enabled?

src/Decode/StringNormalizer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ class StringNormalizer
1212
/**
1313
* Take a string or object, and return a string representing the content
1414
*
15-
* @param mixed $data
1615
* @return string
1716
* @throws DecoderException
1817
*/
19-
public static function getString($data): string
18+
public static function getString(mixed $data): string
2019
{
2120
if (is_string($data)) {
2221
return $data;
@@ -30,7 +29,7 @@ public static function getString($data): string
3029
if (method_exists($data, '__toString')) {
3130
return $data->__toString();
3231
}
33-
throw new DecoderException(sprintf('Cannot convert object of type "%s" into a string', get_class($data)));
32+
throw new DecoderException(sprintf('Cannot convert object of type "%s" into a string', $data::class));
3433
}
3534
throw new DecoderException(sprintf('Cannot convert %s into a string', gettype($data)));
3635
}

0 commit comments

Comments
 (0)