Skip to content

Commit 10a37f6

Browse files
Merge pull request #259 from vierge-noire/#258_fix_pipelines
#258 fix pipelines
2 parents c22686f + 8bf402c commit 10a37f6

25 files changed

+89
-85
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
},
2323
"require-dev": {
2424
"cakephp/bake": "^3.0.0",
25+
"cakephp/twig-view": "^2.0.2",
2526
"cakephp/cakephp-codesniffer": "^5.1",
2627
"cakephp/migrations": "^4.0.0",
2728
"josegonzalez/dotenv": "^4.0.0",
2829
"phpstan/phpstan": "^1.0",
29-
"phpunit/phpunit": "^10.1",
30-
"vimeo/psalm": "^5.0"
30+
"phpunit/phpunit": "^10.5",
31+
"vimeo/psalm": "^6.0"
3132
},
3233
"autoload": {
3334
"psr-4": {

psalm.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
>
1515
<projectFiles>
1616
<directory name="src"/>
17+
<ignoreFiles>
18+
<file name="vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php" />
19+
</ignoreFiles>
1720
</projectFiles>
18-
<issueHandlers>
19-
<InvalidScalarArgument errorLevel="suppress" />
20-
<NoInterfaceProperties errorLevel="suppress" />
21-
</issueHandlers>
2221
</psalm>

src/Command/BakeFixtureFactoryCommand.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Cake\Utility\Inflector;
2626
use CakephpFixtureFactories\Factory\FactoryAwareTrait;
2727
use Exception;
28+
use Override;
2829
use ReflectionClass;
2930
use ReflectionException;
3031

@@ -66,6 +67,7 @@ public function template(): string
6667
/**
6768
* @inheritDoc
6869
*/
70+
#[Override]
6971
public static function defaultName(): string
7072
{
7173
return 'bake fixture_factory';
@@ -104,6 +106,7 @@ public function setTable(string $tableName, ConsoleIo $io)
104106
* @param \Cake\Console\Arguments $args Arguments
105107
* @return string
106108
*/
109+
#[Override]
107110
public function getPath(Arguments $args): string
108111
{
109112
$outputDir = Configure::read('FixtureFactories.testFixtureOutputDir', 'Factory/');
@@ -214,6 +217,7 @@ private function bakeAllModels(Arguments $args, ConsoleIo $io): string
214217
* @param \Cake\Console\ConsoleIo $io The console io
215218
* @return int|null The exit code or null for success
216219
*/
220+
#[Override]
217221
public function execute(Arguments $args, ConsoleIo $io): ?int
218222
{
219223
$this->extractCommonProperties($args);
@@ -393,8 +397,8 @@ public function handleFactoryWithSameName(string $name, Arguments $args, Console
393397
$io->abort(
394398
sprintf(
395399
'A factory with the name `%s` already exists.',
396-
$name
397-
)
400+
$name,
401+
),
398402
);
399403
}
400404

@@ -415,6 +419,7 @@ public function handleFactoryWithSameName(string $name, Arguments $args, Console
415419
*
416420
* @return \Cake\Console\ConsoleOptionParser
417421
*/
422+
#[Override]
418423
public function getOptionParser(): ConsoleOptionParser
419424
{
420425
$name = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
@@ -423,33 +428,19 @@ public function getOptionParser(): ConsoleOptionParser
423428
$parser = $this->_setCommonOptions($parser);
424429

425430
$parser->setDescription(
426-
'Fixture factory generator.'
431+
'Fixture factory generator.',
427432
)
428433
->addArgument('model', [
429434
'help' => 'Name of the model the factory will create entities from' .
430435
'(plural, without the `Table` suffix). You can use the Foo.Bars notation ' .
431436
'to bake a factory for the model Bars located in the plugin Foo. \n
432437
Factories are located in the folder test\Factory of your app, resp. plugin.',
433438
])
434-
->addOption('plugin', [
435-
'short' => 'p',
436-
'help' => 'Plugin to bake into.',
437-
])
438439
->addOption('all', [
439440
'short' => 'a',
440441
'boolean' => true,
441442
'help' => 'Bake factories for all models.',
442443
])
443-
->addOption('force', [
444-
'short' => 'f',
445-
'boolean' => true,
446-
'help' => 'Force overwriting existing file if a factory already exists with the same name.',
447-
])
448-
->addOption('quiet', [
449-
'short' => 'q',
450-
'boolean' => true,
451-
'help' => 'Enable quiet output.',
452-
])
453444
->addOption('methods', [
454445
'short' => 'm',
455446
'boolean' => true,

src/Command/PersistCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use CakephpFixtureFactories\Error\PersistenceException;
2424
use CakephpFixtureFactories\Factory\BaseFactory;
2525
use CakephpFixtureFactories\Factory\FactoryAwareTrait;
26+
use Override;
2627

2728
class PersistCommand extends Command
2829
{
@@ -33,6 +34,7 @@ class PersistCommand extends Command
3334
/**
3435
* @inheritDoc
3536
*/
37+
#[Override]
3638
public static function defaultName(): string
3739
{
3840
return 'fixture_factories_persist';
@@ -41,6 +43,7 @@ public static function defaultName(): string
4143
/**
4244
* @inheritDoc
4345
*/
46+
#[Override]
4447
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
4548
{
4649
$parser
@@ -83,6 +86,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
8386
/**
8487
* @inheritDoc
8588
*/
89+
#[Override]
8690
public function execute(Arguments $args, ConsoleIo $io): int
8791
{
8892
$factory = null;
@@ -193,7 +197,7 @@ public function aliasConnection(string $connection, BaseFactory $factory): void
193197
{
194198
ConnectionManager::alias(
195199
$connection,
196-
$factory->getTable()->getConnection()->configName()
200+
$factory->getTable()->getConnection()->configName(),
197201
);
198202
}
199203

src/Event/ModelEventsHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private function processModelListener(Table $table, mixed $listener, string $orm
136136
if (
137137
!in_array(
138138
$ormEvent,
139-
$this->getListeningModelEvents()
139+
$this->getListeningModelEvents(),
140140
)
141141
) {
142142
$table->getEventManager()->off($ormEvent, $listener);

src/Factory/AssociationBuilder.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(BaseFactory $factory)
6363
*/
6464
public function getAssociation(string $associationName): Association
6565
{
66-
$this->removeBrackets($associationName);
66+
$associationName = $this->removeBrackets($associationName);
6767

6868
try {
6969
$association = $this->getTable()->getAssociation($associationName);
@@ -75,7 +75,7 @@ public function getAssociation(string $associationName): Association
7575
} else {
7676
$associationType = get_class($association);
7777
throw new AssociationBuilderException(
78-
"Unknown association type $associationType on table {$this->getTable()->getAlias()}"
78+
"Unknown association type $associationType on table {$this->getTable()->getAlias()}",
7979
);
8080
}
8181
}
@@ -122,7 +122,7 @@ public function validateToOneAssociation(string $associationName, BaseFactory $a
122122
{
123123
if ($this->associationIsToOne($this->getAssociation($associationName)) && $associationFactory->getTimes() > 1) {
124124
throw new AssociationBuilderException(
125-
"Association $associationName on " . $this->getTable()->getEntityClass() . ' cannot be multiple'
125+
"Association $associationName on " . $this->getTable()->getEntityClass() . ' cannot be multiple',
126126
);
127127
}
128128

@@ -153,13 +153,13 @@ public function removeAssociationForToOneFactory(string $associationName, BaseFa
153153
*/
154154
public function getAssociatedFactory(
155155
string $associationName,
156-
mixed $data = []
156+
mixed $data = [],
157157
): BaseFactory {
158158
$associations = explode('.', $associationName);
159159
$firstAssociation = array_shift($associations);
160160

161161
$times = $this->getTimeBetweenBrackets($firstAssociation);
162-
$this->removeBrackets($firstAssociation);
162+
$firstAssociation = $this->removeBrackets($firstAssociation);
163163

164164
$table = $this->getTable()->getAssociation($firstAssociation)->getClassName();
165165

@@ -193,14 +193,14 @@ public function getFactoryFromTableName(string $modelName, mixed $data = []): Ba
193193
}
194194

195195
/**
196-
* Remove the brackets and there content in a n 'Association1[i].Association2[j]' formatted string
196+
* Remove the brackets and their content in an 'Association1[i].Association2[j]' formatted string
197197
*
198198
* @param string $string String
199-
* @return string
199+
* @return string|null
200200
*/
201-
public function removeBrackets(string &$string): string
201+
public function removeBrackets(string $string): ?string
202202
{
203-
return $string = preg_replace("/\[[^]]+\]/", '', $string);
203+
return preg_replace("/\[[^]]+\]/", '', $string);
204204
}
205205

206206
/**
@@ -259,8 +259,8 @@ public function dropAssociation(string $associationName): void
259259
$this->setAssociated(
260260
Hash::remove(
261261
$this->getAssociated(),
262-
$associationName
263-
)
262+
$associationName,
263+
),
264264
);
265265
}
266266

src/Factory/BaseFactory.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ abstract protected function setDefaultTemplate(): void;
128128
*/
129129
public static function make(
130130
mixed $makeParameter = [],
131-
int $times = 1
131+
int $times = 1,
132132
): BaseFactory {
133133
if (is_numeric($makeParameter)) {
134134
$factory = self::makeFromNonCallable();
@@ -579,8 +579,8 @@ public function mergeAssociated(array $data)
579579
$this->getAssociationBuilder()->setAssociated(
580580
array_merge(
581581
$this->getAssociationBuilder()->getAssociated(),
582-
$data
583-
)
582+
$data,
583+
),
584584
);
585585

586586
return $this;
@@ -599,7 +599,7 @@ public function skipSetterFor(mixed $skippedSetters, bool $merge = false)
599599
{
600600
if (!is_string($skippedSetters) && !is_array($skippedSetters)) {
601601
throw new FixtureFactoryException(
602-
'BaseFactory::skipSettersFor() accepts an array of string or a string as argument.'
602+
'BaseFactory::skipSettersFor() accepts an array of string or a string as argument.',
603603
);
604604
}
605605
$skippedSetters = (array)$skippedSetters;
@@ -642,7 +642,7 @@ public static function get(
642642
array|string $finder = 'all',
643643
CacheInterface|string|null $cache = null,
644644
Closure|string|null $cacheKey = null,
645-
mixed ...$args
645+
mixed ...$args,
646646
): EntityInterface {
647647
return (new static())->getTable()->get($primaryKey, $finder, $cache, $cacheKey, ...$args);
648648
}
@@ -666,7 +666,7 @@ public static function count(): int
666666
* @throws \Cake\Datasource\Exception\RecordNotFoundException When there is no first record.
667667
*/
668668
public static function firstOrFail(
669-
ExpressionInterface|Closure|array|string|null $conditions = null
669+
ExpressionInterface|Closure|array|string|null $conditions = null,
670670
): EntityInterface|array {
671671
return self::find()->where($conditions)->firstOrFail();
672672
}

src/Factory/DataCompiler.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function getCompiledTemplateData(): EntityInterface|array
192192
*/
193193
public function compileEntity(
194194
array|callable|EntityInterface|string $injectedData = [],
195-
bool $setPrimaryKey = false
195+
bool $setPrimaryKey = false,
196196
): EntityInterface {
197197
if (is_string($injectedData)) {
198198
$injectedData = $this->setDisplayFieldToInjectedString($injectedData);
@@ -238,7 +238,7 @@ private function patchEntity(EntityInterface $entity, array $data): EntityInterf
238238
return $this->getFactory()->getTable()->patchEntity(
239239
$entity,
240240
$data,
241-
$this->getFactory()->getMarshallerOptions()
241+
$this->getFactory()->getMarshallerOptions(),
242242
);
243243
}
244244

@@ -262,7 +262,7 @@ private function castArrayNotation(EntityInterface $entity, array $data): array
262262
$entityValue = $entityValue ?? ($entity->get($rootKey) ?? []);
263263
if (!is_array($entityValue)) {
264264
throw new FixtureFactoryException(
265-
"Value $entityValue cannot be merged with array notation $key => $value"
265+
"Value $entityValue cannot be merged with array notation $key => $value",
266266
);
267267
}
268268
$data[$rootKey] = $entityValue = array_replace_recursive($entityValue, $subData[$rootKey]);
@@ -291,7 +291,7 @@ private function setDisplayFieldToInjectedString(string $data): array
291291
$table = get_class($this->getFactory()->getTable());
292292
throw new FixtureFactoryException(
293293
'The display field of a table must be a string when injecting a string into its factory. ' .
294-
"You injected '$data' in $factory but $table's display field is not a string."
294+
"You injected '$data' in $factory but $table's display field is not a string.",
295295
);
296296
}
297297

@@ -347,7 +347,7 @@ private function mergeWithInjectedData(EntityInterface $entity, array|callable|E
347347
if (is_callable($data)) {
348348
$data = $data(
349349
$this->getFactory(),
350-
$this->getFactory()->getFaker()
350+
$this->getFactory()->getFaker(),
351351
);
352352
} elseif (is_array($data)) {
353353
$this->addEnforcedFields($data);
@@ -561,7 +561,7 @@ public function generateArrayOfRandomPrimaryKeys(): array
561561
$res = [];
562562
foreach ($primaryKeys as $pk) {
563563
$res[$pk] = $this->generateRandomPrimaryKey(
564-
$this->getFactory()->getTable()->getSchema()->getColumnType($pk)
564+
$this->getFactory()->getTable()->getSchema()->getColumnType($pk),
565565
);
566566
}
567567

@@ -618,7 +618,7 @@ public function setPrimaryKeyOffset(mixed $primaryKeyOffset): void
618618
$primaryKey = $this->getFactory()->getTable()->getPrimaryKey();
619619
if (!is_string($primaryKey)) {
620620
throw new FixtureFactoryException(
621-
"The primary key assigned must be a string as $primaryKeyOffset is a string or an integer."
621+
"The primary key assigned must be a string as $primaryKeyOffset is a string or an integer.",
622622
);
623623
}
624624
$this->primaryKeyOffset = [
@@ -628,7 +628,7 @@ public function setPrimaryKeyOffset(mixed $primaryKeyOffset): void
628628
$this->primaryKeyOffset = $primaryKeyOffset;
629629
} else {
630630
throw new FixtureFactoryException(
631-
"$primaryKeyOffset must be an integer, a string or an array of format ['primaryKey1' => value, ...]"
631+
"$primaryKeyOffset must be an integer, a string or an array of format ['primaryKey1' => value, ...]",
632632
);
633633
}
634634
}
@@ -656,7 +656,7 @@ private function updatePostgresSequence(array $primaryKeys): void
656656
SELECT pg_get_serial_sequence('$tableName','$pk')")->fetchAll()[0][0];
657657
if ($seq !== null) {
658658
$table->getConnection()->execute(
659-
"SELECT setval('$seq', $offset);"
659+
"SELECT setval('$seq', $offset);",
660660
);
661661
}
662662
}
@@ -676,9 +676,9 @@ public function getModifiedUniqueFields(): array
676676
$this->getEnforcedFields(),
677677
array_merge(
678678
$this->getFactory()->getUniqueProperties(),
679-
(array)$this->getFactory()->getTable()->getPrimaryKey()
680-
)
681-
)
679+
(array)$this->getFactory()->getTable()->getPrimaryKey(),
680+
),
681+
),
682682
);
683683
}
684684

@@ -727,7 +727,7 @@ public function addEnforcedFields(array $fields): void
727727
{
728728
$this->enforcedFields = array_merge(
729729
array_keys($fields),
730-
$this->enforcedFields
730+
$this->enforcedFields,
731731
);
732732
}
733733

0 commit comments

Comments
 (0)