Skip to content

Commit 4565e09

Browse files
committed
💚 Upgrade php-cs-fixer, define configuration, apply changes
1 parent c0a415e commit 4565e09

109 files changed

Lines changed: 744 additions & 713 deletions

File tree

Some content is hidden

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

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ jobs:
3737
- name: "Install dependencies with composer"
3838
run: "composer install --no-interaction --no-progress"
3939

40-
- name: "Run PHP-CS-Fixer on src/"
41-
run: "vendor/bin/php-cs-fixer fix src/ --dry-run --stop-on-violation --format=checkstyle | cs2pr"
42-
43-
- name: "Run PHP-CS-Fixer on tests/"
44-
run: "vendor/bin/php-cs-fixer fix tests/ --dry-run --stop-on-violation --format=checkstyle | cs2pr"
40+
- name: "Run PHP-CS-Fixer"
41+
run: "vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --format=checkstyle | cs2pr"
4542

4643
require-checker:
4744
name: "Composer require checker"

.php-cs-fixer.dist.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
8+
return (new Config())
9+
->setRiskyAllowed(true)
10+
->setRules([
11+
'@auto' => true,
12+
'@auto:risky' => true
13+
])
14+
// 💡 by default, Fixer looks for `*.php` files excluding `./vendor/` - here, you can groom this config
15+
->setFinder(
16+
(new Finder())
17+
// 💡 root folder to check
18+
->in([__DIR__ . '/src', __DIR__ . '/tests'])
19+
// 💡 additional files, eg bin entry file
20+
// ->append([__DIR__.'/bin-entry-file'])
21+
// 💡 folders to exclude, if any
22+
// ->exclude([/* ... */])
23+
// 💡 path patterns to exclude, if any
24+
// ->notPath([/* ... */])
25+
// 💡 extra configs
26+
// ->ignoreDotFiles(false) // true by default in v3, false in v4 or future mode
27+
// ->ignoreVCS(true) // true by default
28+
);

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require" : {
21-
"php": "^8.0",
21+
"php": "^8.2",
2222
"mouf/magic-query": "^2.0",
2323
"mouf/schema-analyzer": "^2.0",
2424
"doctrine/dbal": "^3.6",
@@ -46,7 +46,7 @@
4646
"phpunit/phpunit": "^9.5",
4747
"php-coveralls/php-coveralls": "^2.1",
4848
"fig/log-test": "^1.2",
49-
"friendsofphp/php-cs-fixer": "^3.11",
49+
"friendsofphp/php-cs-fixer": "^3.95",
5050
"symfony/process": "^5 || ^6 || ^7",
5151
"thecodingmachine/tdbm-fluid-schema-builder": "^v2.0.0",
5252
"phpstan/phpstan": "^2.0",
@@ -73,8 +73,8 @@
7373
"phpstan": "php -d memory_limit=3G vendor/bin/phpstan analyse src -c phpstan.neon --no-progress -vvv",
7474
"require-checker": "composer-require-checker check --config-file=composer-require-checker.json",
7575
"test": "XDEBUG_MODE=coverage phpunit",
76-
"csfix": "php-cs-fixer fix src/ && php-cs-fixer fix tests/",
77-
"cscheck": "php-cs-fixer fix src/ --dry-run --stop-on-violation && php-cs-fixer fix tests/ --dry-run --stop-on-violation ",
76+
"csfix": "php-cs-fixer fix",
77+
"cscheck": "php-cs-fixer fix --dry-run --stop-on-violation",
7878
"ci": [
7979
"@cscheck",
8080
"@phpstan",

src/AbstractTDBMObject.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ protected function set(string $var, $value, ?string $tableName = null): void
258258
*/
259259
protected function setRef(string $foreignKeyName, ?AbstractTDBMObject $bean, string $tableName, string $className, string $resultIteratorClass): void
260260
{
261-
assert($bean === null || is_a($bean, $className), new TDBMInvalidArgumentException('$bean should be `null` or `' . $className . '`. `' . ($bean === null ? 'null' : get_class($bean)) . '` provided.'));
261+
assert($bean === null || is_a($bean, $className), new TDBMInvalidArgumentException('$bean should be `null` or `' . $className . '`. `' . ($bean === null ? 'null' : $bean::class) . '` provided.'));
262262

263263
if (!isset($this->dbRows[$tableName])) {
264264
$this->registerTable($tableName);
@@ -479,7 +479,7 @@ private function getRelationshipStorage(string $pivotTableName): \SplObjectStora
479479
*/
480480
private function getManyToOneAlterableResultIterator(string $tableName, string $foreignKeyName): AlterableResultIterator
481481
{
482-
$key = $tableName.'___'.$foreignKeyName;
482+
$key = $tableName . '___' . $foreignKeyName;
483483

484484
return $this->manyToOneRelationships[$key] ?? $this->manyToOneRelationships[$key] = new AlterableResultIterator();
485485
}
@@ -522,8 +522,8 @@ private function removeManyToOneRelationship(string $tableName, string $foreignK
522522
*/
523523
protected function retrieveManyToOneRelationshipsStorage(string $tableName, string $foreignKeyName, array $searchFilter, ?string $orderString, string $resultIteratorClass): AlterableResultIterator
524524
{
525-
assert(is_a($resultIteratorClass, ResultIterator::class, true), new TDBMInvalidArgumentException('$resultIteratorClass should be a `'. ResultIterator::class. '`. `' . $resultIteratorClass . '` provided.'));
526-
$key = $tableName.'___'.$foreignKeyName;
525+
assert(is_a($resultIteratorClass, ResultIterator::class, true), new TDBMInvalidArgumentException('$resultIteratorClass should be a `' . ResultIterator::class . '`. `' . $resultIteratorClass . '` provided.'));
526+
$key = $tableName . '___' . $foreignKeyName;
527527
$alterableResultIterator = $this->getManyToOneAlterableResultIterator($tableName, $foreignKeyName);
528528
if ($this->status === TDBMObjectStateEnum::STATE_DETACHED || $this->status === TDBMObjectStateEnum::STATE_NEW || (isset($this->manyToOneRelationships[$key]) && $this->manyToOneRelationships[$key]->getUnderlyingResultIterator() !== null)) {
529529
return $alterableResultIterator;
@@ -646,9 +646,7 @@ abstract protected function getUsedTables(): array;
646646
/**
647647
* Method called when the bean is removed from database.
648648
*/
649-
protected function onDelete(): void
650-
{
651-
}
649+
protected function onDelete(): void {}
652650

653651
/**
654652
* Returns the foreign keys used by this bean.
@@ -660,7 +658,7 @@ protected static function getForeignKeys(string $tableName): ForeignKeys
660658

661659
public function _getManyToManyRelationshipDescriptor(string $pathKey): ManyToManyRelationshipPathDescriptor
662660
{
663-
throw new TDBMException('Could not find many to many relationship descriptor key for "'.$pathKey.'"');
661+
throw new TDBMException('Could not find many to many relationship descriptor key for "' . $pathKey . '"');
664662
}
665663

666664
/**

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function getAnnotationParser(): AnnotationParser
256256
*/
257257
public static function getDefaultLockFilePath(): string
258258
{
259-
return RootProjectLocator::getRootLocationPath().'tdbm.lock.yml';
259+
return RootProjectLocator::getRootLocationPath() . 'tdbm.lock.yml';
260260
}
261261

262262
public function getLockFilePath(): string

src/DbRow.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class DbRow
116116
* @param mixed[] $dbRow
117117
* @throws TDBMException
118118
*/
119-
public function __construct(AbstractTDBMObject $object, string $tableName, ForeignKeys $foreignKeys, array $primaryKeys = array(), TDBMService $tdbmService = null, array $dbRow = [])
119+
public function __construct(AbstractTDBMObject $object, string $tableName, ForeignKeys $foreignKeys, array $primaryKeys = [], TDBMService $tdbmService = null, array $dbRow = [])
120120
{
121121
$this->object = $object;
122122
$this->dbTableName = $tableName;
@@ -193,15 +193,15 @@ public function _dbLoadIfNotLoaded(): void
193193
}
194194
$connection = $this->tdbmService->getConnection();
195195

196-
list($sql_where, $parameters) = $this->tdbmService->buildFilterFromFilterBag($this->primaryKeys, $connection->getDatabasePlatform());
196+
[$sql_where, $parameters] = $this->tdbmService->buildFilterFromFilterBag($this->primaryKeys, $connection->getDatabasePlatform());
197197

198-
$sql = 'SELECT * FROM '.$connection->quoteIdentifier($this->dbTableName).' WHERE '.$sql_where;
198+
$sql = 'SELECT * FROM ' . $connection->quoteIdentifier($this->dbTableName) . ' WHERE ' . $sql_where;
199199
$result = $connection->executeQuery($sql, $parameters);
200200

201201
$row = $result->fetchAssociative();
202202

203203
if ($row === false) {
204-
throw new TDBMException("Could not retrieve object from table \"$this->dbTableName\" using filter \".$sql_where.\" with data \"".var_export($parameters, true)."\".");
204+
throw new TDBMException("Could not retrieve object from table \"$this->dbTableName\" using filter \".$sql_where.\" with data \"" . var_export($parameters, true) . "\".");
205205
}
206206

207207
$this->dbRow = [];

src/DuplicateRowException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
* An exception thrown if 2 rows are returned when TDBMService->getObject is called.
99
* This can only happen if you use a filter bag as second parameter to the getObject method.
1010
*/
11-
class DuplicateRowException extends TDBMException
12-
{
13-
}
11+
class DuplicateRowException extends TDBMException {}

src/EmptyInnerResultIterator.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TheCodingMachine\TDBM;
46

57
use Iterator;
@@ -26,9 +28,7 @@ public function current(): mixed
2628
* @return void Any returned value is ignored.
2729
* @since 5.0.0
2830
*/
29-
public function next(): void
30-
{
31-
}
31+
public function next(): void {}
3232

3333
/**
3434
* Return the key of the current element
@@ -59,9 +59,7 @@ public function valid(): bool
5959
* @return void Any returned value is ignored.
6060
* @since 5.0.0
6161
*/
62-
public function rewind(): void
63-
{
64-
}
62+
public function rewind(): void {}
6563

6664
/**
6765
* Whether a offset exists
@@ -91,7 +89,7 @@ public function offsetExists($offset): bool
9189
*/
9290
public function offsetGet($offset): mixed
9391
{
94-
throw new TDBMInvalidOffsetException('Offset "'.$offset.'" does not exist in result set.');
92+
throw new TDBMInvalidOffsetException('Offset "' . $offset . '" does not exist in result set.');
9593
}
9694

9795
/**

src/EmptyResultIterator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TheCodingMachine\TDBM;
46

5-
class EmptyResultIterator extends ResultIterator
6-
{
7-
}
7+
class EmptyResultIterator extends ResultIterator {}

src/InnerResultArray.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ public function offsetGet($offset): mixed
9090
private function toIndex($offset): void
9191
{
9292
if ($offset < 0 || filter_var($offset, FILTER_VALIDATE_INT) === false) {
93-
throw new TDBMInvalidOffsetException('Trying to access result set using offset "'.$offset.'". An offset must be a positive integer.');
93+
throw new TDBMInvalidOffsetException('Trying to access result set using offset "' . $offset . '". An offset must be a positive integer.');
9494
}
9595
if ($this->result === null) {
9696
$this->executeQuery();
9797
}
9898
while (!isset($this->results[$offset])) {
9999
$this->next();
100100
if ($this->current === null) {
101-
throw new TDBMInvalidOffsetException('Offset "'.$offset.'" does not exist in result set.');
101+
throw new TDBMInvalidOffsetException('Offset "' . $offset . '" does not exist in result set.');
102102
}
103103
}
104104
}

0 commit comments

Comments
 (0)