Skip to content

Commit 25ccf4f

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

105 files changed

Lines changed: 719 additions & 638 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: 5 additions & 5 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;
@@ -660,7 +660,7 @@ protected static function getForeignKeys(string $tableName): ForeignKeys
660660

661661
public function _getManyToManyRelationshipDescriptor(string $pathKey): ManyToManyRelationshipPathDescriptor
662662
{
663-
throw new TDBMException('Could not find many to many relationship descriptor key for "'.$pathKey.'"');
663+
throw new TDBMException('Could not find many to many relationship descriptor key for "' . $pathKey . '"');
664664
}
665665

666666
/**

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/EmptyInnerResultIterator.php

Lines changed: 3 additions & 1 deletion
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;
@@ -91,7 +93,7 @@ public function offsetExists($offset): bool
9193
*/
9294
public function offsetGet($offset): mixed
9395
{
94-
throw new TDBMInvalidOffsetException('Offset "'.$offset.'" does not exist in result set.');
96+
throw new TDBMInvalidOffsetException('Offset "' . $offset . '" does not exist in result set.');
9597
}
9698

9799
/**

src/EmptyResultIterator.php

Lines changed: 2 additions & 0 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
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
}

src/InnerResultIterator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function executeQuery(): void
113113
{
114114
$sql = $this->getQuery();
115115

116-
$this->logger->debug('Running SQL request: '.$sql);
116+
$this->logger->debug('Running SQL request: ' . $sql);
117117

118118
$this->result = $this->tdbmService->getConnection()->executeQuery($sql, $this->parameters, DbalUtils::generateTypes($this->parameters));
119119

@@ -146,9 +146,9 @@ public function count(): int
146146
*/
147147
private function getRowCountViaSqlQuery(): int
148148
{
149-
$countSql = 'SELECT COUNT(1) FROM ('.$this->getQuery().') c';
149+
$countSql = 'SELECT COUNT(1) FROM (' . $this->getQuery() . ') c';
150150

151-
$this->logger->debug('Running count SQL request: '.$countSql);
151+
$this->logger->debug('Running count SQL request: ' . $countSql);
152152

153153
$this->count = (int) $this->tdbmService->getConnection()->fetchOne($countSql, $this->parameters, DbalUtils::generateTypes($this->parameters));
154154
return $this->count;
@@ -216,7 +216,7 @@ public function next(): void
216216
foreach ($beansData as $beanData) {
217217
// Let's find the bean class name associated to the bean.
218218

219-
list($actualClassName, $mainBeanTableName, $tablesUsed) = $this->tdbmService->_getClassNameFromBeanData($beanData);
219+
[$actualClassName, $mainBeanTableName, $tablesUsed] = $this->tdbmService->_getClassNameFromBeanData($beanData);
220220

221221
// @TODO (gua) this is a weird hack to be able to force a TDBMObject...
222222
// `$this->className` could be used to override `$actualClassName`

0 commit comments

Comments
 (0)