Skip to content

Commit 35ba29c

Browse files
authored
Bump min PHP version to 8.0 and update deps (#646)
1 parent eabc889 commit 35ba29c

24 files changed

+174
-154
lines changed

.github/workflows/code_checks.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions/checkout@v2
3131
- uses: shivammathur/setup-php@v1
3232
with:
33-
php-version: 7.3
33+
php-version: 8.0
3434
extensions: pdo_sqlite, pdo_mysql, pdo_pgsql
3535
coverage: none
3636

.github/workflows/linter.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- uses: shivammathur/setup-php@v1
1717
with:
18-
php-version: 7.3
18+
php-version: 8.0
1919
extensions: pdo_sqlite, pdo_mysql, pdo_pgsql
2020
coverage: none
2121

.github/workflows/tests.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ jobs:
88
strategy:
99
matrix:
1010
php:
11-
- 7.3
12-
- 7.4
1311
- 8.0
1412

1513
name: Test ${{ matrix.php }}

composer.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{ "name": "Knplabs", "homepage": "http://knplabs.com" }
1212
],
1313
"require": {
14-
"php": ">=7.3",
14+
"php": ">=8.0",
1515
"doctrine/common": "^3.0",
1616
"doctrine/persistence": "^2.0",
1717
"doctrine/dbal": "^2.9",
@@ -35,17 +35,17 @@
3535
"doctrine/annotations": "^1.12",
3636
"doctrine/doctrine-bundle": "^2.2",
3737
"php-parallel-lint/php-parallel-lint": "^1.3",
38-
"phpstan/phpstan": "^0.12.83",
38+
"phpstan/phpstan": "^0.12.84",
3939
"phpunit/phpunit": "^9.5",
40-
"rector/rector-prefixed": "^0.10.4",
41-
"symplify/easy-coding-standard": "^9.2.18",
42-
"symplify/phpstan-extensions": "^9.2.18",
43-
"phpstan/phpstan-doctrine": "^0.12.33",
44-
"phpstan/phpstan-phpunit": "^0.12.18",
45-
"symplify/package-builder": "^9.2.18",
46-
"symplify/phpstan-rules": "^9.2.18",
47-
"symplify/config-transformer": "^9.2",
48-
"symplify/amnesia": "^9.2",
40+
"rector/rector": "^0.11.45",
41+
"symplify/easy-coding-standard": "^9.4",
42+
"symplify/phpstan-extensions": "^9.4",
43+
"phpstan/phpstan-doctrine": "^0.12.42",
44+
"phpstan/phpstan-phpunit": "^0.12",
45+
"symplify/package-builder": "^9.4",
46+
"symplify/phpstan-rules": "^9.4",
47+
"symplify/config-transformer": "^9.4",
48+
"symplify/amnesia": "^9.4",
4949
"phpstan/extension-installer": "^1.1"
5050
},
5151
"autoload": {

ecs.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use PhpCsFixer\Fixer\ClassNotation\FinalClassFixer;
65
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
76
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
87
use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer;
@@ -13,6 +12,11 @@
1312
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
1413

1514
return static function (ContainerConfigurator $containerConfigurator): void {
15+
$containerConfigurator->import(SetList::PSR_12);
16+
$containerConfigurator->import(SetList::SYMPLIFY);
17+
$containerConfigurator->import(SetList::COMMON);
18+
$containerConfigurator->import(SetList::CLEAN_CODE);
19+
1620
$parameters = $containerConfigurator->parameters();
1721

1822
$parameters->set(Option::PATHS, [
@@ -24,8 +28,6 @@
2428
__DIR__ . '/rector.php',
2529
]);
2630

27-
$parameters->set(Option::SETS, [SetList::PSR_12, SetList::SYMPLIFY, SetList::COMMON, SetList::CLEAN_CODE]);
28-
2931
$parameters->set(Option::SKIP, [
3032
UnaryOperatorSpacesFixer::class,
3133
PhpUnitStrictFixer::class => [__DIR__ . '/tests/ORM/Timestampable/TimestampableTest.php'],

phpstan.neon

+3
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@ parameters:
101101
-
102102
message: '#Use dependency injection instead of dependency juggling#'
103103
path: tests/DatabaseLoader.php
104+
105+
# known retype
106+
- '#Cannot cast array\|bool\|float\|int\|string\|null to string#'

rector.php

+10-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Core\Configuration\Option;
6-
use Rector\DeadCode\Rector\Class_\RemoveUnusedDoctrineEntityMethodAndPropertyRector;
6+
use Rector\Nette\Set\NetteSetList;
77
use Rector\Set\ValueObject\SetList;
88
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
99

@@ -12,20 +12,13 @@
1212

1313
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/utils']);
1414

15-
$parameters->set(Option::SETS, [
16-
SetList::DEAD_CODE,
17-
SetList::CODE_QUALITY,
18-
SetList::CODING_STYLE,
19-
SetList::NETTE_UTILS_CODE_QUALITY,
20-
SetList::NAMING,
21-
SetList::PHP_70,
22-
SetList::PHP_71,
23-
SetList::PHP_72,
24-
SetList::PHP_73,
25-
]);
26-
27-
$parameters->set(Option::SKIP, [
28-
RemoveUnusedDoctrineEntityMethodAndPropertyRector::class,
29-
__DIR__ . '/src/Model/Translatable/TranslatableMethodsTrait.php',
30-
]);
15+
$containerConfigurator->import(SetList::DEAD_CODE);
16+
$containerConfigurator->import(SetList::CODE_QUALITY);
17+
$containerConfigurator->import(SetList::CODING_STYLE);
18+
$containerConfigurator->import(NetteSetList::NETTE_CODE_QUALITY);
19+
$containerConfigurator->import(SetList::NAMING);
20+
$containerConfigurator->import(SetList::PHP_70);
21+
$containerConfigurator->import(SetList::PHP_71);
22+
$containerConfigurator->import(SetList::PHP_72);
23+
$containerConfigurator->import(SetList::PHP_73);
3124
};

src/Bundle/DoctrineBehaviorsBundle.php

-14
This file was deleted.

src/Model/Blameable/BlameableTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait BlameableTrait
88
{
99
use BlameablePropertiesTrait;
10+
1011
use BlameableMethodsTrait;
1112
}

src/Model/Sluggable/SluggableTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait SluggableTrait
88
{
99
use SluggablePropertiesTrait;
10+
1011
use SluggableMethodsTrait;
1112
}

src/Model/SoftDeletable/SoftDeletableTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait SoftDeletableTrait
88
{
99
use SoftDeletablePropertiesTrait;
10+
1011
use SoftDeletableMethodsTrait;
1112
}

src/Model/Timestampable/TimestampableTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait TimestampableTrait
88
{
99
use TimestampablePropertiesTrait;
10+
1011
use TimestampableMethodsTrait;
1112
}

src/Model/Translatable/TranslatableMethodsTrait.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ public function getCurrentLocale(): string
107107
return $this->currentLocale ?: $this->getDefaultLocale();
108108
}
109109

110-
/**
111-
* @param mixed $locale the default locale
112-
*/
113-
public function setDefaultLocale($locale): void
110+
public function setDefaultLocale(string $locale): void
114111
{
115112
$this->defaultLocale = $locale;
116113
}
@@ -223,7 +220,8 @@ private function ensureIsIterableOrCollection($translations): void
223220
return;
224221
}
225222

226-
throw new TranslatableException(sprintf('$translations parameter must be iterable or %s', Collection::class)
223+
throw new TranslatableException(
224+
sprintf('$translations parameter must be iterable or %s', Collection::class)
227225
);
228226
}
229227

src/Model/Translatable/TranslatableTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait TranslatableTrait
88
{
99
use TranslatablePropertiesTrait;
10+
1011
use TranslatableMethodsTrait;
1112
}

src/Model/Translatable/TranslationTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait TranslationTrait
88
{
99
use TranslationPropertiesTrait;
10+
1011
use TranslationMethodsTrait;
1112
}

src/Model/Tree/TreeNodeMethodsTrait.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Common\Collections\ArrayCollection;
99
use Doctrine\Common\Collections\Collection;
1010
use Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface;
11+
use Knp\DoctrineBehaviors\Exception\ShouldNotHappenException;
1112
use Knp\DoctrineBehaviors\Exception\TreeException;
1213
use Nette\Utils\Json;
1314

@@ -54,7 +55,7 @@ public function getParentMaterializedPath(): string
5455
return static::getMaterializedPathSeparator() . implode(static::getMaterializedPathSeparator(), $path);
5556
}
5657

