Skip to content

Commit 28f892c

Browse files
committed
Set minimum PHP version to PHP8
- Upgrade squirrelphp dependencies which have already been upgraded to PHP8 and slightly adapted - Use new attributes instead of previous annotations (annotations are gone) - Adjust the documentation slightly to reflect the changes
1 parent 46028ba commit 28f892c

25 files changed

+224
-222
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ env:
22
global:
33
- CC_TEST_REPORTER_ID=9ba975cd443857ed8633ab9f438690d3b6eadbe73bb57533da71fa2d228a6abd
44
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
5+
- XDEBUG_MODE=coverage
56
language: php
67
php:
7-
- '7.4'
8+
- '8.0'
89

910
before_script:
1011
- composer self-update

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Configure the directories where the bundle will look for repositories like this
2424
- '%kernel.project_dir%/src'
2525
- '%kernel.project_dir%/possibleOtherDirectory'
2626

27-
It will go through these directories recusively, finding all entities and generated repositories and creating services for the repositories. The details on how to work with the repositories can be found in the documentation for the underlying library [squirrelphp/entities](https://github.com/squirrelphp/entities).
27+
It will go through these directories recusively, finding all entities, generating repositories and creating services for the repositories. The details on how to work with the repositories can be found in the documentation for the underlying library [squirrelphp/entities](https://github.com/squirrelphp/entities).
2828

2929
Overriding table names and connection names
3030
-------------------------------------------
@@ -39,7 +39,7 @@ If you are reusing entities from other projects and only want to change the conn
3939
Application\Entity\User: 'differentdatabase.users'
4040
Application\Entity\Session: 'sessions_table'
4141

42-
This can also come in handy if you want to change connection names and table names for testing or development, while the annotation values are for the production system. Just use the fully qualified entity class name as the key. If you specify an empty string as connection name the default connection is used (if a default connection was defined through `QueriesBundle`).
42+
This can also come in handy if you want to change connection names and table names for testing or development, while the attribute values are for the production system. Just use the fully qualified entity class name as the key. If you specify an empty string as connection name the default connection is used (if a default connection was defined through `QueriesBundle`).
4343

4444
Workflow with entities and repositories
4545
---------------------------------------
@@ -48,7 +48,7 @@ At this point you should have already configured [squirrelphp/queries-bundle](ht
4848

4949
### While developing
5050

51-
1. Create annotated entities as explained in [squirrelphp/entities](https://github.com/squirrelphp/entities)
51+
1. Create entities with attributes as explained in [squirrelphp/entities](https://github.com/squirrelphp/entities)
5252
2. Run `vendor/bin/squirrel_repositories_generate --source-dir=src` to generate the repositories for your entities - those will be gitignored (add or change the --source-dir entries depending on where your entities are)
5353
3. Add the directories of your entities to the `squirrel_entities` configuration so repositories are found and initialized automatically when the Symfony service container is compiled.
5454
4. Use the generated repository classes as type hints in your code and let Symfony autowire these services.

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
}
2424
],
2525
"require": {
26-
"php": ">=7.4",
26+
"php": ">=8.0",
2727
"symfony/dependency-injection": "^5.0",
2828
"symfony/http-kernel": "^5.0",
2929
"symfony/finder": "^5.0",
3030
"symfony/config": "^5.0",
31-
"squirrelphp/queries-bundle": "^0.12",
32-
"squirrelphp/entities": "^0.11"
31+
"squirrelphp/queries-bundle": "^0.13",
32+
"squirrelphp/entities": "^0.12"
3333
},
3434
"require-dev": {
3535
"bamarni/composer-bin-plugin": "^1.3",
@@ -52,14 +52,14 @@
5252
},
5353
"scripts": {
5454
"phpstan": "vendor/bin/phpstan analyse",
55+
"phpstan_full": "vendor/bin/phpstan clear-result-cache && vendor/bin/phpstan analyse",
5556
"phpstan_base": "vendor/bin/phpstan analyse --generate-baseline",
56-
"phpstan_clear": "vendor/bin/phpstan clear-result-cache",
57-
"psalm": "vendor/bin/psalm --show-info=false --diff",
58-
"psalm_full": "vendor/bin/psalm --show-info=false",
57+
"psalm": "vendor/bin/psalm --show-info=false",
58+
"psalm_full": "vendor/bin/psalm --clear-cache && vendor/bin/psalm --show-info=false",
5959
"psalm_base": "vendor/bin/psalm --set-baseline=psalm-baseline.xml",
6060
"phpunit": "vendor/bin/phpunit --colors=always",
6161
"phpunit_clover": "vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml",
62-
"coverage": "vendor/bin/phpunit --coverage-html tests/_reports",
62+
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html tests/_reports",
6363
"phpcs": "vendor/bin/phpcs --standard=ruleset.xml --extensions=php --cache=.phpcs-cache --colors --ignore=tests/TestEntities,tests/TestEntities2 src tests",
6464
"phpcsfix": "vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --cache=.phpcs-cache --ignore=tests/TestEntities,tests/TestEntities2 src tests",
6565
"binupdate": "@composer bin all update --ansi",

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="tests/autoload.php">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
33
<coverage>
44
<include>
55
<directory suffix=".php">src</directory>

psalm-baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="3.11.2@d470903722cfcbc1cd04744c5491d3e6d13ec3d9"/>
2+
<files psalm-version="4.7.3@38c452ae584467e939d55377aaf83b5a26f19dd1"/>

psalm.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88
>
99
<projectFiles>
1010
<directory name="src" />
11+
<directory name="tests" />
1112
<ignoreFiles>
1213
<directory name="vendor" />
14+
<directory name="tests/TestEntities" />
15+
<directory name="tests/TestEntities2" />
1316
</ignoreFiles>
1417
</projectFiles>
18+
19+
<plugins>
20+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
21+
<pluginClass class="Psalm\MockeryPlugin\Plugin"/>
22+
</plugins>
1523
</psalm>

ruleset.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable"/>
4646
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
4747
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
48-
<rule ref="SlevomatCodingStandard.Functions.TrailingCommaInCall"/>
48+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
49+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
4950
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
5051
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
5152
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>

src/DependencyInjection/SquirrelEntitiesExtension.php

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

33
namespace Squirrel\EntitiesBundle\DependencyInjection;
44

5-
use Squirrel\Entities\Annotation\EntityProcessor;
6-
use Squirrel\Entities\Generate\FindClassesWithAnnotation;
5+
use Squirrel\Entities\Attribute\EntityProcessor;
6+
use Squirrel\Entities\Generate\FindClassesWithAttribute;
77
use Squirrel\Entities\MultiRepositoryBuilderReadOnly;
88
use Squirrel\Entities\MultiRepositoryBuilderReadOnlyInterface;
99
use Squirrel\Entities\MultiRepositoryBuilderWriteable;
@@ -13,6 +13,7 @@
1313
use Squirrel\Entities\MultiRepositoryWriteable;
1414
use Squirrel\Entities\MultiRepositoryWriteableInterface;
1515
use Squirrel\Entities\RepositoryConfig;
16+
use Squirrel\Entities\RepositoryConfigInterface;
1617
use Squirrel\Entities\RepositoryReadOnly;
1718
use Squirrel\Entities\RepositoryWriteable;
1819
use Squirrel\Entities\Transaction;
@@ -29,18 +30,10 @@
2930
*/
3031
class SquirrelEntitiesExtension extends Extension
3132
{
32-
private EntityProcessor $entityProcessor;
33-
private FindClassesWithAnnotation $identifyEntityClasses;
34-
3533
public function __construct(
36-
EntityProcessor $entityProcessor,
37-
FindClassesWithAnnotation $findClassesWithAnnotation
34+
private EntityProcessor $entityProcessor,
35+
private FindClassesWithAttribute $identifyEntityClasses,
3836
) {
39-
// Entity annotation processor to find repository config
40-
$this->entityProcessor = $entityProcessor;
41-
42-
// Looks through a PHP file to find possible entity classes
43-
$this->identifyEntityClasses = $findClassesWithAnnotation;
4437
}
4538

4639
public function load(array $configs, ContainerBuilder $container): void
@@ -160,32 +153,26 @@ private function findNextFileAndReturnContentsGenerator(string $directory): \Gen
160153
}
161154

162155
/**
163-
* @param ContainerBuilder $container
164-
* @param RepositoryConfig $repositoryConfig Configuration of repository according to annotations
165156
* @param string|null $overrideConnectionName Connection name should be replaced by this configuration setting
166157
* @param string|null $overrideTableName Table name should be replaced by this configuration setting
167158
* @return string Connection name (as used when decorating the connection) for this entity
168159
*/
169160
private function createRepositoryServicesForEntity(
170161
ContainerBuilder $container,
171-
RepositoryConfig $repositoryConfig,
162+
RepositoryConfigInterface $repositoryConfig,
172163
?string $overrideConnectionName,
173-
?string $overrideTableName
164+
?string $overrideTableName,
174165
): string {
175166
// Connection can be overwritten in configuration
176-
$connectionName = isset($overrideConnectionName)
177-
? $overrideConnectionName
178-
: $repositoryConfig->getConnectionName();
167+
$connectionName = $overrideConnectionName ?? $repositoryConfig->getConnectionName();
179168

180169
// No ReadOnly repository - exit early
181170
if (!\class_exists($repositoryConfig->getObjectClass() . 'RepositoryReadOnly')) {
182171
return $connectionName;
183172
}
184173

185174
// Table name can be overwritten in configuration
186-
$tableName = isset($overrideTableName)
187-
? $overrideTableName
188-
: $repositoryConfig->getTableName();
175+
$tableName = $overrideTableName ?? $repositoryConfig->getTableName();
189176

190177
// Create repository config definition
191178
$repositoryConfigDef = new Definition(RepositoryConfig::class, [

src/SquirrelEntitiesBundle.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace Squirrel\EntitiesBundle;
44

5-
use Doctrine\Common\Annotations\AnnotationReader;
6-
use Squirrel\Entities\Annotation\EntityProcessor;
7-
use Squirrel\Entities\Generate\FindClassesWithAnnotation;
5+
use Squirrel\Entities\Attribute\EntityProcessor;
6+
use Squirrel\Entities\Generate\FindClassesWithAttribute;
87
use Squirrel\EntitiesBundle\DependencyInjection\SquirrelEntitiesExtension;
98
use Symfony\Component\HttpKernel\Bundle\Bundle;
109

@@ -16,8 +15,8 @@ class SquirrelEntitiesBundle extends Bundle
1615
public function getContainerExtension()
1716
{
1817
return new SquirrelEntitiesExtension(
19-
new EntityProcessor(new AnnotationReader()),
20-
new FindClassesWithAnnotation(),
18+
new EntityProcessor(),
19+
new FindClassesWithAttribute(),
2120
);
2221
}
2322
}

tests/SquirrelEntitiesExtensionTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace Squirrel\EntitiesBundle\Tests;
44

5-
use Doctrine\Common\Annotations\AnnotationReader;
6-
use Squirrel\Entities\Annotation\EntityProcessor;
7-
use Squirrel\Entities\Generate\FindClassesWithAnnotation;
5+
use Squirrel\Entities\Attribute\EntityProcessor;
6+
use Squirrel\Entities\Generate\FindClassesWithAttribute;
87
use Squirrel\Entities\MultiRepositoryBuilderReadOnlyInterface;
98
use Squirrel\Entities\MultiRepositoryBuilderWriteableInterface;
109
use Squirrel\Entities\MultiRepositoryReadOnlyInterface;
@@ -28,7 +27,7 @@
2827

2928
class SquirrelEntitiesExtensionTest extends \PHPUnit\Framework\TestCase
3029
{
31-
public function testNoConfiguration()
30+
public function testNoConfiguration(): void
3231
{
3332
$container = new ContainerBuilder();
3433
$configuration = [];
@@ -42,7 +41,7 @@ public function testNoConfiguration()
4241
$this->assertEquals(5, \count($container->getDefinitions())); // + service container
4342
}
4443

45-
public function testSimpleConfiguration()
44+
public function testSimpleConfiguration(): void
4645
{
4746
$container = new ContainerBuilder();
4847
$configuration = [
@@ -88,7 +87,7 @@ public function testSimpleConfiguration()
8887
);
8988
}
9089

91-
public function testNoWriteRepository()
90+
public function testNoWriteRepository(): void
9291
{
9392
$container = new ContainerBuilder();
9493
$configuration = [
@@ -113,7 +112,7 @@ public function testNoWriteRepository()
113112
$this->assertEquals(7, \count($container->getDefinitions())); // + service container
114113
}
115114

116-
public function testOverwriteTableNameAndConnection()
115+
public function testOverwriteTableNameAndConnection(): void
117116
{
118117
$container = new ContainerBuilder();
119118
$configuration = [
@@ -192,11 +191,11 @@ public function testOverwriteTableNameAndConnection()
192191
);
193192
}
194193

195-
protected function loadExtension(ContainerBuilder $container, array $configs)
194+
protected function loadExtension(ContainerBuilder $container, array $configs): void
196195
{
197196
$extension = new SquirrelEntitiesExtension(
198-
new EntityProcessor(new AnnotationReader()),
199-
new FindClassesWithAnnotation(),
197+
new EntityProcessor(),
198+
new FindClassesWithAttribute(),
200199
);
201200

202201
$extension->load($configs, $container);

tests/TestEntities/NonRepositoryWithAnnotationInUse.php renamed to tests/TestEntities/NonRepositoryWithAttributeInUse.php

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

33
namespace Squirrel\EntitiesBundle\Tests\TestEntities;
44

5-
use Squirrel\Entities\Annotation as SQL;
5+
use Squirrel\Entities\Attribute as SQL;
66

7-
class NonRepositoryWithAnnotationInUse
7+
class NonRepositoryWithAttributeInUse
88
{
99
private int $userId = 0;
1010

tests/TestEntities/User.php

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,40 @@
22

33
namespace Squirrel\EntitiesBundle\Tests\TestEntities;
44

5-
use Squirrel\Entities\Annotation as SQL;
5+
use Squirrel\Entities\Attribute\Entity;
6+
use Squirrel\Entities\Attribute\Field;
67
use Squirrel\Entities\PopulatePropertiesWithIterableTrait;
78

8-
/**
9-
* @SQL\Entity("users")
10-
*/
9+
#[Entity("users")]
1110
class User
1211
{
1312
use PopulatePropertiesWithIterableTrait;
1413

15-
/**
16-
* @SQL\Field("user_id", autoincrement=true)
17-
*/
14+
#[Field("user_id", autoincrement: true)]
1815
private int $userId = 0;
1916

20-
/**
21-
* @SQL\Field("active")
22-
*/
17+
#[Field("active")]
2318
private bool $active = false;
2419

25-
/**
26-
* @SQL\Field("user_name")
27-
*/
20+
#[Field("user_name")]
2821
private string $userName = '';
2922

30-
/**
31-
* @SQL\Field("login_name_md5")
32-
*/
23+
#[Field("login_name_md5")]
3324
private string $loginNameMD5 = '';
3425

35-
/**
36-
* @SQL\Field("login_password")
37-
*/
26+
#[Field("login_password")]
3827
private string $loginPassword = '';
3928

40-
/**
41-
* @SQL\Field("email_address")
42-
*/
29+
#[Field("email_address")]
4330
private string $emailAddress = '';
4431

45-
/**
46-
* @SQL\Field("balance")
47-
*/
32+
#[Field("balance")]
4833
private float $balance = 0;
4934

50-
/**
51-
* @SQL\Field("location_id")
52-
*/
35+
#[Field("location_id")]
5336
private ?int $locationId;
5437

55-
/**
56-
* @SQL\Field("create_date")
57-
*/
38+
#[Field("create_date")]
5839
private int $createDate = 0;
5940

6041
public function getUserId(): int

0 commit comments

Comments
 (0)