57-
public function setParentMaterializedPath($path): void
58+
public function setParentMaterializedPath(string $path): void
5859
{
5960
$this->parentNodePath = $path;
6061
}
@@ -273,7 +274,12 @@ public function offsetGet($offset)
273274
*/
274275
protected function getExplodedPath(): array
275276
{
276-
$path = explode(static::getMaterializedPathSeparator(), $this->getRealMaterializedPath());
277+
$separator = static::getMaterializedPathSeparator();
278+
if ($separator === '') {
279+
throw new ShouldNotHappenException();
280+
}
281+
282+
$path = explode($separator, $this->getRealMaterializedPath());
277283

278284
return array_filter($path, function ($item) {
279285
return $item !== '';

src/Model/Tree/TreeNodeTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait TreeNodeTrait
88
{
99
use TreeNodeMethodsTrait;
10+
1011
use TreeNodePropertiesTrait;
1112
}

src/Model/Uuidable/UuidableMethodsTrait.php

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Knp\DoctrineBehaviors\Model\Uuidable;
66

7+
use Knp\DoctrineBehaviors\Exception\ShouldNotHappenException;
78
use Ramsey\Uuid\Uuid;
89
use Ramsey\Uuid\UuidInterface;
910

@@ -17,6 +18,10 @@ public function setUuid(UuidInterface $uuid): void
1718
public function getUuid(): ?UuidInterface
1819
{
1920
if (is_string($this->uuid)) {
21+
if ($this->uuid === '') {
22+
throw new ShouldNotHappenException();
23+
}
24+
2025
return Uuid::fromString($this->uuid);
2126
}
2227

src/Model/Uuidable/UuidableTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
trait UuidableTrait
88
{
99
use UuidablePropertiesTrait;
10+
1011
use UuidableMethodsTrait;
1112
}

src/Provider/LocaleProvider.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
99
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
1010
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
11+
use Symfony\Component\HttpFoundation\Request;
1112
use Symfony\Component\HttpFoundation\RequestStack;
1213
use Symfony\Contracts\Translation\LocaleAwareInterface;
1314
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -42,7 +43,7 @@ public function __construct(
4243
public function provideCurrentLocale(): ?string
4344
{
4445
$currentRequest = $this->requestStack->getCurrentRequest();
45-
if ($currentRequest === null) {
46+
if (! $currentRequest instanceof Request) {
4647
return null;
4748
}
4849

@@ -67,10 +68,10 @@ public function provideFallbackLocale(): ?string
6768

6869
try {
6970
if ($this->parameterBag->has('locale')) {
70-
return $this->parameterBag->get('locale');
71+
return (string) $this->parameterBag->get('locale');
7172
}
7273

73-
return $this->parameterBag->get('kernel.default_locale');
74+
return (string) $this->parameterBag->get('kernel.default_locale');
7475
} catch (ParameterNotFoundException | InvalidArgumentException $parameterNotFoundException) {
7576
return null;
7677
}

tests/Fixtures/Entity/Sluggable/SluggableTranslatableEntityTranslation.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class SluggableTranslatableEntityTranslation implements TranslationInterface, SluggableInterface
1717
{
1818
use SluggableTrait;
19+
1920
use TranslationTrait;
2021

2122
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Knp\DoctrineBehaviors\Tests\ORM\Timestampable\Source;
6+
7+
final class SomeClassForMetadata
8+
{
9+
public string $name;
10+
}

tests/ORM/Timestampable/TimestampableMakeEntityTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\ORM\Events;
99
use Doctrine\ORM\Mapping\ClassMetadata;
1010
use Knp\DoctrineBehaviors\Tests\AbstractBehaviorTestCase;
11+
use Knp\DoctrineBehaviors\Tests\ORM\Timestampable\Source\SomeClassForMetadata;
1112

1213
/**
1314
* When console make:entity creates a new class, the event arguments are not fully populated
@@ -19,8 +20,7 @@ final class TimestampableMakeEntityTest extends AbstractBehaviorTestCase
1920
{
2021
public function testMakeEntityEmptyEvent(): void
2122
{
22-
$className = 'App\Entity\MyClass';
23-
$classMetadata = new ClassMetadata($className);
23+
$classMetadata = new ClassMetadata(SomeClassForMetadata::class);
2424
$loadClassMetadataEventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->entityManager);
2525

2626
$doctrineEventManager = $this->entityManager->getEventManager();

0 commit comments

Comments
 (0)